我正在用react-native-gifted-chat开发一个移动聊天应用程序,我想让系统消息点击来执行一个功能。
我的代码在下面,但不知怎么不起作用。
import React, { Component } from 'react';
import { Image, ImageBackground, Text, Linking, SafeAreaView, ScrollView, StyleSheet, View } from 'react-native';
import { Body, Container, Header, Icon, Left, Right, Thumbnail } from "native-base";
import { Button, List } from 'react-native-paper';
import { GiftedChat, Composer } from 'react-native-gifted-chat';
export default class ChatScreen extends Component {
messages = [
{
_id: 1,
text: <Text onClick={() => { alert('hello')}} style={{ color: 'red' }}>This message can not be clickable</Text>,
createdAt: new Date(Date.UTC(2016, 5, 11, 17, 20, 0)),
system: true,
}
];
renderComposer = props => {
return (
<View style={{flexDirection: 'row'}}>
<Icon type='SimpleLineIcons' name='paper-clip' style={{ fontSize: 20, justifyContent: 'center', paddingTop: 10, paddingLeft: 5 }}/>
<Composer {...props} />
<Button>Submit</Button>
</View>
);
};
render() {
return (
<Container>
<GiftedChat
renderComposer={this.renderComposer}
messages={this.messages}
/>
</Container>
)
}
}
});这是我模拟器的截图。https://gyazo.com/bc1facffffcbe868fbce5cb15385890d
我希望系统消息‘这个消息不能被点击’应该是可点击的,它会在点击它时显示警告信息'hello‘。但不起作用。
发布于 2019-06-04 22:15:50
您会尝试在文本组件中使用onPress而不是onClick吗?
你也可以参考下面的内容。
发布于 2019-06-10 12:00:02
文本有一个onPress道具而不是onClick,所以您只需要将onClick更改为onPress。如果您要更改这个,那么您的消息将如下所示
messages = [
{
_id: 1,
text: <Text onPress={() => { alert('hello')}} style={{ color: 'red' }}>This message can not be clickable</Text>,
createdAt: new Date(Date.UTC(2016, 5, 11, 17, 20, 0)),
system: true,
}
];这肯定对你有用!
https://stackoverflow.com/questions/56446835
复制相似问题