当我收到另一条短信时,我必须向上滚动一点以显示新信息。当我发送消息时,它的工作方式不同,它只是显示而无需滚动
RN 0.59,SignalR
我如何收到消息
componentDidMount() {
this._isMounted = true;
this.refreshDataFromServer();
hub.on("message", (id, name, msg, img, uId) => {
if (this._isMounted) {
if (id !== null) {
//let mess = '{"Name":"' + name + '","Message":"' + msg + '","Image":"' + img + '"}';
let mess = '{"Id":"' + id + '","Name":"' + name + '","Message":"' + msg + '"}';
var obj = JSON.parse(mess.toString());
this.state.data.push(obj);
}
}
});
hub.on("Loading", () => { }
);
hub.on("doneLoad", () => { }
);
}
我的单位列表
render() {
return (
<View style={styles.container}>
<FlatList
data={this.state.data}
removeClippedSubviews={false}
extraData={this.state.data}
ref={(ref) => { this.flatListRef = ref; }}
onContentSizeChange={()=> this.flatListRef.scrollToEnd()}
renderItem={({ item, index }) => {
return (
<FlatListItem item={item} index={index} navigation={this.props.navigation}>
</FlatListItem>);
}}
keyExtractor={(item, index) => String(index)}
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this.onRefresh}
/>}
/>
<View style={styles.footer}>
<View style={styles.inputContainer}>
<TextInput style={styles.inputs}
multiline = {true}
ref={input => { this.textInput = input }}
placeholder="Write a message..."
underlineColorAndroid='transparent'
onChangeText={(text) => this.updateValue(text, 'sendMessage')}>
</TextInput>
</View>
<TouchableOpacity style={styles.btnSend}
onPress={this.sendMessage}>
<Image source={{ uri: "https://png.icons8.com/small/75/ffffff/filled-sent.png" }} style={styles.iconSend} />
</TouchableOpacity>
</View>
</View>
);
}
我是RN的新手,所以我真的不知道RN的生命周期如何工作。谢谢
答案 0 :(得分:1)
您不应直接将值设置为#include <iostream>
int diagonal(int array[][4])
{
int sum = 0;
for(int I = 0; I < 4; I++)
{
sum += array[I][I];
}
return sum;
}
int main()
{
int array[4][4] = {{1,2,3,4}, {1,2,3,4}, {1,2,3,4}, {1,2,3,4}};
std::cout << "sum is " << diagonal(array) << std::endl;
return 0;
}
之类的状态
它不会触发渲染。相反,您需要使用setState
this.state.data.push(obj)