-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different Bubble color for each user. #672
Comments
Yes use the renderBubble prop of the GiftedChat and pass a function like this
there you will return your Custom Bubble.js (Copy the code from the src folder in the node module)
In Bubble.js you will find the styles. You have to look at the wrapper in left and right and set the backgroundColor you want to. |
Thanks @mafiusu |
Yes, I use this pattern to display usernames in different colors. You could use this function:
Then you will pass the backgroundColor style in the Render Method of |
You saves my life. |
I close this issue but create a FAQ in readme to refer it: https://github.com/FaridSafi/react-native-gifted-chat#questions |
FYI this is the code example you want: renderBubble={props => {
return (
<Bubble
{...props}
textStyle={{
right: {
color: 'yellow',
},
}}
wrapperStyle={{
left: {
backgroundColor: 'red',
},
}}
/>
);
}} |
Hey guys, I've been struggling with understanding what you guys mean. Could you please help me out a little bit more? This is what my Gifted Chat looks like.
Here are the two helper functions you guys mentioned. I'm not sure how to use them in order to pass each individual bubble a color in order to get a distinct color. Please advise.
I'm uncertain where I should pass a single user in, because GiftedChat takes an array of messages so I don't know how to pass in a username so that it'll be used accordingly. |
Hey Loi, Inside renderBubble function props, you could actually get the currentMessage and its user, then you could decide on the color of that bubble like below: renderBubble = props => {
let username = props.currentMessage.user.name
let color = this.getColor(username)
return (
<Bubble
{...props}
textStyle={{
right: {
color: 'white'
}
}}
wrapperStyle={{
left: {
backgroundColor: color
}
}}
/>
)
} |
@jameshuynh Ohhh, thanks bud! |
How would you customize the color of the message timestamp?
<GiftedChat
messages={this.state.messages}
onSend={this.onSend}
renderCustomView={CustomView}
keyboardShouldPersistTaps="never"
user={{ _id: 1 }}
renderBubble={props => {
return (
<Bubble
{...props}
timeTextStyle={{
right: { color: 'red' }
}}
/>
);
}}
parsePatterns={this.parsePatterns}
/> Previous comment i.e. react-native-gifted-chat/src/Time.js Lines 12 to 15 in 36082ff
This doesn't work: <Bubble
{...props}
timeProps={{
textStyle: {
right: { color: 'black' },
},
}}
/> |
any luck @gianpaj ? |
so, the only way to achieve this behavior is by copying the source code for Bubble, which itself depends on other files in the source folder, as well as outside packages? shouldn't there be a 'getBubbleColor' prop? i mean, this is the first link under the Questions section on the readme, seems like a common enough issue that it warrants a better solution than basically forking the project... |
The prop is not being passed down to the |
@AndresTIY my PR #942 has been merged to master 🎉. Hopefully, a new release will be out soon 🙏 |
Just a tiny bit of additional information:
|
how to pass the props in the render |
@Nagasai97 See my updated comment All props on README. |
@gianpaj can i get the code of onSend function for class component...? |
Does anyone have an example of how to change the bubble styling when using typescript props? |
How is this done with functional component? |
This is the version with Functional Components
And then:
|
A more complete example on how to modify the styles of the text bubbles using functional components: #640 (comment) |
const renderTime = (props: TimeProps) => { const renderBubble = (props: Bubble["props"]) => { |
For those there is no change in the bubble styles just restart the server it works renderBubble={(props: any) => {
return (
<Bubble
{...props}
wrapperStyle={{
right: {
backgroundColor: "black",
},
left: {
backgroundColor: "#E5E5EA",
},
}}
/>
);
}} |
Issue Description
If more than 2 user in a conversation.
How can I set Bubble color for each user?
Thank you in advance!
Additional Information
The text was updated successfully, but these errors were encountered: