Can't scroll inside ScrollView, when there are TextInputs - react-native

I have ScrollView inside that ScrollView, I have TextInputs, the scroll doesn't work in the area of TextInput. How to fix that?
render () {
return (
<View>
<ScrollView
ref='keyboardScroll'
keyboardShouldPersistTaps={true}
>
<View>
<TextInput
placeholder='First Name'
/>
</View>
<View>
<TextInput
placeholder='Last Name'
/>
</View>
<ScrollView>
</View>
)}
Here is the video with the issue.

I found the solution of that problem. The main problem was that text font size was too big for the TextInput field, which causes scroll inside the TextInput, so there are 2 solutions: 1) decrease font size 2) make the height of the TextInput field bigger. Also this solution solved another problem: Placeholders in TextInput are moving during the scroll

I had the same problem on Android, where the placeholder was scrolling just a little bit up and down and preventing the ScrollView from scrolling. I managed to fix it by adding the following styles on the TextInput:
paddingTop: 0,
paddingBottom: 0,
paddingLeft: <whatever>,
paddingRight: <whatever>

Related

Keyboard and layout handling with React Native

I've been trying to figure out how to properly handle layout changes after keyboard opens up (At least on Android). I'm using latest Expo.
Example of my form:
<View style={{flex: 1}}>
<View style={{flex: 1}}></View>
<View style={{flex: 2}}>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<Button></Button>
</View>
</View>
The problem is, when i click on any TextInput, the keyboard squishes everything thats above it and it becomes unreachable until i close the keyboard.I've already tried using:
KeyboardAvoidingView + ScrollView inside
"softwareKeyboardLayoutMode": "pan" in app.json
KeyboardAwareScrollView - seems to be working, kinda, problem below
I also have a problem with "pan" setting, screen adjusts weirdly in a way that it will squish top elements when i click on a bottom TextInput, but wont when i click on a top TextInput, which breaks KeyboardAwareScrollView i guess (It adds different padding/height to the bottom of a screen depending on where i click to open a keyboard)
Does anybody have a better solution to this problem? I want it to simply enable scroll on view (add height ?) without squishing flexboxes or changing anything in my layout.
It's really tough to manage multiple inputs with help of the keyboard avoiding view from React Native Library.
To find the workaround for this, and fix the issues with the Multiple Inputs and Keyboard management in iOS, I have used an npm dependency known as react-native-keyboard-aware-scrollview
Which really helped me in achieving my goal.
You can also try the npm dependency, I hope it will surely help you in achieving your desired outcome.
Here I am attaching the HOC component, Using which I wrap my components in which I need to manage the input and keyboard avoiding.
HOC Component :
import * as React from "react"
import { View, TouchableWithoutFeedback, Keyboard } from "react-native"
import SafeAreaView from 'react-native-safe-area-view'
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"
/**
* Root component for screen managing safe area view and keyboard avoiding view
*/
const Root = (props) => {
const { style, children } = props
return (
<SafeAreaView style={{ flex: 1, backgroundColor: 'white' }}>
<KeyboardAwareScrollView
keyboardShouldPersistTaps={'always'}
contentContainerStyle={{
flexGrow: 1 // this will fix scrollview scroll issue by passing parent view width and height to it
}}
>
<TouchableWithoutFeedback
onPress={Keyboard.dismiss}
style={{ flexGrow: 1 }}
>
<View style={{ flexGrow: 1 }}>
{children}
</View>
</TouchableWithoutFeedback>
</KeyboardAwareScrollView>
</SafeAreaView>
)
}
export default Root
Simply wrap it with ScrollView, as seen below.
<ScrollView>
<View style={{flex: 1}}>
<View style={{flex: 1}}></View>
<View style={{flex: 2}}>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<Button></Button>
</View>
</View>
</ScrollView>

TextInput vanishes inside ScrollView React Native

Scenario: I want to achieve a situation like the code shown below. Where there will be:
A multiline TextInput with other components and the screen will be scrollable.
I don't want the TextInput to be scrollable.
Problem: What happens is, after writing a certain amount of lines in the TextInput, the texts vanishes. I can still select the text and get suggestion in the keyboard. It's like the texts and the TextInput became transperant. After the TextInput reaches the height of the phone screen, this problem occurs.
Is this a bug of React-Native? or am I doing something wrong here?
Note: I'm using "expo": "~40.0.0". Also, the code below is just to portrait the situation, not the actual code.
return (
<ScrollView>
<View style={styles.block} />
<View style={styles.block} />
<TextInput
value={content}
onChangeText={setContent}
placeholder="Start writing from here"
multiline
/>
<View style={styles.block} />
<View style={styles.block} />
</ScrollView>
);
const styles = StyleSheet.create({
block: {
height: 200,
backgroundColor: 'blue',
},
});
Try out any of following Workarounds:
Enabling scrollEnabled on the TextInput
Explicitly setting a height on the TextInput (eg. by dynamically measuring the contents)
<ScrollView scrollEnabled style={{ marginTop: 100 }}>
<TextInput multiline placeholder="type here" scrollEnabled={true} />
</ScrollView>

React Native: Fix TextInput at the bottom of the screen with a ScrollView

I need to fix the input in the bottom of the screen, so that keyboard pushes this input (similar to instagram comments).
Here's an example():
https://snack.expo.io/LPRwoGpik
It's working fine, but if I put the FlatList inside the ScrollView the bottom input is dissapearing.
What's the right way to solve this problem?
try this
<View style={{flex: 1,}} >
<ScrollView>
{content}
</ScrollView>
<TextInput style={{position: "absolute", bottom :0}}/>
</View>

Scrollview goes under status bar when using KeyboardAvoidingView

If you take a look on the left of the time on the status bar, you can see part of the scrollview showing. When scrolling up i can see the scrollview with all the elements ( pickers ,textinputs etc) scrolling underneath the statusbar.
My hierarchy looks like this
<React.Fragment>
<SafeAreaView forceInset={true} style={{ flex: 1, backgroundColor: colors.black, zIndex: 10000 }}>
<View style={{flex:1}}>
<Header/> //has certain height. had to add zIndex=10000 to avoid same issue
<KeyboardAvoidingView behavior='position'>
<ScrollViewWithContent/>
</KeyboardAvoidingView>
</View>
</SafeAreaView>
</React.Fragment>
Are you seeing anything obviously off?
Adding overflow:hidden; will do the trick. However i feel like this shouldnt be happening in the first place. The original bug is a weird state where part of the scrollview shows ( the text ) and part of it doesnt ( the background )

React Native avoid {width: '100%'} by default

My code is pretty simple: (relevant parts shown only)
<ScrollView style={{/* padding, centering... */}>
<Text>SHARE WITH YOU FRIENDS</Text>
</ScrollView>
Yet, when I inspect the Text node, its width is 100% of its container, and the grey background goes all the width.
Is there a layout setting to make this Text's width as small as possible? I.e. only until the end of the Text.
You can use alignSelf property:
<View style={{alignSelf: 'flex-start'}}>
<Text>SHARE WITH YOU FRIENDS</Text>
</View>
For Scroll view you can try like
<ScrollView contentContainerStyle={{ alignItems: 'flex-start'}}>
<Text >SHARE WITH YOU FRIENDS</Text>
</ScrollView>
Hope this will help!