Fixed footer in react native with FlatList - react-native

Following this question on fixed footer with a ScrollView, I'm trying to implement a fixed footer on the screen with a FlatList. I have tried to use the answer provided by putting the flat list inside a view, but then none of the items are rendered. Does any one know how to implement a fixed footer with a flat list as the other main element of component?

Using this flex solution I managed to do it with a couple of nested Views:
<View style={{flex: 1}}>
<View style={{flex: 0.9}}>
<FlatList/>
</View>
<View style={{flex: 0.1}}/>
</View>

FlatList comes with footer support in the form of ListFooterComponent
Try adding something like this to your flatlist
ListFooterComponent={() => <Text>Footer content</Text>}
Hope this helps!

It is similar to the answer above, but I think this also works.
<View style={{flex: 1}}>
<View style={{flex: 1}}>
<FlatList/>
</View>
<View />
</View>

To complete the solution of Tom and avoid a gap/space at the bottom of the screen.
Use an integer for flex value
<View style={{flex: 1}}>
<View style={{flex: 1}}>
<FlatList/>
</View>
<View style={{flex: 0}}/>
</View>

Related

How to align column of text in react native

How can I align a column of text to the right like the image below in react native? I have tried setting the textAlign to 'right' and setting alignSelf to 'flex-end', but it doesn't seem to be working.
Image
You can do like this:
<View style={{alignItems:'flex-end'}}>
<View style={{flex:1}}>
<Text>TOTAL</Text>
</View>
<View style={{flex:1}}>
<Text>100</Text>
</View>
<View style={{flex:1}}>
<Text>200</Text>
</View>
<View style={{flex:1}}>
<Text>300</Text>
</View>
<View style={{flex:1}}>
<Text>400</Text>
</View>
<View style={{flex:1}}>
<Text>500</Text>
</View>
</View>
The alignItems property in Flexbox only works when the items has the flex property.
Check the documentation here: https://reactnative.dev/docs/flexbox#align-items
Result:

How to make TouchableOpacity wrap its content when nested inside parent that has flex = 1

I know that as default TouchableOpacity always has width as wrap-content. But I place it inside a View that has flex: 1. TouchableOpacity's width become match-parent/take the full width of the screen.
<View style={ {flex:1} }>
<TouchableOpacity>
<Text>I'm button</Text>
</TouchableOpacity>
</View>
The question is how could I make the TouchableOpacity wrap-content while nested inside a View like that.
Thanks
You will have to use position: "absolute" style for the TouchableOpacity
<View style={{flex:1}}>
<TouchableOpacity style={{position: "absolute" }}>
<Text>I'm button</Text>
</TouchableOpacity>
</View>
You can also use
alignSelf:'flex-start' can use center or flex-end as well.
you can style TouchableOpacity like this so that TouchableOpacity will have it's own style
<View style={ {flex:1} }>
<TouchableOpacity style={{width:'80%',height:'20%'}}>
<Text>I'm button</Text>
</TouchableOpacity>
</View>

Nested ScrollView can not scroll to bottom

I pull the scrollView to the bottom and it bounce back.
<ScrollView style={{flex: 1}}>
<View></View>
....
<ScrollView style={{flex: 1}}></ScrollView>
</ScrollView>
The nested ScrollView needs the exact height.
<ScrollView style={{flex: 1}}>
<View></View>
....
<ScrollView style={{height: 400}}></ScrollView>
</ScrollView>

React Native ScrollView does not scroll in landscape mode

I am using scrollView component to scroll component. It works in local build. But after creating apk file it doesn't work. what can i do.
<View style={{ flex: 1 }}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }} style={{ flex: 1 }}>
<View style={styles.container}>
{
submit ?
isPreview ?
<Text>Preview Page</Text> : <Text style={styles.text}>Thank you!</Text>
: <Questions />
}
<PoweredByPEX />
</View>
</ScrollView>
</View>
i have used View and scrollView component here. i can debug after APK build file. what can i do now. i have used flex layout here. is there any way to sort it out.

How react native scroll text?

How react native scroll text?
I have a long text in a fixed height container. I want to show a part of text in that container and scroll it when I want to see more.
I have try overflow scroll but react native seems not support overflow scroll.
Thanks.
You can use ScrollView for this case. Just put your text inside it and set height to scroll view.
I'm used the following code. Take ScrollView and put your any element inside ScrollView.
render() {
return(
<View style={styles.container}>
<ScrollView>
<Text>
Add your text
</Text>
</ScrollView>
</View>
);
}
There is currently a limitation in React Native where you can't set height directly on the ScrollView style prop. So, I suggest you do the following if you also want to set the height:
<View style={{ height: 100 }}>
<ScrollView>
<Text>
Your text goes here.
</Text>
</ScrollView>
</View>
Or alternatively using flexGrow:
<ScrollView style={{ flexGrow: 0.2 }}>
<Text>
Your text goes here.
</Text>
</ScrollView>
Relevant issue I found: https://github.com/facebook/react-native/issues/3422
<View style={{ height: hp(3)}}>
<ScrollView>
<Text style={{ fontSize: hp(2) }}>
Your text goes here
</Text>
</ScrollView>