-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApp.tsx
More file actions
412 lines (389 loc) · 11.2 KB
/
Copy pathApp.tsx
File metadata and controls
412 lines (389 loc) · 11.2 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import React, { useState } from 'react';
import { ScrollView, StyleSheet, Text, View } from 'react-native';
import { NitroText } from 'react-native-nitro-text';
export default function App() {
const [layoutInfo, setLayoutInfo] = useState<string>('');
const handleLayout = (event: any) => {
const { height, width } = event.nativeEvent.layout;
setLayoutInfo(`Layout: ${Math.round(width)}×${Math.round(height)}px`);
};
const handleTextLayout = (event: any) => {
const { lines } = event.nativeEvent;
console.log('lines', lines);
// setLayoutInfo(`Lines: ${lines.length}`);
};
return (
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
{/* Header Section */}
<View style={styles.section}>
<NitroText style={styles.mainTitle}>🚀 NitroText Showcase</NitroText>
<NitroText style={styles.subtitle}>
High-performance selectable text with native rendering
</NitroText>
</View>
{/* Basic Usage */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Basic Usage</NitroText>
<NitroText style={styles.basicText}>
This is a simple NitroText component with native performance. Try
selecting this text to see the smooth selection behavior!
</NitroText>
</View>
{/* Rich Text Formatting */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Rich Text Formatting</NitroText>
<NitroText style={styles.richText}>
Welcome to the world of{' '}
<NitroText style={styles.bold}>bold text</NitroText>,{' '}
<NitroText style={styles.italic}>beautiful italics</NitroText>, and{' '}
<NitroText style={styles.highlight}>highlighted content</NitroText>.
{'\n\n'}
You can combine multiple styles:{' '}
<NitroText style={[styles.bold, styles.underline, styles.colorful]}>
Bold, underlined, and colorful!
</NitroText>
{'\n\n'}
Different font sizes work seamlessly:{' '}
<NitroText style={styles.large}>Large text</NitroText> mixed with{' '}
<NitroText style={styles.small}>small text</NitroText> in the same
paragraph.
</NitroText>
</View>
{/* Layout Measurement */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Layout Measurement</NitroText>
<NitroText style={styles.measuredText} onLayout={handleLayout} onTextLayout={handleTextLayout}>
This text demonstrates layout measurement capabilities. The component
can measure its dimensions and report back to JavaScript.
{'\n\n'}
<NitroText style={styles.infoText}>
{layoutInfo || 'Measuring...'}
</NitroText>
</NitroText>
</View>
{/* Line Limiting */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Line Limiting</NitroText>
<NitroText style={styles.description}>Two lines maximum:</NitroText>
<NitroText style={styles.limitedText} numberOfLines={2}>
This is a very long text that would normally span multiple lines, but
we're limiting it to just two lines. The text will be truncated with
an ellipsis when it exceeds the specified number of lines. This is
useful for creating consistent layouts in lists or cards where you
need predictable text heights.
</NitroText>
</View>
{/* Mixed Content */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Mixed Content</NitroText>
<NitroText style={styles.mixedContent}>
NitroText can seamlessly integrate with React Native's Text component:
{'\n\n'}
<Text style={styles.rnText}>
This is a React Native Text component{' '}
<NitroText style={styles.nested}>with nested NitroText</NitroText>{' '}
inside it.
</Text>
{'\n\n'}And vice versa - NitroText can contain:{'\n'}
<NitroText style={styles.nestedContainer}>
Regular text with{' '}
<Text style={styles.rnNested}>RN Text nested inside</Text>{' '}
NitroText.
</NitroText>
</NitroText>
</View>
{/* Code Example */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Code Syntax</NitroText>
<NitroText style={styles.codeBlock}>
<NitroText style={styles.codeKeyword}>import</NitroText>{' '}
<NitroText style={styles.codeString}>{'{ NitroText }'}</NitroText>{' '}
<NitroText style={styles.codeKeyword}>from</NitroText>{' '}
<NitroText style={styles.codeString}>
'react-native-nitro-text'
</NitroText>
;{'\n\n'}
<NitroText style={styles.codeKeyword}>const</NitroText>{' '}
<NitroText style={styles.codeFunction}>MyComponent</NitroText> = ()
=> {'{'}
{'\n'}
{' '}
<NitroText style={styles.codeKeyword}>return</NitroText> ({'\n'}
{' '}
<NitroText style={styles.codeTag}>{'<NitroText '}</NitroText>
<NitroText style={styles.codeAttribute}>style</NitroText>=
<NitroText style={styles.codeValue}>{'{'}</NitroText>
<NitroText style={styles.codeValue}>styles.text</NitroText>
<NitroText style={styles.codeValue}>{'}'}</NitroText>
<NitroText style={styles.codeTag}>{'>'}</NitroText>
{'\n'}
{' '}Hello World!{'\n'}
{' '}
<NitroText style={styles.codeTag}>{'</NitroText>'}</NitroText>
{'\n'}
{' '});{'\n'}
{'};'}
</NitroText>
</View>
{/* Performance Comparison */}
<View style={styles.section}>
<NitroText style={styles.sectionTitle}>Performance Benefits</NitroText>
<View style={styles.comparisonContainer}>
<View style={styles.comparisonItem}>
<NitroText style={styles.comparisonLabel}>NitroText</NitroText>
<NitroText style={styles.performanceText}>
⚡ Native rendering{'\n'}
🎯 Optimized selection{'\n'}
📱 Better memory usage{'\n'}
🚀 Smooth scrolling
</NitroText>
</View>
<View style={styles.comparisonItem}>
<Text style={styles.comparisonLabel}>Standard Text</Text>
<Text style={styles.performanceText}>
📝 JavaScript bridge{'\n'}
🐌 Standard selection{'\n'}
💾 More memory overhead{'\n'}
📱 Standard performance
</Text>
</View>
</View>
</View>
{/* Footer */}
{/* Bug when applying alignItems: 'center' NitroText disappears */}
<View style={[styles.section, styles.footer]}>
<NitroText style={styles.footerText}>Built with ❤️</NitroText>
<Text style={styles.footerText}>Built with ❤️</Text>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f8f9fa',
},
content: {
paddingHorizontal: 16,
paddingTop: 60,
paddingBottom: 40,
},
section: {
marginBottom: 32,
},
// Headers
mainTitle: {
fontSize: 25,
padding: 10,
fontWeight: 'bold',
color: '#1a1a1a',
textAlign: 'center',
// marginBottom: 8,
backgroundColor: 'red',
},
subtitle: {
fontSize: 16,
color: '#6c757d',
textAlign: 'center',
alignSelf: 'flex-start',
lineHeight: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: 'bold',
color: '#2c3e50',
marginBottom: 16,
},
description: {
fontSize: 14,
color: '#6c757d',
marginBottom: 8,
},
// Basic text styles
basicText: {
fontSize: 16,
color: '#495057',
lineHeight: 24,
backgroundColor: '#ffffff',
padding: 16,
borderRadius: 8,
borderLeftWidth: 4,
borderLeftColor: '#007bff',
},
// Rich text styles
richText: {
fontSize: 16,
color: '#495057',
lineHeight: 26,
backgroundColor: '#ffffff',
padding: 16,
borderRadius: 8,
},
bold: {
fontWeight: 'bold',
color: '#2c3e50',
},
italic: {
fontStyle: 'italic',
color: '#6f42c1',
},
highlight: {
backgroundColor: '#fff3cd',
color: '#856404',
paddingHorizontal: 4,
paddingVertical: 2,
},
underline: {
textDecorationLine: 'underline',
textAlign: 'auto',
},
colorful: {
color: '#e83e8c',
},
large: {
fontSize: 20,
fontWeight: 'bold',
},
small: {
fontSize: 12,
color: '#6c757d',
},
// Layout measurement
measuredText: {
fontSize: 16,
color: '#495057',
lineHeight: 24,
backgroundColor: '#e3f2fd',
padding: 16,
borderRadius: 8,
borderWidth: 1,
borderColor: '#2196f3',
borderStyle: 'dashed',
},
infoText: {
fontSize: 14,
fontWeight: 'bold',
color: '#1976d2',
backgroundColor: '#ffffff',
paddingHorizontal: 8,
paddingVertical: 4,
borderRadius: 4,
},
// Line limiting
limitedText: {
fontSize: 16,
color: '#495057',
lineHeight: 22,
backgroundColor: '#fff8e1',
padding: 16,
borderRadius: 8,
borderLeftWidth: 4,
borderLeftColor: '#ff9800',
},
// Mixed content
mixedContent: {
fontSize: 16,
color: '#495057',
lineHeight: 26,
backgroundColor: '#f8f9fa',
padding: 16,
borderRadius: 8,
borderWidth: 1,
borderColor: '#dee2e6',
},
rnText: {
backgroundColor: '#ffeaa7',
padding: 8,
borderRadius: 4,
fontSize: 15,
color: '#2d3436',
},
nested: {
fontWeight: 'bold',
color: '#0984e3',
},
nestedContainer: {
backgroundColor: '#ddd6fe',
padding: 8,
borderRadius: 4,
},
rnNested: {
fontStyle: 'italic',
color: '#7c3aed',
fontWeight: 'bold',
},
// Code syntax
codeBlock: {
fontSize: 14,
fontFamily: 'Menlo, Monaco, monospace',
backgroundColor: '#1e1e1e',
color: '#d4d4d4',
padding: 16,
borderRadius: 8,
lineHeight: 20,
},
codeKeyword: {
color: '#569cd6',
fontWeight: 'bold',
},
codeString: {
color: '#ce9178',
},
codeFunction: {
color: '#dcdcaa',
},
codeTag: {
color: '#4ec9b0',
},
codeAttribute: {
color: '#9cdcfe',
},
codeValue: {
color: '#ce9178',
},
// Performance comparison
comparisonContainer: {
flexDirection: 'row',
gap: 16,
},
comparisonItem: {
flex: 1,
backgroundColor: '#ffffff',
padding: 16,
borderRadius: 8,
borderWidth: 1,
borderColor: '#dee2e6',
},
comparisonLabel: {
fontSize: 16,
fontWeight: 'bold',
color: '#2c3e50',
// marginBottom: 12,
textAlign: 'center',
},
performanceText: {
fontSize: 14,
color: '#495057',
lineHeight: 22,
},
// Footer
footer: {
// alignItems: 'center',
// paddingTop: 20,
borderTopWidth: 1,
borderTopColor: '#dee2e6',
// paddingBottom: 60,
backgroundColor: 'blue',
},
footerText: {
textTransform: 'uppercase',
// fontSize: 16,
fontStyle: 'italic',
backgroundColor: 'red',
textAlign: 'center',
marginBottom: 1,
// alignSelf: 'flex-start',
// width: '100%',
// height: '100%',
},
});