Open fahad86 opened 1 year ago
you can do like this:
useState(() => {
if(message[0].state === 'sending' && message[0].user._id === currentUserId){
gitedRef.current.scrollToBottom()
}
} ,[message]}
you can do like this:
useState(() => { if(message[0].state === 'sending' && message[0].user._id === currentUserId){ gitedRef.current.scrollToBottom() } } ,[message]}
We used to do that in the past but with the change to functional components in version 2.1.0 not able to set a reference to giftedChat. Setting a ref yeilds the following error:
ERROR Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
can you please let me know how a reference can be set in the latest version of react-native-gifted-chat
Im using 0.16.3 and mofidy a lot of code for my job. If you using giftedChat lasted version, you can see the props:
scrollToBottom (Bool) - Enables the scroll to bottom Component (Default is false)
like this
<GiftedChat
...
scrollToBottom={(message[0].state === 'sending' && message[0].user._id === currentUserId}
...
/>
giftedChatRef.current._listRef._scrollRef.scrollTo(1)' & Working with "react-native-gifted-chat": "^2.4.0", & "react-native": "0.71.8", < GiftedChat messageContainerRef={giftedChatRef} />
const giftedChatRef = useRef<any>();
<GiftedChat
... other code ...
messageContainerRef={giftedChatRef}
... other code ...
</GiftedChat>
Then anywhere in your code, for example onSend, you can call this
if (giftedChatRef.current) {
giftedChatRef.current._listRef._scrollRef.scrollToEnd();
}
Issue Description
Changes in message list is not automatically triggering the message list to scroll down. (Basically scrollToBottom inside GiftedChat.js is not getting triggered on new messages)
Steps to Reproduce / Code Snippets
Expected Results
The list should scroll down to the bottom to reveal the newly sent / received messages
Additional Information