-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
339 lines (257 loc) · 9.85 KB
/
index.js
File metadata and controls
339 lines (257 loc) · 9.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import React from 'react'
import { requireNativeComponent, StyleSheet, View, Platform, findNodeHandle, UIManager } from 'react-native';
import PropTypes from 'prop-types';
let InputMasking = requireNativeComponent(`InputMasking`);
class RNInputMasking extends React.Component {
constructor(props) {
super(props);
}
focus = () => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.inputMaskingRef),
UIManager.getViewManagerConfig('InputMasking').Commands
.focus,
[]
);
}
blur = () => {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.inputMaskingRef),
UIManager.getViewManagerConfig('InputMasking').Commands
.blur,
[]
);
}
_onErrorForMasking = ({nativeEvent}) => {
console.log('error ',nativeEvent)
}
render() {
return <View style={[styles.fieldContainer, this.props.style]} >
<InputMasking
ref={_ref => this.inputMaskingRef = _ref}
style={styles.field}
onChangeText={this.props.onChangeText}
/******************
*
*
* Catch the result from this function as,
*
* console.log(' onChangeText ', event.nativeEvent.text )
*
*********************/
{...(Platform.OS == "android" ?
{ onFocus: this.props.onFocus }
: { onFocusText: this.props.onFocus })
}
/*********************
*
* Catch the result from this function as,
*
* console.log(' onFocus ', event.nativeEvent.focus )
*
*********************/
onErrorForMasking={this.props.onErrorForMasking ?? this._onErrorForMasking}
/*********************
*
* Catch the result from this function as,
*
* Use this function to see why the typing was stopped,
*
*
* console.log(' onErrorForMasking ', event.nativeEvent.error )
*
*********************/
{...(Platform.OS == "android" ?
{ onSubmitEditing: this.props.onSubmitEditing }
: { onSubmitText: this.props.onSubmitEditing })
}
/*********************
*
* Catch the result from this function as,
*
* console.log(' onSubmitEditing ', event.nativeEvent.text )
*
*********************/
underlineColorAndroid={this.props.underlineColorAndroid}
/*********************
*
* Use this prop to set the underline color of the text input:
*
* default is #cccccc, pass any hex color
*
*********************/
{...(Platform.OS == "android" ?
{ placeholder: this.props.placeholder }
: { _placeholder: this.props.placeholder })
}
/*********************
*
* Use this prop to set the placeholder for the text input:
*
* Pass any string
*
*********************/
placeholderTextColor={this.props.placeholderTextColor}
/*********************
*
* Use this prop to set the placeholder text color for the text input:
*
* default is #cccccc, pass any hex color
*
*********************/
{...(Platform.OS == "android" ?
{ textColor: this.props.textColor }
: { _textColor: this.props.textColor })
}
/*********************
*
* Use this prop to set the text color for the text input:
*
* default is android's default, pass any hex color
*
*********************/
textSize={this.props.textSize}
/*********************
*
* Use this prop to set the text size for the text input:
*
* default is android's default, pass any number
*
*********************/
disabled={this.props.disabled}
/*********************
*
* Use this prop to disable the editing for the text input:
*
* default is false, pass a boolean to toggle
*
*********************/
value={this.props.value}
/*********************
*
* Use this prop to set the default value for the text input:
*
* default is empty string, pass any string value
*
*********************/
textAlign={this.props.textAlign}
/*********************
*
* Use this prop to set the alignment of the text inside the text input:
*
* default is Left, can be either of Left or Right
*
*********************/
{...(Platform.OS == "android" ?
{ keyboardType: this.props.keyboardType }
: { _keyboardType: this.props.keyboardType })
}
/*********************
*
* Use this prop to set the keyboard type for the text input:
*
* default is android's default, can be of following types:
*
* number-pad , date-time , email-address , password
*
* !!! IMPORTANT !!!
*
* The password property for the keyboard will conceal the input with default dots
*
*********************/
{...(Platform.OS == "android" ?
{ returnKeyType: this.props.returnKeyType }
: { _returnKeyType: this.props.returnKeyType })
}
/*********************
*
* Use this prop to set the returnKeyType of the keyboard for the text input:
*
* default is done, can be of following types:
*
* go , next , search , done ( default )
*
*********************/
maskType={this.props.maskType}
/*********************
*
* Use this prop to set the maskType for the text input:
*
* default is none, can be of following types:
*
* credit-card , phone-number , default
*
*********************/
maskFormat={this.props.maskFormat}
/*********************
*
* Use this prop to set the maskFormat for the text input:
*
* Use the following format to set the maskFormat:
*
* use A where you want to show the alphabet and use D where you want to show a digit
*
* For example:
*
* To mask the input for credit-card following format is suitable:
*
* DDDD-DDDD-DDDD-DDDD
*
* To mask the input for id card following format is suitable:
*
* AA-DDD
*
* To mask the input for date following format is suitable:
*
* DD/DD/DD
*
* To mask the input for phone-number following format is suitable:
*
* > for eg if UK's phone no. needed to be masked:
*
* +44-DDDD-DDDDDD
*
* !!! IMPORTANT !!!
*
* use default or no maskType if using for other than credit-card or phone-number
*
*********************/
{...(Platform.OS == "ios" ?
{ fontType: this.props.fontFamily?.split(".")[0] }
: { fontFamily: this.props.fontFamily })
}
/>
</View>
}
}
const styles = StyleSheet.create({
field: {
height: '100%',
width: '100%',
},
fieldContainer: {
height: 100,
width: 100,
}
})
RNInputMasking.propTypes = {
onChangeText: PropTypes.func,
onFocus: PropTypes.func,
onErrorForMasking: PropTypes.func,
onSubmitEditing: PropTypes.func,
underlineColorAndroid: PropTypes.string,
placeholder: PropTypes.string,
placeholderTextColor: PropTypes.string,
textColor: PropTypes.string,
textSize: PropTypes.number,
disabled: PropTypes.bool,
value: PropTypes.string,
textAlign: PropTypes.string,
keyboardType: PropTypes.string,
returnKeyType: PropTypes.string,
maskType: PropTypes.string,
maskFormat: PropTypes.string.isRequired,
style: PropTypes.object,
fontFamily: PropTypes.string,
}
export default RNInputMasking;