garganurag893 / react-native-phone-number-input

React Native component for phone number.
MIT License
372 stars 212 forks source link

Open the keyboard after selecting a country #138

Closed svtpt closed 1 year ago

svtpt commented 1 year ago

This is my code:

<PhoneInput ref={phoneInput} defaultValue={phoneRawValue} defaultCode="US" layout="second" onChangeText={(text) => { setPhoneRawValue(text); }} onChangeFormattedText={(text) => { setPhone(text); }} withDarkTheme autoFocus={true} placeholder="Enter your Number" containerStyle={{ marginTop: 100, backgroundColor: 'transparent', }} textContainerStyle={{ backgroundColor: 'transparent', }} textInputStyle={{ backgroundColor: 'transparent', fontSize: 23, fontWeight: 'bold', color: '#000' }} codeTextStyle={{ backgroundColor: 'transparent', fontSize: 25, fontWeight: 'bold', }} keyboardType="phone-pad" textInputProps={{ placeholderTextColor: "#414141", ref: phoneInput }} onChangeCountry={() => { phoneInput.current.focus(); }} />

When the page is initially loaded, the keyboard is visible. Then I click on the country-code button and select another country. The popup is closed, the keyboard is hidden and the input's pointer blinks (i.e. it's focused, but the keyboard is not there). Tried with onChangeCountry , but it didn't help.

Any suggestions?

svtpt commented 1 year ago

Nevermind, I found a solution.

  1. Unfocus the field
  2. Focus on it again
  3. Profit

onChangeCountry={() => { Keyboard.dismiss(); setTimeout(() => { phoneInput.current.focus(); }, 100); }}