我正在开发一个移动聊天应用程序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
我希望系统消息“此消息无法单击”应该是可单击的,并且在单击它时会显示警报消息“你好”。但它不起作用。