bubble messages within renderBubble function can't re-rendered after setState
See original GitHub issueHi every one, I want to animate a progressbar for every sound message duration when gets played, I have a PLAY ICON for any sound message, when I click on play icon, sound starts as well and I update the progressbar by setState, actually the progress gets update but the problem is my progressbar doesnt re-render to get progress value for progressbar. and also the play icon does not re-render to get red color.
I got something from:
my code is:
render(){
return (
<GiftedChat
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
user={{
_id: this.state.userId,
}}
renderBubble={this.renderBubble}
renderInputToolbar={this.renderInputToolbar.bind(this)}
/>
);
}
renderBubble = props => {
if (props.currentMessage.audio) {
return (
<View style={[{ width: 150, height: 70, backgroundColor: 'lightgray' }, props.position === 'left' ? { left: -41 } : {}]}>
<EIcon
name="google-play"
size={30}
color={this.state.playAudio ? "red" : "blue"}
style={{
left: 90,
position: "relative",
shadowColor: "#000",
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 0.5,
backgroundColor: "transparent"
}}
onPress={() => {
this.setState({
playAudio: true
});
const sound = new Sound(props.currentMessage.audio, "", error => {
if (error) {
console.log("failed to load the sound", error);
}
const duration = sound.getDuration();
const progressPhase = 1 / duration;
if (duration !== 0) {
this._interval = setInterval(() => {
this.setState({
progress: this.state.progress += progressPhase
});
if (this.state.progress >= 1) {
clearInterval(this._interval);
this.setState({
progress: 0.0,
playAudio: false
});
}
}, 1000);
}
sound.play(success => {
console.log(success, "success play");
if (!success) {
Alert.alert("There was an error playing this audio");
}
});
});
}}
/>
<Progress.Circle progress={this.state.progress} showsText size={35} />
</View>
);
} else {
return (
<Bubble
{...props}
textStyle={{
right: {
color: '#fff',
},
left: {
color: '#fff',
},
}}
wrapperStyle={{
left: {
backgroundColor: "orange",
left: -41
},
right: {
backgroundColor: 'green'
}
}}
/>
);
}
}
My Expections
I want to re-render progressbar with updating state { progress: 0.0 } when I call
this.setState({
progress: this.state.progress += progressPhase
});
// this should be re-render on every update
<Progress.Circle progress={this.state.progress} showsText size={35} />
Additional Information
- Nodejs version: v11.3.0
- React version: 16.6.3
- React Native version: 0.57.8
- react-native-gifted-chat version: 0.7.2
- Platform(s) (iOS, Android, or both?): on macos for Android
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:20
Top Results From Across the Web
react-native-gifted-chat only re-render last bubble
I want to custom ticks in Bubble with status: sending, sent, ... I guest the bubble is not re-render although I setState status...
Read more >React setState usage and gotchas - ITNEXT
setState () enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the...
Read more >When does React re-render components? - Felix Gerschau
Changing the state means that React triggers an update when we call the setState function (in React hooks, you would use useState )....
Read more >How does React decide to re-render a component? - Lucy Bain
A re-render can only be triggered if a component's state has changed. The state can change from a props change, or from a...
Read more >Event Bubbling and Event Catching in JavaScript and React
✨ Which Events Do Not Bubble and How Are They Handled? ✨ Event Listeners In React Version 16 and before VS Version 17+;...
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 Free
Top 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
Sorry about that. Maybe try to use
extraData
props?Actually I found the problem but still I dont know what is the solutions, The problem is with react-native-gifted-chat version 0.7.2 The above code works well on react-native-gifted-chat version 0.4.3
In version 0.4.3 there when I click play icon all sound message progessbar starts progressing instead of the one I clicked. I want just the one should start progressing which I have clicked.