6

I have just placed TextInput KeyboardType ={"numeric"} just trying to find weather user enter '-' if means I have to event.preventDefault() in OnChange first.Later tried in onKeyPress but onKeyPress is not trigerring , I was just tried to do that but it allowing me to type shows warning Synthetic Event Performance issue.

guys help me .

Srinu Chilukuri
  • 83
  • 2
  • 11
saiRam89
  • 365
  • 1
  • 8
  • 21

4 Answers4

10

You are testing with android mobile whereasonKeyPress method is for iOS, check documentation for same

You can use onChangeText for text change.

Example:

<TextInput
    onChangeText={(text) => this.onFirstNameText(text)}
    returnKeyType={'next'}
    underlineColorAndroid='transparent'
    style={styles.inputColLeft}
/>

Edit 2018

onKeyPress is now also supported for Android devices as per this commit.

From doc:

Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
2

Here is the solution to this issue of synthetic event:

Input element:

<Input onKeyPress = {this.keyPress} />

keyPress function

keyPress = (event) => {

/* this line will solve your error */

event.persist();
console.log(event);
}

Fahad Mahmood
  • 159
  • 1
  • 10
2
 const App =()=>{
  const  handleKeyPress = ({ nativeEvent: { key: keyValue } }) => {
      console.log(keyValue);
      if(keyValue === 'Enter')
      {
        console.log("enter");
      }
  };
  return(
    <View>
         <TextInput
            placeholder="Your Password"
            placeholderTextColor="#666666"
            style={styles.inputSearch}
            // onEndEditing={(e)=>handleValidUser(e.nativeEvent.text)}
            onKeyPress={handleKeyPress}
          />
    </View>
  )
}
Apple Yellow
  • 307
  • 1
  • 2
  • 7
1

Use onChangeText like this:

<TextInput  onChangeText = {(text) => this.getPhone(text)} keyboardType="numeric" autoCapitalize="none" autoCorrect={false} onSubmitEditing={ () => this.addressInput.focus()} style={styles.input} placeholder="phone" placeholderTextColor="rgba(255,255,255,0.6)" underlineColorAndroid="rgba(0,0,0,0.0)" returnKeyType="next"/>

 getPhone = (text) => {
      this.setState({phone: text})
      //use your logic here 

   }