首页 > 解决方案 > React Native - 有天赋的聊天消息问题

问题描述

我正在使用react-native-gifted-chat版本“^0.16.3”,但每次收到新消息时,它只会更新最后 2 条消息。我可以做些什么来更新新消息的完整聊天列表,这是正确的做法吗?

<View style={{
                    backgroundColor: 'white',
                    padding: 10,
                    width: "85%",
                    borderRadius: 5,
                    shadowColor: '#000',
                    shadowOffset: { width: 0, height: 0 },
                    shadowOpacity: 0.4,
                    shadowRadius: 1,
                    elevation: 5
                }}>
                    {/* <Text color={'black'} bold size={'4.4%'} style={{ paddingLeft: 10 }} >Client wants to hire you</Text> */}
                    <Bubble
                        {...item}
                        allowFontScaling={false}
                        wrapperStyle={{
                            right: {
                                backgroundColor: Theme.darkSkyBlue,
                                width:'100%'
                            },
                            left: {
                                backgroundColor: Theme.white,
                                width:'100%'
                            }
                        }}
                    />
                    { !answered && type === "button" && (
                        <Row style={{width:'100%'}}>
                            <Btn style={{width:'48%'}} onPress={() => requestOpportunities(State.TrainerHire, requestId, _id)} yes>
                                <Btn.Text allowFontScaling = {false}>YES</Btn.Text>
                            </Btn>
                            <Btn style={{width:'48%'}} activeOpacity={0.3} onPress={() => requestOpportunities(State.TrainerAccept, requestId, _id)} packages>
                                <Btn.Text color={'blue'} allowFontScaling = {false}>NO</Btn.Text>
                            </Btn>
                        </Row>
                    )}
                </View>

这是我的代码,当用户单击是或否按钮时,它应该隐藏这些按钮。它在最后一条消息时工作,但如果在此消息之后有一些消息,它就不起作用。

标签: react-nativereact-native-gifted-chat

解决方案


为了解决这个问题,我在屏幕上放置了一个加载器,并使用 API 更新了整个内容。


推荐阅读