View lowers itself when typing in TextInput React Native (Expo) - react-native

In general the lay-out seems fine, the content is wrapped up inside a KeyboardAvoidingView as followed:
<KeyboardAvoidingView
keyboardVerticalOffset={-useHeaderHeight()}
behavior={"padding"}
style={styles.container}>
<View style={styles.conversationContainer}>
<ScrollView
ref={scrollViewRef}
onContentSizeChange={() => scrollViewRef.current.scrollToEnd({ animated: true })}
overScrollMode='never'
showsVerticalScrollIndicator={false}
enableOnAndroid={true}
style={styles.conversation}>
{messagesView}
</ScrollView>
<View
style={styles.send}>
<TextInput
value={text}
textAlignVertical='center'
placeholder='Write your message'
style={styles.textInput}
blurOnSubmit={true}
onChangeText={(value) => setText(value)}
>
</TextInput>
<TouchableOpacity
style={[styles.button]}
activeOpacity={.6}
onPress={() => addMessage()}>
<IonIcon
name={"arrow-forward-circle-outline"}
size={30}
color={'#00966E'}
style={styles.icon} />
</TouchableOpacity>
</View>
</View>
</KeyboardAvoidingView>
With the keyboard open, the TextInput is placed above the keyboard as intended.
Keyboard Picture
But whenever I press a single keystroke, the entire view (including the TextInput), lowers down, covering half of the TextInput.
Image of keyboard covering the TextInput
I have already tried changing the KeyboardVerticalOffset to different values as well as the changing the behavior to "heigth", "position" or none. None of these happened to change anything.

Had the same issue. This syntax helped me: <KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>

Related

react native TouchableOpacity onpress problem

i'm using TabView and in every tab i use flatList. every list item has phone and email button. But TouchableOpacity onpress not working so i use onPressOut. onPressOut working but it works when i touched in not when touched out. you guys have any ideas why this is happennig
<View style={styles.ButtonGroup}>
<TouchableOpacity
style={[styles.ButtonCont, {backgroundColor: '#BEF7D1'}]}
onPressOut={() => {
Linking.openURL(`tel:+90${data.item.kiraci_gsm1}`);
}}>
<Icon
name={'phone'}
type="font-awesome-5"
size={24}
color="#036122"
/>
</TouchableOpacity>
<TouchableOpacity
style={[styles.ButtonCont, {backgroundColor: '#C6E1FF'}]}
onPressOut={() => {
Linking.openURL(`mailto:${data.item.kiraci_eposta1}`);
}}>
<Icon
name={'envelope'}
type="font-awesome"
size={24}
color="#0050AC"
/>
</TouchableOpacity>
</View>
Pay attention from where import your "TouchableOpacity". When I changed "TouchableOpacity" from "react-native-gesture-handler" to "react-native" for Android platform.

React Native - Background Image should scroll with the Text

I have the background transparent image (the light blue in the screenshot). The problem is when I type something in the textbox a vertical scroll comes up and the form moves a little bit up. Is it possible that the background moves with the scroll as well?
#1 - in the screenshot is the form that moves
#2 - is the background image
Here is the code
<Container style={styles.container}>
<ImageBackground source={loginbackground} style={{width: '100%',height:'100%' }}>
<Content>
<View style={{marginTop:margint,paddingLeft:30,paddingRight:30}}>
<View style={{marginTop:10}}>
<Item style={{backgroundColor:'rgb(149,197,69)',borderRadius:8,borderWidth:1,borderColor:'rgb(117,170,70)'}}>
<Image source={emailicon} style={{height:20,width:20,marginLeft:10,marginRight:10}}/>
<Input placeholder="Email" value={this.state.username} onChangeText={ (text) => this.setState({ username: text }) } placeholderTextColor="rgb(240,240,240)" />
</Item>
</View>
<View style={{marginTop:15}}>
<Item style={{backgroundColor:'rgb(149,197,69)',borderRadius:8,borderWidth:1,borderColor:'rgb(117,170,70)'}}>
<Image source={passwordicon} style={{height:20,width:20,marginLeft:10,marginRight:10}}/>
<Input placeholder="Password" secureTextEntry={true} value={this.state.Password} onChangeText={ (text) => this.setState({ Password: text }) } placeholderTextColor="rgb(240,240,240)" />
</Item>
</View>
{this.state.Loading==true?
<ActivityIndicator
animating={true}
style={styles.indicator} />
:
<View>
<View style={{flexDirection:'row',justifyContent:'center',marginTop:15}}>
<View style={{width:'13%',justifyContent:'center'}}>
<TouchableOpacity onPress={() => this._toggleRememberme()}>
<Image source={this.state.isrememberme?checkboxcheck:checkboxuncheck} style={{width:28,height:28}}/>
</TouchableOpacity>
</View>
<View style={{width:'41%',justifyContent:'center'}}>
<Text onPress={() => this._toggleRememberme()} style={{fontSize:17,color:'rgb(56,56,56)'}} >Remember me</Text>
</View>
<View style={{width:'46%',justifyContent:'center'}}>
<Text onPress={() => this.props.navigation.navigate("forgotpass")} style={{textAlign:'right', fontSize:17,color:'rgb(56,56,56)'}} >Forgot password?</Text>
</View>
</View>
<Text onPress={() => this.props.navigation.navigate("signup")} style={{textAlign:'center', textDecorationLine:'underline', fontSize:17,color:'rgb(56,56,56)',marginTop:15}} >Create an Account</Text>
<Button onPress={() => this.signin()} block style={{backgroundColor:'rgb(107,29,43)', marginTop:15,height:50, borderRadius:8,borderWidth:1,borderColor:'rgb(117,170,70)'}}>
<Text style={{color:'#fff',fontSize:19}}>Login</Text>
</Button>
</View>
}
</View>
</Content>
</ImageBackground>
</Container>
Just to clairify, you would like for the form to appear fixed above the image background, and for the form and image background to move together as you scroll. So, currently your background is fixed, but the form is above and scrolls independently of the background?
I just want to make sure I have your question correct :)
I think when you use ImageBackground it will always behave in this way, hence the "background". If you want the form to move with the image you could try to position the form with "absolute" position on top of a regular Image component. You might want to try using react-native-elements or react-native-paper as they have Card and Surface components which can help to achieve this behaviour.
I realize this isn't a very definitive answer but I hope it helps in some way. Also you might want to just check any style props of the components which you have used as well as reviewing the documentation on ImageBackground. https://reactnative.dev/docs/imagebackground
My apologies that I couldn't give you a better answer.

