From 63b8c04ebcebb46c0633b7e81b128a85da794e1c Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Fri, 17 Mar 2017 10:06:40 -0400 Subject: [PATCH] fix(input): Rework of the past system Related to #97 --- src/components/mobile-input/mobile-input.html | 6 ++++-- src/components/mobile-input/mobile-input.ts | 21 +++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/components/mobile-input/mobile-input.html b/src/components/mobile-input/mobile-input.html index 3def67e..13354ed 100755 --- a/src/components/mobile-input/mobile-input.html +++ b/src/components/mobile-input/mobile-input.html @@ -16,7 +16,8 @@ (blur) = "toggleFocus()" (focus) = "toggleFocus()" (keyup) = "emitChange($event)" - (press) = "onPast()" + (press) = "onPress()" + (pressup) = "onPressUp()" > @@ -33,7 +34,8 @@ [formControl] = "control" [(ngModel)] = "value" (ngModelChange) = "valueChange.emit($event)" - (press) = "onPast()" + (press) = "onPress()" + (pressup) = "onPressUp()" > diff --git a/src/components/mobile-input/mobile-input.ts b/src/components/mobile-input/mobile-input.ts index 7ba8c88..ef64500 100755 --- a/src/components/mobile-input/mobile-input.ts +++ b/src/components/mobile-input/mobile-input.ts @@ -47,6 +47,8 @@ export class MobileInput { valueChange = new EventEmitter(); isFocused = false; + pressedOn = 0; + pastTimeOut; constructor() { @@ -77,7 +79,23 @@ export class MobileInput { } } - onPast(){ + onPressUp(){ + if(Date.now() - this.pressedOn < 1000){ + clearTimeout(this.pastTimeOut); + } + this.pressedOn = 0; + } + + onPress(){ + + this.pressedOn = Date.now(); + this.pastTimeOut = setTimeout(()=>{ + this.paste(); + }, 1000); + + } + + paste(){ Clipboard.paste().then( (resolve: string) => { this.value = resolve; @@ -87,7 +105,6 @@ export class MobileInput { console.error("Unsucessful pasting") } ); - } toggleFocus():void{