question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React gifted chat message alignment

See original GitHub issue

Issue 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
InovaXioncommented, Jan 14, 2021

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 have user={{ _id: 1 }} it’s not working but ‘user={{ _id: '1' }}’ works fine

0reactions
stale[bot]commented, Apr 18, 2022

Sorry, 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 😀 !!!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found