Keyboard closes immediately once opened in TextInput inside a navigation stack screen (expo-android)
See original GitHub issueDescription
When the input of a TextInput component is pressed, the keyboard pops up and immediately closes again. This happens inside a stack navigation screen. However, the issue doesn’t seem to be of react-navigation (solutions in issue #8414 don’t solve the problem). What solved the issue was downgrading from react-native-screens@3.12 to react-native-screens@3.11
Screenshots
Steps To Reproduce
1. expo init screens --template blank
2. npm install @react-navigation/native @react-navigation/stack react-native-elements react-native-gesture-handler react-native-safe-area-context react-native-screens
3. expo run:android
Expected behavior
When the TextInput component is pressed (focused), the keyboard opens and remains open.
Actual behavior
When the TextInput component is pressed (focused), the keyboard opens and immediately closes again.
Reproduction
Minimal code example
import React, { useState } from 'react'
import {
KeyboardAvoidingView,
Text,
TextInput,
Button,
StyleSheet,
Platform
} from 'react-native'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'
import { enableScreens } from 'react-native-screens'
enableScreens()
const Stack = createStackNavigator()
export default function App () {
return (
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
gestureEnabled: true,
animationEnabled: false
}}
>
<Stack.Screen
name='Login View'
component={LoginView}
options={{ title: 'Read it Later - Maybe' }}
/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
)
}
export function LoginView () {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const onPressSignIn = async () => {
console.log('Trying sign in with user: ' + email)
}
const onPressSignUp = async () => {
console.log('Trying signup with user: ' + email)
}
return (
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<Text>Sign Up or Sign In:</Text>
<SafeAreaView style={styles.inputContainer}>
<TextInput
placeholder='email'
autoCapitalize='none'
onChangeText={mail => {
setEmail(mail)
}}
value={email}
style={styles.inputStyle}
keyboardType='email-address'
/>
</SafeAreaView>
<SafeAreaView style={styles.inputContainer}>
<TextInput
placeholder='password'
secureTextEntry
onChangeText={pass => {
setPassword(pass)
}}
value={password}
style={styles.inputStyle}
/>
</SafeAreaView>
<Button onPress={onPressSignIn} title='Sign In' />
<Button onPress={onPressSignUp} title='Sign Up' />
</KeyboardAvoidingView>
)
}
const styles = StyleSheet.create({
inputContainer: {
padding: 5
},
inputStyle: {
borderColor: 'black',
borderWidth: 1,
padding: 10,
borderRadius: 2
},
manageTeamWrapper: {
width: 350
},
manageTeamTitle: {
marginBottom: 10
},
addTeamMemberInput: {
borderBottomColor: 'black',
borderBottomWidth: 1,
marginTop: 5,
fontSize: 18
},
manageTeamButtonContainer: {
textAlign: 'left',
borderTopColor: 'grey',
borderTopWidth: 1,
borderBottomColor: 'grey',
borderBottomWidth: 1
},
plusButton: {
fontSize: 28,
fontWeight: '400'
}
})
Platform
- iOS - [ x ] Android
- Web
- Windows
- tvOS
Workflow
- [ x ] Managed workflow
- Bare workflow
Package versions
package | version |
---|---|
react | 17.0.1 |
react-dom | 17.0.1 |
react-native | 0.64.3 |
react-native-web | 17.0.1 |
@react-navigation/native | ^6.0.8 |
@react-navigation/stack | ^6.1.1 |
react-native-screens | ^3.12 |
react-native-safe-area-context | ^3.4.1 |
react-native-gesture-handler | ^2.2.0 |
react-native-elements | ^3.4.2 |
expo | ~44.0.0 |
expo-splash-screen | ~0.14.1 |
expo-status-bar | ~1.2.0 |
@babel/core | ^7.12.9 |
@babel/core is a development dependency.
Issue Analytics
- State:
- Created 2 years ago
- Comments:21 (1 by maintainers)
Top Results From Across the Web
React Native TextInput closes automatically when opened on ...
Now every time I click on one TextInput the keyboard opens and closes immediately only on android. I attached a quick recording here....
Read more >keyboard.dismiss reactnative Code Example - Code Grepper
Answers related to “keyboard.dismiss reactnative” · keyboard close when typing react native · button doesn't work while keyboard is shown react native ·...
Read more >TextInput - React Native
A foundational component for inputting text into the app via a keyboard. Props provide configurability for several features, ...
Read more >How to dismiss the keyboard in React native without clicking ...
Method 1: Using TouchableWithoutFeedback Component: We simply encapsulate the outermost View component of our App inside the ...
Read more >How to dismiss keyboard with react-navigation in React Native ...
TextInput inside ScrollView · 'never' (the default), tapping outside of the focused text input when the keyboard is up dismisses the keyboard. ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Downgrading to 3.11 solved the issue. I don’t know what the root cause is but it is definitely something in the latest release.
Downgrading worked for me. I have kept “react-native-screens”: “3.4.0” and the keyboard issue worked