Skip to content

Commit

Permalink
fix(input): Rework of the past system
Browse files Browse the repository at this point in the history
Related to #97
  • Loading branch information
MathieuNls committed Mar 17, 2017
1 parent c6d8f3a commit 63b8c04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/mobile-input/mobile-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
(blur) = "toggleFocus()"
(focus) = "toggleFocus()"
(keyup) = "emitChange($event)"
(press) = "onPast()"
(press) = "onPress()"
(pressup) = "onPressUp()"
>
</ion-input>

Expand All @@ -33,7 +34,8 @@
[formControl] = "control"
[(ngModel)] = "value"
(ngModelChange) = "valueChange.emit($event)"
(press) = "onPast()"
(press) = "onPress()"
(pressup) = "onPressUp()"
>
</ion-input>

Expand Down
21 changes: 19 additions & 2 deletions src/components/mobile-input/mobile-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class MobileInput {
valueChange = new EventEmitter();

isFocused = false;
pressedOn = 0;
pastTimeOut;


constructor() {
Expand Down Expand Up @@ -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;
Expand All @@ -87,7 +105,6 @@ export class MobileInput {
console.error("Unsucessful pasting")
}
);

}

toggleFocus():void{
Expand Down

0 comments on commit 63b8c04

Please sign in to comment.