-
Notifications
You must be signed in to change notification settings - Fork 60
/
App.tsx
150 lines (144 loc) · 3.89 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import * as React from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';
import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import * as TEST_CONST from './testConstants';
import {PlatformInfo} from './PlatformInfo';
export default function App() {
const [value, setValue] = React.useState(TEST_CONST.EXAMPLE_CONTENT);
const [textColorState, setTextColorState] = React.useState(false);
const [linkColorState, setLinkColorState] = React.useState(false);
const [textFontSizeState, setTextFontSizeState] = React.useState(false);
const [emojiFontSizeState, setEmojiFontSizeState] = React.useState(false);
const [selection, setSelection] = React.useState({start: 0, end: 0});
const style = React.useMemo(() => {
return {
color: textColorState ? 'gray' : 'black',
fontSize: textFontSizeState ? 15 : 20,
};
}, [textColorState, textFontSizeState]);
const markdownStyle = React.useMemo(() => {
return {
emoji: {
fontSize: emojiFontSizeState ? 15 : 20,
},
link: {
color: linkColorState ? 'red' : 'blue',
},
};
}, [emojiFontSizeState, linkColorState]);
const ref = React.useRef<MarkdownTextInput>(null);
return (
<View style={styles.container}>
<PlatformInfo />
<MarkdownTextInput
multiline
autoCapitalize="none"
value={value}
onChangeText={setValue}
style={[styles.input, style]}
ref={ref}
markdownStyle={markdownStyle}
placeholder="Type here..."
onSelectionChange={e => setSelection(e.nativeEvent.selection)}
selection={selection}
id={TEST_CONST.INPUT_ID}
maxLength={30000}
/>
<Text style={styles.text}>{JSON.stringify(value)}</Text>
<Button
testID="focus"
title="Focus"
onPress={() => {
if (!ref.current) {
return;
}
ref.current.focus();
}}
/>
<Button
testID="blur"
title="Blur"
onPress={() => {
if (!ref.current) {
return;
}
ref.current.blur();
}}
/>
<Button
testID="reset"
title="Reset"
onPress={() => {
setValue(TEST_CONST.EXAMPLE_CONTENT);
setTextColorState(false);
setLinkColorState(false);
setTextFontSizeState(false);
setEmojiFontSizeState(false);
setSelection({start: 0, end: 0});
}}
/>
<Button
testID="clear"
title="Clear"
onPress={() => {
setValue('');
}}
/>
<Button
title="Toggle text color"
onPress={() => setTextColorState(prev => !prev)}
/>
<Button
title="Toggle link color"
onPress={() => setLinkColorState(prev => !prev)}
/>
<Button
title="Toggle text font size"
onPress={() => setTextFontSizeState(prev => !prev)}
/>
<Button
title="Toggle emoji font size"
onPress={() => setEmojiFontSizeState(prev => !prev)}
/>
<Button
title="Toggle all"
onPress={() => {
setTextColorState(prev => !prev);
setLinkColorState(prev => !prev);
setTextFontSizeState(prev => !prev);
setEmojiFontSizeState(prev => !prev);
}}
/>
<Button
title="Change selection"
onPress={() => {
if (!ref.current) {
return;
}
ref.current.focus();
setSelection({start: 0, end: 20});
}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
marginTop: 60,
},
input: {
fontSize: 20,
width: 300,
padding: 5,
borderColor: 'gray',
borderWidth: 1,
textAlignVertical: 'top',
},
text: {
fontFamily: 'Courier New',
marginTop: 10,
height: 100,
},
});