React native flexbox not adapting correctly - ios

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.

Related

Native iOS list of buttons with arrow to the right

I have used React with MUI and starting to explore React Native. I have read the documentation but can not seem to find this basic example.
How do I create a list of buttons(button group) with icons to the right?
I would like to do something similar to MUI like <Button endIcon={<ArrowRight />} />
but achieve the Native iOS look and feel.
Like the Settings app on iOS:
| General —-——————————————- —> |
| Control Center —————————- —> |
| Display & Brightness ———— —> |
Is there a way to do this without coding the entire thing from scratch?
There is probably a third party package for this somwhere, but my advice would be to use SectionList from react-native and RectButton from react-native-gesture-handler to get the native ios/android feel.
You can use FlatList with custom buttons and apply styles to it.
https://reactnative.dev/docs/flatlist
Example of button content:
<View style={{flexDirection: 'row'}}>
<View style={{flex: 0.3}}>Icon here</View>
<View style={{flex: 0.5}}><Text>Text here</Text></View>
<View style={{flex: 0.2, alignItems: 'flex-end'}}>Icon here</View>
</View>

React Native with ScrollView feels sluggish

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

React Native: How to make a view stick on screen while the screen changes?

I'm building a podcasting app with react native and I would like to implement the mini player you see at bottom of screen in most podcasting/music apps. See image below. I want to make the mini player stick no matter which screen you navigate to. Any idea how to implement this in react native? I'm using react navigation as the main navigator right now https://reactnavigation.org/.
The best way to do this is use the magic of flexbox.
Think about your app as combination of two major screens.
1) The part with header, navigation menus and the playlist (inside etc.)
2) The player
Try this layout
<View style={styles.container}>
<View style={styles.firstBox}>
1)
</View>
<View style={styles.secondBox}>
2)
</View>
</View>
Now all you have to do is assign proper styles
const styles = {
container: {
flex: 1,
},
firstBox: {
flex: 8
},
secondBox: {
flex: 2
}
}
This is enough for the basic structure. You can design accordingly.

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 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