1

I want to show my custom keyboard component when an input field is press. I want to prevent the system default keyboard from getting triggered at all.

I have tried dismissing the keyboard on onFocus but this triggers the keyboard and then dismisses the keyboard.

 <TextInput
     placeholder="type here"
     onFocus={Keyboard.dismiss}
 />

I have tired wrapping the TextInput inside TouchableWithoutFeedback but this solution doesn't work.

<TouchableWithoutFeedback
    onPress={() => Keyboard.dismiss()}
    accessible={false}
>
    <View>
        <TextInput placeholder="type here" />
    </View>
</TouchableWithoutFeedback>

Any ideas how can I achieve the desired results?

2
  • 3
    You don't necessarily have to use a TextInput for that. You could just put a Text inside TouchableWithoutFeedback which triggers the keyboard, save your custom keyboard input in a state or something and then pass the value to Text Commented Dec 31, 2019 at 15:10
  • 2
    I thought of that idea but Text component won't behave like TextInput. Commented Jan 1, 2020 at 9:18

2 Answers 2

6

You can use showSoftInputOnFocus on Android, see the docs: https://facebook.github.io/react-native/docs/textinput#showsoftinputonfocus

Your case is the same as avoiding showing the keyboard when an external keyboard is connected (on iPad it common).

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I needed. Thanks a lot.
5

Open AndroidManifest file in (android > app > src > main) folder of your project and then add :

android:windowSoftInputMode="stateHidden"

to your activity tag like this :

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="stateHidden">

2 Comments

android:windowSoftInputMode="stateHidden" still triggers the keyboard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.