react-native-confirmation-code-input icon indicating copy to clipboard operation
react-native-confirmation-code-input copied to clipboard

How to get value user write?

Open anastely opened this issue 5 years ago • 2 comments

Hey,

I have a function to check the code input sent from firebase, and i want to know what user he writes in <CodeInput> so i use onChangeText as usual in TextInput RN , but i can't see any thing when i log the value?

SO how can I update the state after he right the code and "onFulfill" invoked?

Code

state = {
   isValid: false,
   codeInput: '', // what's user write!
   confirmResult: this.props.navigation.getParam('confirmResult'),
   message: this.props.navigation.getParam('message'),
 };
<CodeInput
           value={this.state.codeInput}
           onChangeText={input =>
             this.setState({codeInput: input}, () =>
               console.log(this.state.codeInput + 'heyCh'),
             )
           }
           ref="codeInputRef2"
           secureTextEntry
           compareWithCode={this.state.codeInput.toString()}
           activeColor="#1a4672"
           inactiveColor="#286fb7"
           autoFocus={false}
           ignoreCase={true}
           inputPosition="center"
           size={50}
           keyboardType="numeric"
           codeLength={6}
           onFulfill={() => this.confirmCode()}
           containerStyle={{margin: 0}}
           codeInputStyle={{borderWidth: 1.5}}
         />

// Function 
 confirmCode = () => {
   const {codeInput, confirmResult} = this.state;
   console.log('confirmResult:++ ', confirmResult);
   console.log('codeInput:++', codeInput); // it's empty although  i write the code number in inputs!
   if (confirmResult && codeInput.length) {
     confirmResult
       .confirm(codeInput)
       .then(user => {
         console.log(JSON.stringify(user.uid));
         this.setState({
           message: 'Code Confirmed!',
         });
       })
       .catch(error => {
         this.setState({message: `Code Confirm Error: ${error.message}`});
       });
   } else {
     console.log('Not here');
   }
 };

anastely avatar Nov 03 '19 18:11 anastely

@anastely

You can use a fork without this problem https://github.com/retyui/react-native-confirmation-code-field

retyui avatar Feb 19 '20 07:02 retyui

@retyui I will use it as soon as possible, Thanks :)

anastely avatar Feb 19 '20 18:02 anastely