React Native View below Flatlist is flickering

I have a view below flatlist. I want the view to be always at bottom of screen and it is wrapped inside KeyboardAvoidingView. Check video for more details
https://drive.google.com/file/d/1eeMfpH3AV7AqLNqAhlhQX5JmOQSRLbtp/view?usp=sharing
As soon as I comment my FlatList code then the bottom view does not flicker.
Below is my code
<View>
<FlatList ..../>
<KeyboardAvoidingView
behavior={Platform.OS == "ios" ? "padding" : "height"}
>
<SafeAreaView style={styles.bottomViewStyle}>
<TouchableOpacity>
<Image source={CAMERA_CHAT_ICON} />
</TouchableOpacity>
<View style={styles.textAreaViewStyle}>
<TextInput
placeholder="Start Typing..."
placeholderTextColor="#9b9b9b"
style={styles.textInputStyle}
/>
</View>
<TouchableOpacity>
<Image source={CHAT_SEND_ICON} />
</TouchableOpacity>
</SafeAreaView>
</KeyboardAvoidingView>
</View>
All components including the FlatList component should be wrapped inside the KeyboardAvoidingView. Also, SafeAreaViews should be placed at the root of the screen because it provides padding for SafeAreas.
<KeyboardAvoidingView behavior={Platform.OS == "ios" ? "padding" : "height"}>
<SafeAreaView>
<FlatList ... />
<View>
<TextInput ... />
</View>
</SafeAreaView>
</KeyboardAvoidingView>
See https://reactnative.dev/docs/keyboardavoidingview and https://reactnative.dev/docs/safeareaview for more examples.

I can't able to type a Textinput, keyboard hided within 2 sec in android mobile using react native

I am a beginner at React Native. When I try to type a text in a Text Input box, I'm not able to type, because the keyboard hides within 2 seconds. I don't know why this happens, here is my code, kindly solve this issue, this issue only occurs on Android devices.
Here is my code,
render() {
return (
<View style={styles.container1}>
<ScrollView>
<View style={styles.container}>
<View style={styles.SectionStyle}>
<Image source={require('../assets/padlock.png')} style={styles.ImageStyle} />
<TextInput
style={{flex:1}}
placeholder="Current Password"
underlineColorAndroid="transparent"
secureTextEntry
selectionColor={'#002B60'}
returnKeyType={'next'}
blurOnSubmit={false}
onSubmitEditing={() => this.passwordRef.focus()}
onChangeText={(oldpassword) => this.setState({oldpassword})}
/>
</View> </View>
</View>
</ScrollView>
</View>
);
}
}

Unable to set FlatList height inside a Modal

Normally the height of a FlatList is set by wrapping a around it.
This doesn't appear to work if I put it inside a modal component of react native.
Is there any other way to set the height for a FlatList?
<Modal
visible={visible}
transparent={true}
animationType='slide'
>
<View style={middleInnerContainer}>
<FlatList
data={this.props.vegetablesBenefit}
renderItem={modalBenefitItem}
keyExtractor={(item) => item.key}
scrollEnabled
/>
</View>
</Modal>
I've simplified this code to the basic structure I am using.
It works perfectly fine outside of a modal.
Can you be more specific? If you want a list inside a popup you can simply use the following code I wrote for creating a generic dialog popup!
<TouchableWithoutFeedback onPress={() => this.closeDialog()}>
<Modal
visible={this.state.showDialog}
transparent={true}
onRequestClose={() => this.closeDialog()}
animationType='slide'>
{/* tslint:disable-next-line:no-empty */}
<TouchableWithoutFeedback onPress={() => this.closeDialog()}>
<View style={styles.parentContainer}>
<View style={styles.childContainer}>
<View style={styles.viewContainer}>
{/* tslint:disable-next-line:no-empty */}
<TouchableWithoutFeedback onPress={() => { }}>
<View>
<Text style={styles.headerStyle}>{this.props.headerTitle}
</Text>
</View>
</TouchableWithoutFeedback>
{this.renderListComponent()}
</View>
</View>
</View>
</TouchableWithoutFeedback>
</Modal>
</TouchableWithoutFeedback>
Handles the touch outside as well. Let me know if this completes your requirement.