react-native-gifted-chat icon indicating copy to clipboard operation
react-native-gifted-chat copied to clipboard

The start of messages does not appear when the keyboard is active

Open ayrtonlima7 opened this issue 8 months ago • 5 comments

I've tried tinkering with various parts of the message list configuration but haven't found a solution

`import { useCallback, useEffect, useState } from 'react' import { Bubble, GiftedChat, IMessage } from 'react-native-gifted-chat' import { COLORS, spacing } from '@/constants' import { ActivityIndicator } from 'react-native' import { ChatbotInputComponent } from '@/components/chatbot-input-component/ChatbotInputComponent'

export const ChatBot = () => { const [messages, setMessages] = useState<IMessage[]>([]) const [text, setText] = useState('')

const customBubble = (props: any) => {
    return (
        <Bubble
            {...props}
            wrapperStyle={{
                left: {
                    paddingVertical: spacing.xxxl * 2,
                    backgroundColor: COLORS.BG_TAB_COLOR
                },
                right: {
                    paddingVertical: spacing.xxxl * 2,
                    backgroundColor: COLORS.BUTTON_COLOR
                }
            }}
            textStyle={{
                right: {
                    color: COLORS.GLOBAL_COLOR
                },
                left: {
                    color: COLORS.GLOBAL_COLOR
                }
            }}
        />
    )
}

useEffect(() => {
    setMessages([
        {
            _id: 1,
            text: 'Hi!, how can I help you?',
            createdAt: new Date(),
            user: {
                _id: 2,
                name: 'bot'
            }
        },
        {
            _id: 2,
            text: 'Hi!, how can I help you?',
            createdAt: new Date(),
            user: {
                _id: 2,
                name: 'bot'
            }
        },
        {
            _id: 3,
            text: 'Hi!, how can I help you?',
            createdAt: new Date(),
            user: {
                _id: 2,
                name: 'bot'
            }
        }
    ])
}, [])

const onSend = useCallback(() => {
    if (text.trim().length === 0) return
    const newMessage = {
        _id: Math.random().toString(),
        text: text,
        createdAt: new Date(),
        user: {
            _id: 1
        }
    }
    setMessages(previousMessages => GiftedChat.append(previousMessages, [newMessage]))
    setText('')
}, [text])

return (
    <GiftedChat
        renderLoading={() => <ActivityIndicator size={'large'} color={COLORS.GLOBAL_COLOR} />}
        renderTime={() => null}
        messages={messages}
        user={{
            _id: 1
        }}
        renderBubble={customBubble}
        renderAvatar={null}
        renderInputToolbar={() => {
            return (
                <ChatbotInputComponent
                    onPress={onSend}
                    value={text}
                    onSubmitEditing={onSend}
                    onChangeText={setText}
                />
            )
        }}
    />
)

} `

https://github.com/user-attachments/assets/3a9a8b1a-1f01-4ec0-a297-505ea6554ca7

ayrtonlima7 avatar Apr 13 '25 12:04 ayrtonlima7

+1

xiongxiongjiang avatar Apr 16 '25 07:04 xiongxiongjiang

Same here

brentlecomte-itp avatar Apr 18 '25 11:04 brentlecomte-itp

the same

chiefchief avatar Jun 02 '25 10:06 chiefchief

+1

cloudworkpro-sean avatar Jun 26 '25 20:06 cloudworkpro-sean

try this ! its work https://github.com/FaridSafi/react-native-gifted-chat/issues/2574#issuecomment-2599325795

MuazzezA avatar Jul 18 '25 06:07 MuazzezA