@@ -4,15 +4,17 @@ import {
4
4
StyleSheet ,
5
5
View ,
6
6
ActivityIndicator ,
7
- Platform
7
+ Platform ,
8
+ Linking ,
9
+ Clipboard
8
10
} from 'react-native'
9
11
import Ionicons from 'react-native-vector-icons/Ionicons'
10
12
import { NativeStackNavigationProp } from '@react-navigation/native-stack'
11
13
12
14
import globalStyle from '../globalStyle'
13
15
import useDarkMode from '../context/useDarkMode'
14
- import SettingsContext from '../context/settingsContext'
15
16
import ConnectionContext from '../context/connectionContext'
17
+ import SettingsContext , { Settings } from '../context/settingsContext'
16
18
import {
17
19
ChatToJsx ,
18
20
parseValidJson ,
@@ -37,22 +39,45 @@ interface Message {
37
39
text : MinecraftChat
38
40
}
39
41
40
- const renderItem = ( colorMap : ColorMap ) => {
42
+ const renderItem = ( colorMap : ColorMap , settings : Settings ) => {
41
43
const ItemRenderer = ( { item } : { item : Message } ) => (
42
44
< View style = { styles . androidScaleInvert } >
43
- < ChatToJsx chat = { item . text } component = { Text } colorMap = { colorMap } />
45
+ < ChatToJsx
46
+ chat = { item . text }
47
+ component = { Text }
48
+ colorMap = { colorMap }
49
+ clickEventHandler = { async ce => {
50
+ // TODO: run_command, suggest_command and URL prompt support.
51
+ if (
52
+ ce . action === 'open_url' &&
53
+ settings . webLinks &&
54
+ ( ce . value . startsWith ( 'https://' ) || ce . value . startsWith ( 'http://' ) )
55
+ ) {
56
+ await Linking . openURL ( ce . value )
57
+ } else if ( ce . action === 'copy_to_clipboard' ) {
58
+ Clipboard . setString ( ce . value )
59
+ } // No open_file/change_page handling.
60
+ } }
61
+ />
44
62
</ View >
45
63
)
46
64
return ItemRenderer // LOW-TODO: Performance implications?
47
65
} // https://reactnative.dev/docs/optimizing-flatlist-configuration
48
- const ChatMessageList = ( props : { messages : Message [ ] ; darkMode : boolean } ) => {
66
+ const ChatMessageList = ( props : {
67
+ messages : Message [ ]
68
+ darkMode : boolean
69
+ settings : Settings
70
+ } ) => {
49
71
return (
50
72
< FlatList
51
73
inverted = { Platform . OS !== 'android' }
52
74
data = { props . messages }
53
75
style = { [ styles . androidScaleInvert , styles . chatArea ] }
54
76
contentContainerStyle = { styles . chatAreaScrollView }
55
- renderItem = { renderItem ( props . darkMode ? mojangColorMap : lightColorMap ) }
77
+ renderItem = { renderItem (
78
+ props . darkMode ? mojangColorMap : lightColorMap ,
79
+ props . settings
80
+ ) }
56
81
/>
57
82
)
58
83
}
@@ -207,7 +232,11 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
207
232
) }
208
233
{ loggedIn && (
209
234
< >
210
- < ChatMessageListMemo messages = { messages } darkMode = { darkMode } />
235
+ < ChatMessageListMemo
236
+ messages = { messages }
237
+ darkMode = { darkMode }
238
+ settings = { settings }
239
+ />
211
240
< View style = { darkMode ? styles . textAreaDark : styles . textArea } >
212
241
< TextField
213
242
value = { message }
0 commit comments