React gifted chat message alignment
See original GitHub issueIssue Description
I cannot get messages from two users to align on the left and right side, while pulling them from state. They all go on the left side. If i try to post a new message, that message goes on the right side as expected, but not while pulling them from state.
Steps to Reproduce / Code Snippets
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { GiftedChat } from 'react-native-gifted-chat';
import { StyleSheet, Text, View } from 'react-native';
export default function App() {
const [messages, setMessages] = useState([
{
_id: 1,
text: 'This is a quick reply. Do you love Gifted Chat? (radio) KEEP IT',
createdAt: new Date(),
user: {
_id: 2,
name: 'React Native',
},
},
{
_id: 2,
text: 'This is a quick reply. Do you love Gifted Chat? (checkbox)',
createdAt: new Date(),
user: {
_id: 3,
name: 'React',
},
}
]);
const onSend = (newMessage = []) => {
setMessages(GiftedChat.append(messages, newMessage));
};
return (
<GiftedChat
messages={messages}
onSend={newMessage => onSend(newMessage)}
user={{
_id: 1,
}}
/>
);
}
Expected Results
The messages should be left and right aligned, but they are just left aligned. Posting a new message is not a problem, pulling them from state is.
Additional Information
- Nodejs version: 12.18.4
- React version: 17.0.0
- React Native version: 0.63.4
- react-native-gifted-chat version: 0.16.3
- Platform(s) (iOS, Android, or both?): Web
- TypeScript version: 4.1.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
React gifted chat message alignment - Stack Overflow
I am very glad to answer this question for the right alignment one message in right and one message on the left you...
Read more >gifted chat ui library, messages alignment problem : r/react - Reddit
Hello Folks,. I am trying to display messages from two different users, but i cannot get them to display properly. The messages are...
Read more >react-native-gifted-chat - npm
Gifted Chat uses onLayout to determine the height of the chat container. To trigger onLayout during your tests, you can run the following...
Read more >react-native-gifted-chat-rncc - npm package - Snyk
Features. Fully customizable components; Composer actions (to attach photos, etc.) Load earlier messages; Copy messages to clipboard; Touchable ...
Read more >Serverless Chat APP with React Native Gifted Chat | UI Part
In this video, I will be sharing with you how to build a chat app in react native. This video is actually the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The user id of
<GiftedChat messages={messages} onSend={newMessage => onSend(newMessage)} user={{ _id: 1, }} />
have to be the same as the user id message. If you want ReactNative to be the user at right juste change the id to 2. If you want React, change it to 3… If it still not working try with quotes, for me when i haveuser={{ _id: 1 }}
it’s not working but ‘user={{ _id: '1' }}
’ works fineSorry, but this issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. BTW Thank you for your contributions 😀 !!!