I am making a chat application. I am using flatlist to show all the contents of chat. I am trying to scroll to end of the screen whenever new message comes up.
Till here everything is working fine.
But I wanted to have extra padding after the latest message comes up. The problem is auto scroll is not getting scrolled to those extra space, it only scrolls to the message part.
Below is my code:
const messagesScrollView = useRef<FlatList | null>();<KeyboardAvoidCommonView><FlatList contentContainerStyle={{ flexGrow: 1, paddingBottom: 120, paddingTop: 5, }} style={{ paddingBottom: 100, paddingTop: 5, flex: 1 }} ref={(ref) => { messagesScrollView.current = ref; }} onLayout={() => messagesScrollView.current?.scrollToEnd({animated: true}) } data={messageList} onContentSizeChange={() => { messagesScrollView.current?.scrollToEnd({animated: true}); }} renderItem={({item}) => { return (<View onLayout={(event) => { style={{ marginVertical: 5, marginLeft: 5, width: '100%', marginTop: 25, }}> {getMessageBackground(item)}</View> ); }}></FlatList></KeyboardAvoidCommonView>
You can see that I have given paddingBottom: 120,
in contentContainerStyle
, this is part of the screen where autoscroll does not go. I have been trying to find the issues since many hours, but unable to find it. Please help.