React Native with ScrollView feels sluggish - ios

Any idea why ScrollView + multiline TextInput + KeyboardAvoidingView feels really sluggish? I'm using react-navigation with the react-native-screen for the native modal look. The screenshot gif below is taken on emulator but it behave similarly even on the real device (notice that there is a flash of blue background just before keyboard showed up)
My code looks something like (I set the KeyboardAvoidingView background to pink so it's easy to spot and ScrollView background is set to blue
<KeyboardAvoidingView behavior={'padding'} style={{flex: 1, backgroundColor: 'pink'}} keyboardVerticalOffset={48}>
<View style={{flex: 1}}>
<View style={styles.header}>
<Text>{date}</Text>
<Button title="Delete"/>
<Button title="Save"/>
</View>
<ScrollView keyboardDismissMode={'interactive'} style={{flex:1, backgroundColor: 'blue'}}>
<TextInput onChangeText={(text) => setNote(text)}
placeholder='Note'
value={note}
multiline={true}
scrollEnabled={false}
style={{flex: 1, backgroundColor: '#fff'}}
/>
</ScrollView>
</View>
</KeyboardAvoidingView>
I'm also using react-native-elements, react-navigation+react-native-screens for the native modal look
PS - I tried not using ScrollView and simply using TextInput with scrollable={true} which seems to be working but the problem with that is I can't dismiss the keyboard once the keyboard is shown

Related

How to have fixed header after keyboard is shown on iOS?

The fixed header is scrolling after keyboard is open on iOS device. Is there any possibility to have fixed header after keyboard is open? I do not want to have header scrolling with the content.
Here is explained similar problem:
https://medium.com/#im_rahul/safari-and-position-fixed-978122be5f29
I am facing the problem in the React project using Cordova.
Thank you very much for your help.
use keyboardAvoidingView from 'react-native'
docs
import {
KeyboardAvoidingView
} from 'react-native';
<KeyboardAvoidingView behavior="padding" style={styles.container}>
<View style={styles.inputContainer}>
<TextInput
returnKeyType="next"
placeholder="Mobile No."
placeholderTextColor="powderblue"
keyboardType="number-pad"
onSubmitEditing={() => this.passwordInput.focus()}
style={styles.input}
onChangeText={(value) => this.setState({mobileno:value})}
value={this.state.mobileno}
/>
<TextInput
returnKeyType="go"
placeholder="Password"
placeholderTextColor="powderblue"
style={styles.input}
secureTextEntry
ref={input => (this.passwordInput = input)}
onChangeText={(value) => this.setState({pssd:value})}
value={this.state.pssd}
/>
</View>
</KeyboardAvoidingView>
If you are hiding status bar the KeyboardAvoiding will push everything including the header to top, it’s a bug of KeyboardAvoidingView in react native.
To make your header fixed while keyboard is shown, make your statusbar hidden=false

Handling the status bar on iOS

Is there a goto way to handle the status bar on iOS? For my app, I just want everything to be below the status bar.. but it looks like the only way to do that is to go to every single component and add padding? I would guess theres a way to do it in xcode but I have no clue!
Thanks!
There is already a component in react-native for the StatusBar
You just need to add it as
<YourParentWrapper style={{flex: 1}}>
<View style={{ height, backgroundColor }}>
<StatusBar { ...props } />
</View>
// ... Your navigation or the child components
</YourParentWrapper>
where the height is
Platform.OS === 'ios' ? 20 : StatusBar.currentHeight
This will handle your components below the default status bar for all the devices

iOS TextInput styles in React Native

Elements such as <Button/> and <TextInput/> get rendered with default styles on Android but on iOS they are pretty much unstyled. Is there a way to get platform styles (e.g. borders and padding) applied on iOS without reproducing them in CSS?
For example
<View style={{flex:1, justifyContent: 'center'}}>
<Text>Please sign in</Text>
<TextInput placeholder="Username"/>
<TextInput placeholder="Password"/>
<Button onPress={() => {}} title="Sign in"/>
</View>
https://github.com/tombenner/nui
to apply them you can use platform.select

React native flexbox not adapting correctly

Description
I’m developing a react native application with a three-column keyboard. I’ve based the keyboard on a vertical flex layout. Each row in the keyboard is configured with an horizontal flex layout. Buttons and the horizontal and vertical separators are simple views.
On particular conditions it seems that the flex layout cannot correctly size views.
For instance see the pictures below for iPhone 6 screen size: the three buttons are all equally sized to 123.5 width and a 0.5 blank space is clearly visible between the second and the third column.
Do you guys have any hypothesis on why does this happen?
Reproduction
I’ve put some sample code here: https://rnplay.org/apps/Vl7nVg
In this example however the problem does NOT seem to appear but it uses react v0.31.
Trying to run the sample locally with v0.35 causes the problem.
Additional Information
React Native version: 0.35
Platform: iOS
Operating System: MacOS
Remove the last line verticalLine style from each row.
<View style={styles.verticalLine}/>
Currently your each row is like this.
<View style={styles.row}>
<View style={styles.verticalLine}/>
<View style={styles.button}>
<Text style={styles.buttonText}>1</Text>
</View>
<View style={styles.verticalLine}/>
<View style={styles.button}>
<Text style={styles.buttonText}>2</Text>
</View>
<View style={styles.verticalLine}/>
<View style={styles.button}>
<Text style={styles.buttonText}>3</Text>
</View>
<View style={styles.verticalLine}/>
</View>
After removing it becomes,
<View style={styles.row}>
<View style={styles.verticalLine}/>
<View style={styles.button}>
<Text style={styles.buttonText}>1</Text>
</View>
<View style={styles.verticalLine}/>
<View style={styles.button}>
<Text style={styles.buttonText}>2</Text>
</View>
<View style={styles.verticalLine}/>
<View style={styles.button}>
<Text style={styles.buttonText}>3</Text>
</View>
</View>
This change removed the extra blank space.
Note:
Not sure why this line was causing an issue. May be some issue with react-native 0.35.0 iOS implementation. Your code worked fine in Android.

React Native sticky footer with TextInput

The problems statement is similar to this question
But I am looking for some pointers to implement the same with react-native.
I am building a chat window (like iMessage, whatsapp) where messages(ListView) come on top with a sticky footer containing a TextInput.
I am able to get a sticky footer, but when someone tries to enter text with TextInput in footer, the keyboard hides the TextInput. I tried approaches mentioned in this post, but none seem to work because of presence of ListView above.
Here is what my current layout code looks like:
<View style={styles.container}>
<ListView
automaticallyAdjustContentInsets={false}
keyboardDismissMode="on-drag"
keyboardShouldPersistTaps={true}
showsVerticalScrollIndicator={false}
/>
<View style={styles.textContainer}>
<TextInput/>
</View>
</View>

Resources