1
1
import _ from 'lodash' ;
2
2
import React , { Component } from 'react' ;
3
3
import { ScrollView , StyleSheet } from 'react-native' ;
4
- import { Typography , View , Text , MaskedInput } from 'react-native-ui-lib' ; //eslint-disable-line
4
+ import { Typography , View , Text , MaskedInput , Button } from 'react-native-ui-lib' ; //eslint-disable-line
5
5
6
6
export default class MaskedInputScreen extends Component {
7
7
constructor ( props ) {
8
8
super ( props ) ;
9
9
10
10
this . state = {
11
11
error : '' ,
12
+ timeValue : '15'
12
13
} ;
13
14
}
14
15
@@ -18,6 +19,11 @@ export default class MaskedInputScreen extends Component {
18
19
} , 500 ) ;
19
20
}
20
21
22
+ clearInputs = ( ) => {
23
+ this . minput . clear ( ) ;
24
+ this . priceInput . clear ( ) ;
25
+ } ;
26
+
21
27
renderTimeText ( value ) {
22
28
const paddedValue = _ . padStart ( value , 4 , '0' ) ;
23
29
const hours = paddedValue . substr ( 0 , 2 ) ;
@@ -51,12 +57,11 @@ export default class MaskedInputScreen extends Component {
51
57
}
52
58
53
59
render ( ) {
60
+ const { timeValue} = this . state ;
61
+
54
62
return (
55
63
< View flex >
56
- < ScrollView
57
- contentContainerStyle = { styles . container }
58
- keyboardShouldPersistTaps = 'always'
59
- >
64
+ < ScrollView contentContainerStyle = { styles . container } keyboardShouldPersistTaps = "always" >
60
65
< Text text40 marginB-20 >
61
66
Masked Inputs
62
67
</ Text >
@@ -69,16 +74,21 @@ export default class MaskedInputScreen extends Component {
69
74
renderMaskedText = { this . renderTimeText }
70
75
keyboardType = { 'numeric' }
71
76
maxLength = { 4 }
72
- value = { '15' }
77
+ value = { timeValue }
78
+ onChangeText = { value => this . setState ( { timeValue : value } ) }
73
79
/>
74
80
75
81
< Text text70 marginT-40 >
76
82
Price/Discount
77
83
</ Text >
78
84
< MaskedInput
85
+ ref = { r => ( this . priceInput = r ) }
79
86
renderMaskedText = { this . renderPrice }
80
87
keyboardType = { 'numeric' }
81
88
/>
89
+ < View centerH marginT-100 >
90
+ < Button label = "Clear All" onPress = { this . clearInputs } />
91
+ </ View >
82
92
</ ScrollView >
83
93
</ View >
84
94
) ;
@@ -89,13 +99,13 @@ const styles = StyleSheet.create({
89
99
container : {
90
100
flexDirection : 'column' ,
91
101
justifyContent : 'flex-start' ,
92
- padding : 25 ,
102
+ padding : 25
93
103
} ,
94
104
title : {
95
- ...Typography . text20 ,
105
+ ...Typography . text20
96
106
} ,
97
107
header : {
98
108
...Typography . text60 ,
99
- marginVertical : 20 ,
100
- } ,
109
+ marginVertical : 20
110
+ }
101
111
} ) ;
0 commit comments