FaridSafi / react-native-gifted-chat

💬 The most complete chat UI for React Native
https://gifted.chat
MIT License
13.56k stars 3.55k forks source link

Unable to scroll to the top of the chat when the keyboard is open, and it doesn’t automatically scroll to the bottom when a new message is sent. #2527

Open nishmitha03 opened 2 months ago

nishmitha03 commented 2 months ago

Issue Description

  1. Unable to scroll to the top of the chat when the keyboard is open.
  2. The chat doesn’t automatically scroll to the bottom when a new message is sent

Steps to Reproduce / Code Snippets

1) Type a message in the chat. 2) Open the keyboard. 3) Attempt to scroll to the top of the chat.

Below is my code

import React, {useCallback, useEffect, useState} from 'react';
import {SafeAreaView} from 'react-native';
import {GiftedChat} from 'react-native-gifted-chat';

const ChatComponent = () => {
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    setMessages([
      {
        _id: 1,
        text: 'Hello developer',
        createdAt: new Date(),
        user: {
          _id: 2,
          name: 'React Native',
          avatar: 'https://placeimg.com/140/140/any',
        },
      },
    ]);
  }, []);

  const onSend = useCallback((messages = []) => {
    setMessages(previousMessages =>
      GiftedChat.append(previousMessages, messages),
    );
  }, []);

  return (
    <SafeAreaView style={{flex: 1}}>
      <GiftedChat
        messages={messages}
        onSend={messages => onSend(messages)}
        user={{
          _id: 1,
        }}
      />
    </SafeAreaView>
  );
};

export default ChatComponent;
import React from 'react';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import ChatComponent from './ChatComponent';

const App = () => {
  return (
    <SafeAreaProvider>
      <ChatComponent />
    </SafeAreaProvider>
  );
};

export default App;

Expected Results

  1. The chat should remain scrollable to the top even when the keyboard is open.
  2. The chat should automatically scroll to the bottom when a new message is sent.

Additional Information

Recording for -> Unable to scroll to the top of the chat when the keyboard is open.

https://github.com/user-attachments/assets/ec23b608-307a-4561-bf1b-93f98cd0e0cd

Recording for -> The chat doesn’t automatically scroll to the bottom when a new message is sent.

https://github.com/user-attachments/assets/3489cd87-2794-4ded-898c-9548f21fce58

nikita10001 commented 2 months ago

having the same issue

MrNapcae commented 2 months ago

having the same issue

osikes commented 4 weeks ago

same