|
1 | 1 | import * as React from 'react'; |
2 | 2 |
|
3 | | -import {Button, Platform, StyleSheet, Text, View} from 'react-native'; |
4 | | - |
| 3 | +import {StyleSheet, View} from 'react-native'; |
5 | 4 | import {MarkdownTextInput} from '@expensify/react-native-live-markdown'; |
6 | | -import type {TextInput} from 'react-native'; |
7 | | - |
8 | | -const DEFAULT_TEXT = ['Hello, *world*!', 'https://expensify.com', '# Lorem ipsum', '> Hello world', '`foo`', '```\nbar\n```', '@here', '@someone@swmansion.com', '#room-mention'].join('\n'); |
9 | | - |
10 | | -function isWeb() { |
11 | | - return Platform.OS === 'web'; |
12 | | -} |
13 | | - |
14 | | -function getPlatform() { |
15 | | - if (isWeb()) { |
16 | | - return 'web'; |
17 | | - } |
18 | | - // @ts-expect-error it works |
19 | | - return Platform.constants.systemName || Platform.constants.Brand; |
20 | | -} |
21 | | - |
22 | | -function getPlatformVersion() { |
23 | | - return Platform.Version; |
24 | | -} |
25 | | - |
26 | | -function getBundle() { |
27 | | - return __DEV__ ? 'dev' : 'production'; |
28 | | -} |
29 | | - |
30 | | -function getRuntime() { |
31 | | - if ('HermesInternal' in global) { |
32 | | - const version = |
33 | | - // @ts-expect-error this is fine |
34 | | - // eslint-disable-next-line es/no-optional-chaining |
35 | | - global.HermesInternal?.getRuntimeProperties?.()['OSS Release Version']; |
36 | | - return `Hermes (${version})`; |
37 | | - } |
38 | | - if ('_v8runtime' in global) { |
39 | | - // @ts-expect-error this is fine |
40 | | - // eslint-disable-next-line no-underscore-dangle |
41 | | - const version = global._v8runtime().version; |
42 | | - return `V8 (${version})`; |
43 | | - } |
44 | | - return 'JSC'; |
45 | | -} |
46 | | - |
47 | | -function getArchitecture() { |
48 | | - return 'nativeFabricUIManager' in global ? 'Fabric' : 'Paper'; |
49 | | -} |
50 | | - |
51 | | -function getReactNativeVersion() { |
52 | | - const {major, minor, patch} = Platform.constants.reactNativeVersion; |
53 | | - return `${major}.${minor}.${patch}`; |
54 | | -} |
55 | | - |
56 | | -function getRandomColor() { |
57 | | - return `#${Math.floor(Math.random() * 16777215) |
58 | | - .toString(16) |
59 | | - .padStart(6, '0')}`; |
60 | | -} |
61 | 5 |
|
62 | 6 | export default function App() { |
63 | | - const [value, setValue] = React.useState(DEFAULT_TEXT); |
64 | | - const [markdownStyle, setMarkdownStyle] = React.useState({}); |
65 | | - const [selection, setSelection] = React.useState({start: 0, end: 0}); |
66 | | - |
67 | | - // TODO: use MarkdownTextInput ref instead of TextInput ref |
68 | | - const ref = React.useRef<TextInput>(null); |
69 | | - |
70 | 7 | return ( |
71 | | - <View style={styles.container}> |
72 | | - <View style={styles.platform}> |
73 | | - <Text> |
74 | | - Platform: {getPlatform()} {getPlatformVersion()} |
75 | | - </Text> |
76 | | - <Text>Bundle: {getBundle()}</Text> |
77 | | - {!isWeb() && ( |
78 | | - <> |
79 | | - <Text>Architecture: {getArchitecture()}</Text> |
80 | | - <Text>RN version: {getReactNativeVersion()}</Text> |
81 | | - <Text>RN runtime: {getRuntime()}</Text> |
82 | | - </> |
83 | | - )} |
84 | | - </View> |
85 | | - {/* <Text>MarkdownTextInput singleline</Text> |
86 | | - <MarkdownTextInput |
87 | | - autoCapitalize="none" |
88 | | - value={value} |
89 | | - onChangeText={setValue} |
90 | | - style={styles.input} |
91 | | - /> */} |
92 | | - <Text>MarkdownTextInput multiline</Text> |
93 | | - <MarkdownTextInput |
94 | | - multiline |
95 | | - autoCapitalize="none" |
96 | | - value={value} |
97 | | - onChangeText={setValue} |
98 | | - style={styles.input} |
99 | | - ref={ref} |
100 | | - markdownStyle={markdownStyle} |
101 | | - placeholder="Type here..." |
102 | | - onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} |
103 | | - selection={selection} |
104 | | - /> |
105 | | - {/* <Text>TextInput singleline</Text> |
106 | | - <TextInput |
107 | | - autoCapitalize="none" |
108 | | - value={value} |
109 | | - onChangeText={setValue} |
110 | | - style={styles.input} |
111 | | - /> */} |
112 | | - {/* <Text>TextInput multiline</Text> |
113 | | - <TextInput |
114 | | - multiline |
115 | | - autoCapitalize="none" |
116 | | - value={value} |
117 | | - onChangeText={setValue} |
118 | | - style={styles.input} |
119 | | - /> */} |
120 | | - <Text style={styles.text}>{JSON.stringify(value)}</Text> |
121 | | - <Button |
122 | | - title="Focus" |
123 | | - onPress={() => { |
124 | | - if (!ref.current) { |
125 | | - return; |
126 | | - } |
127 | | - ref.current.focus(); |
128 | | - }} |
129 | | - /> |
130 | | - <Button |
131 | | - title="Blur" |
132 | | - onPress={() => { |
133 | | - if (!ref.current) { |
134 | | - return; |
135 | | - } |
136 | | - ref.current.blur(); |
137 | | - }} |
138 | | - /> |
139 | | - <Button |
140 | | - title="Reset" |
141 | | - onPress={() => { |
142 | | - setValue(DEFAULT_TEXT); |
143 | | - setMarkdownStyle({}); |
144 | | - }} |
145 | | - /> |
146 | | - <Button |
147 | | - title="Clear" |
148 | | - onPress={() => setValue('')} |
149 | | - /> |
150 | | - <Button |
151 | | - title="Change style" |
152 | | - onPress={() => |
153 | | - setMarkdownStyle({ |
154 | | - link: { |
155 | | - color: getRandomColor(), |
156 | | - }, |
157 | | - }) |
158 | | - } |
159 | | - /> |
160 | | - <Button |
161 | | - title="Change selection" |
162 | | - onPress={() => { |
163 | | - if (!ref.current) { |
164 | | - return; |
165 | | - } |
166 | | - ref.current.focus(); |
167 | | - setSelection({start: 0, end: 20}); |
168 | | - }} |
169 | | - /> |
| 8 | + <View style={{marginTop: 200}}> |
| 9 | + <MarkdownTextInput style={styles.input} /> |
170 | 10 | </View> |
171 | 11 | ); |
172 | 12 | } |
173 | 13 |
|
174 | 14 | const styles = StyleSheet.create({ |
175 | | - container: { |
176 | | - flex: 1, |
177 | | - alignItems: 'center', |
178 | | - marginTop: 60, |
179 | | - }, |
180 | | - platform: { |
181 | | - alignItems: 'center', |
182 | | - marginBottom: 20, |
183 | | - }, |
184 | 15 | input: { |
185 | | - fontSize: 20, |
186 | | - width: 300, |
187 | | - padding: 5, |
188 | | - borderColor: 'gray', |
| 16 | + lineHeight: 25, |
| 17 | + height: 25, |
| 18 | + fontSize: 15, |
189 | 19 | borderWidth: 1, |
190 | | - textAlignVertical: 'top', |
191 | | - }, |
192 | | - text: { |
193 | | - fontFamily: 'Courier New', |
194 | | - marginTop: 10, |
195 | | - height: 100, |
| 20 | + overflow: 'hidden', |
196 | 21 | }, |
197 | 22 | }); |
0 commit comments