File tree Expand file tree Collapse file tree 4 files changed +18
-11
lines changed
Expand file tree Collapse file tree 4 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export default class App extends Component {
77 constructor ( props ) {
88 super ( props ) ;
99
10- this . input = [ ] ;
10+ this . textInput = [ ] ;
1111
1212 this . state = {
1313 value : "Example of string" ,
@@ -17,13 +17,12 @@ export default class App extends Component {
1717 }
1818
1919 render ( ) {
20- this . input = [ ] ;
2120 return (
2221 < ScrollView style = { styles . container } >
2322 < Text style = { styles . title } > Example{ "\n" } react-native-input-validator</ Text >
2423 < TextInput
2524 onRef = { ( r ) => {
26- this . input . push ( r ) ;
25+ this . textInput [ 0 ] = r ;
2726 } }
2827 value = { this . state . value }
2928 style = { styles . input }
@@ -32,7 +31,7 @@ export default class App extends Component {
3231 </ TextInput >
3332 < TextInput
3433 onRef = { ( r ) => {
35- this . input . push ( r ) ;
34+ this . textInput [ 1 ] = r ;
3635 } }
3736 value = { this . state . valueRequired }
3837 required = { true }
@@ -42,7 +41,7 @@ export default class App extends Component {
4241 </ TextInput >
4342 < TextInput
4443 onRef = { ( r ) => {
45- this . input . push ( r ) ;
44+ this . textInput [ 2 ] = r ;
4645 } }
4746 value = { this . state . value }
4847 style = { styles . input }
@@ -52,7 +51,7 @@ export default class App extends Component {
5251 </ TextInput >
5352 < TextInput
5453 onRef = { ( r ) => {
55- this . input . push ( r ) ;
54+ this . textInput [ 3 ] = r ;
5655 } }
5756 value = { this . state . valueNumber }
5857 style = { styles . input }
@@ -63,12 +62,14 @@ export default class App extends Component {
6362 < TouchableOpacity
6463 style = { styles . button }
6564 onPress = { ( ) => {
66- this . input . map ( ( item ) => {
67- console . log ( item ) ;
65+ console . log ( this . textInput ) ;
66+ this . textInput . map ( ( item , i ) => {
67+ console . log ( "TextInput " + i , item . isValid ( ) ) ;
6868 } ) ;
6969 } } >
7070 < Text > Validate</ Text >
7171 </ TouchableOpacity >
72+ < Text > Check validation on console.</ Text >
7273 </ ScrollView >
7374 ) ;
7475 }
Original file line number Diff line number Diff line change 1212 "react" : " 16.8.3" ,
1313 "react-dom" : " ^16.8.6" ,
1414 "react-native" : " https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz" ,
15- "react-native-input-validator" : " ^1.0.7 " ,
15+ "react-native-input-validator" : " ^1.0.9 " ,
1616 "react-native-web" : " ^0.11.4" ,
1717 "validator" : " ^11.1.0"
1818 },
Original file line number Diff line number Diff line change 11{
22 "name" : " react-native-input-validator" ,
3- "version" : " 1.0.7 " ,
3+ "version" : " 1.0.9 " ,
44 "description" : " React native input with floating label and data validation" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ class InputValidator extends Component {
3131 * @param prevState
3232 */
3333 componentDidUpdate ( prevProps , prevState ) {
34+ if ( typeof this . props . onRef === 'function' ) {
35+ this . props . onRef ( this . _isMounted ? this : undefined ) ;
36+ }
3437 const props_value = this . parseValue ( this . props . value ) ;
3538 const state_value = this . parseValue ( ) ;
3639 if ( this . props . value == null ) {
@@ -45,6 +48,7 @@ class InputValidator extends Component {
4548 * Component did mount
4649 */
4750 componentDidMount ( ) {
51+ this . _isMounted = true ;
4852 if ( typeof this . props . onRef === 'function' ) {
4953 this . props . onRef ( this ) ;
5054 }
@@ -54,7 +58,8 @@ class InputValidator extends Component {
5458 /**
5559 * Component did unmount
5660 */
57- componentDidUnmount ( ) {
61+ componentWillUnmount ( ) {
62+ this . _isMounted = false ;
5863 if ( typeof this . props . onRef === 'function' ) {
5964 this . props . onRef ( undefined ) ;
6065 }
@@ -373,6 +378,7 @@ class InputValidator extends Component {
373378 }
374379
375380 delete props . children ;
381+ delete props . onRef ;
376382 delete props . ref ;
377383
378384 if ( props . editable === false ) {
You can’t perform that action at this time.
0 commit comments