-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
133 lines (126 loc) · 3.13 KB
/
App.tsx
File metadata and controls
133 lines (126 loc) · 3.13 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
import { useState, useMemo } from 'react';
import {
StyleSheet,
ScrollView,
Alert,
Linking,
Platform,
View,
Text,
} from 'react-native';
import {
EnrichedMarkdownText,
type LinkPressEvent,
} from 'react-native-enriched-markdown';
import { SafeAreaView } from 'react-native-safe-area-context';
import { sampleMarkdown } from './sampleMarkdown';
import { customMarkdownStyle } from './markdownStyles';
import InputScreen from './InputScreen';
type Screen = 'text' | 'input';
export default function App() {
const [screen, setScreen] = useState<Screen>('input');
const markdownStyle = useMemo(() => customMarkdownStyle, []);
const contextMenuItems = useMemo(
() => [
{
text: 'Summarize with AI',
icon: Platform.OS === 'ios' ? 'sparkles' : undefined,
onPress: ({ text }: { text: string }) => {
Alert.alert('✦ Summarize with AI', `"${text}"`, [
{ text: 'Dismiss', style: 'cancel' },
]);
},
},
{
text: 'Translate',
icon: Platform.OS === 'ios' ? 'globe' : undefined,
onPress: ({ text }: { text: string }) => {
Alert.alert('Translate', `"${text}"`, [
{ text: 'Dismiss', style: 'cancel' },
]);
},
},
],
[]
);
const handleLinkPress = (event: LinkPressEvent) => {
const { url } = event;
Alert.alert('Link Pressed!', `You tapped on: ${url}`, [
{
text: 'Open in Browser',
onPress: () => {
Linking.openURL(url);
},
},
{
text: 'Cancel',
style: 'cancel',
},
]);
};
return (
<SafeAreaView style={styles.root}>
<View style={styles.tabs}>
<Text
style={[styles.tab, screen === 'input' && styles.tabActive]}
onPress={() => setScreen('input')}
>
Input
</Text>
<Text
style={[styles.tab, screen === 'text' && styles.tabActive]}
onPress={() => setScreen('text')}
>
Text
</Text>
</View>
{screen === 'input' ? (
<InputScreen />
) : (
<ScrollView
style={styles.scrollView}
contentContainerStyle={styles.content}
>
<EnrichedMarkdownText
flavor="github"
markdown={sampleMarkdown}
onLinkPress={handleLinkPress}
markdownStyle={markdownStyle}
contextMenuItems={contextMenuItems}
selectionColor={Platform.OS === 'ios' ? '#5A52FA' : '#DCDDFE'}
selectionHandleColor="#5A52FA"
/>
</ScrollView>
)}
</SafeAreaView>
);
}
const styles = StyleSheet.create({
root: {
flex: 1,
},
tabs: {
flexDirection: 'row',
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#D1D5DB',
},
tab: {
flex: 1,
textAlign: 'center',
paddingVertical: 12,
fontSize: 15,
fontWeight: '500',
color: '#6B7280',
},
tabActive: {
color: '#2563EB',
borderBottomWidth: 2,
borderBottomColor: '#2563EB',
},
scrollView: {
paddingHorizontal: 16,
},
content: {
paddingVertical: 16,
},
});