|
| 1 | +/** |
| 2 | + * Sample React Native App |
| 3 | + * https://github.com/facebook/react-native |
| 4 | + * |
| 5 | + * Generated with the TypeScript template |
| 6 | + * https://github.com/react-native-community/react-native-template-typescript |
| 7 | + * |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
1 | 11 | import SandboxReactNativeView from '@callstack/react-native-sandbox'
|
| 12 | +import {NewAppScreen} from '@react-native/new-app-screen' |
2 | 13 | import React from 'react'
|
3 |
| -import { |
4 |
| - SafeAreaView, |
5 |
| - ScrollView, |
6 |
| - StatusBar, |
7 |
| - StyleSheet, |
8 |
| - Text, |
9 |
| - useColorScheme, |
10 |
| - View, |
11 |
| -} from 'react-native' |
12 |
| - |
13 |
| -const Colors = { |
14 |
| - light: '#ffffff', |
15 |
| - lighter: '#f0f0f0', |
16 |
| - dark: '#000000', |
17 |
| - darker: '#1a1a1a', |
18 |
| -} |
19 |
| - |
20 |
| -const Header = ({children}: {children: React.ReactNode}) => ( |
21 |
| - <Text style={{fontSize: 24, fontWeight: 'bold', margin: 20}}>{children}</Text> |
22 |
| -) |
| 14 | +import {ScrollView, StyleSheet, Text, useColorScheme, View} from 'react-native' |
23 | 15 |
|
24 | 16 | const MAX_DEPTH = 5
|
25 | 17 |
|
26 |
| -type SectionProps = { |
27 |
| - children: React.ReactNode |
28 |
| - title: string |
29 |
| - depth: number |
30 |
| -} |
31 |
| - |
32 |
| -function Section({children, title, depth}: SectionProps): React.JSX.Element { |
33 |
| - const isDarkMode = useColorScheme() === 'dark' |
34 |
| - return ( |
35 |
| - <View style={styles.sectionContainer}> |
36 |
| - <Text |
37 |
| - style={[ |
38 |
| - styles.sectionTitle, |
39 |
| - { |
40 |
| - color: isDarkMode ? Colors.light : Colors.dark, |
41 |
| - fontSize: 26 - depth * 3, |
42 |
| - }, |
43 |
| - ]}> |
44 |
| - {title} |
45 |
| - </Text> |
46 |
| - <Text |
47 |
| - style={[ |
48 |
| - styles.sectionDescription, |
49 |
| - { |
50 |
| - color: isDarkMode ? Colors.light : Colors.dark, |
51 |
| - fontSize: 20 - depth * 3, |
52 |
| - }, |
53 |
| - ]}> |
54 |
| - {children} |
55 |
| - </Text> |
56 |
| - </View> |
57 |
| - ) |
58 |
| -} |
59 |
| - |
60 | 18 | interface AppProps {
|
61 | 19 | depth?: number
|
62 | 20 | }
|
63 | 21 |
|
64 |
| -function App({depth = 1}: AppProps): React.JSX.Element { |
| 22 | +const App = ({depth = 1}: AppProps) => { |
65 | 23 | const isDarkMode = useColorScheme() === 'dark'
|
66 | 24 |
|
67 | 25 | const backgroundStyle = {
|
68 |
| - backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, |
| 26 | + backgroundColor: isDarkMode ? '#000000' : '#ffffff', |
69 | 27 | }
|
70 | 28 |
|
71 |
| - const colors = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF'] |
72 |
| - const borderColor = colors[depth - 1] || 'gray' |
73 |
| - |
74 | 29 | return (
|
75 |
| - <SafeAreaView style={backgroundStyle}> |
76 |
| - <StatusBar |
77 |
| - barStyle={isDarkMode ? 'light-content' : 'dark-content'} |
78 |
| - backgroundColor={backgroundStyle.backgroundColor} |
79 |
| - /> |
| 30 | + <View style={backgroundStyle}> |
80 | 31 | <ScrollView
|
81 | 32 | contentInsetAdjustmentBehavior="automatic"
|
82 | 33 | style={backgroundStyle}>
|
83 |
| - <Header>React Native Multi-Instance</Header> |
84 |
| - <View |
85 |
| - style={[ |
86 |
| - { |
87 |
| - backgroundColor: isDarkMode ? Colors.dark : Colors.light, |
88 |
| - borderColor: borderColor, |
89 |
| - }, |
90 |
| - depth > 1 && styles.nestedContainer, |
91 |
| - ]}> |
92 |
| - <Section title={`Recursive Sandbox (Depth: ${depth})`} depth={depth}> |
93 |
| - This is a nested React Native instance. |
94 |
| - </Section> |
| 34 | + <Text style={styles.scrollHint}>👇👇 Scroll to the bottom 👇👇</Text> |
| 35 | + |
| 36 | + <NewAppScreen templateFileName="App.tsx" /> |
| 37 | + |
| 38 | + <View style={styles.recursiveSection}> |
95 | 39 | {depth < MAX_DEPTH ? (
|
96 | 40 | <View style={styles.recursiveSandboxContainer}>
|
97 | 41 | <Text style={styles.recursiveSandboxTitle}>
|
98 | 42 | Next Level (Depth: {depth + 1})
|
99 | 43 | </Text>
|
100 | 44 | <SandboxReactNativeView
|
101 | 45 | style={styles.recursiveSandbox}
|
102 |
| - jsBundleSource="index" // bundle name for query from metro |
103 |
| - componentName="App" // Recursively load App component from index.js |
| 46 | + jsBundleSource="index" |
| 47 | + componentName="App" |
104 | 48 | initialProperties={{depth: depth + 1}}
|
105 |
| - onMessage={msg => console.log('message', msg)} |
106 |
| - onError={e => console.error('error', e)} |
| 49 | + onMessage={(msg: any) => console.log('message', msg)} |
| 50 | + onError={(e: any) => console.error('error', e)} |
107 | 51 | />
|
108 | 52 | </View>
|
109 | 53 | ) : (
|
110 |
| - <Section title="Max Depth Reached!" depth={depth}> |
111 |
| - No more nested instances will be created. |
112 |
| - </Section> |
| 54 | + <View style={styles.maxDepthContainer}> |
| 55 | + <Text |
| 56 | + style={[ |
| 57 | + styles.maxDepthTitle, |
| 58 | + {color: isDarkMode ? '#ffffff' : '#000000'}, |
| 59 | + ]}> |
| 60 | + Max Depth Reached! |
| 61 | + </Text> |
| 62 | + <Text |
| 63 | + style={[ |
| 64 | + styles.maxDepthDescription, |
| 65 | + {color: isDarkMode ? '#cccccc' : '#666666'}, |
| 66 | + ]}> |
| 67 | + No more nested instances will be created. This demonstrates the |
| 68 | + full capability of nested React Native instances. |
| 69 | + </Text> |
| 70 | + </View> |
113 | 71 | )}
|
114 | 72 | </View>
|
115 | 73 | </ScrollView>
|
116 |
| - </SafeAreaView> |
| 74 | + </View> |
117 | 75 | )
|
118 | 76 | }
|
119 | 77 |
|
120 | 78 | const styles = StyleSheet.create({
|
121 |
| - sectionContainer: { |
122 |
| - marginTop: 32, |
123 |
| - paddingHorizontal: 24, |
124 |
| - }, |
125 |
| - sectionTitle: { |
126 |
| - fontWeight: '600', |
127 |
| - }, |
128 |
| - sectionDescription: { |
129 |
| - marginTop: 8, |
130 |
| - fontWeight: '400', |
131 |
| - }, |
132 |
| - highlight: { |
133 |
| - fontWeight: '700', |
| 79 | + scrollHint: { |
| 80 | + padding: 20, |
| 81 | + textAlign: 'center', |
| 82 | + fontSize: 22, |
| 83 | + backgroundColor: '#f3f3f3', |
134 | 84 | },
|
135 |
| - nestedContainer: { |
136 |
| - borderWidth: 2, |
137 |
| - margin: 5, |
138 |
| - padding: 5, |
| 85 | + recursiveSection: { |
| 86 | + paddingHorizontal: 24, |
| 87 | + backgroundColor: '#f3f3f3', |
| 88 | + paddingBottom: 24, |
| 89 | + marginTop: -34, |
139 | 90 | },
|
140 | 91 | recursiveSandboxContainer: {
|
141 |
| - marginTop: 20, |
142 | 92 | height: 500,
|
143 | 93 | borderWidth: 1,
|
144 |
| - borderColor: 'gray', |
145 |
| - marginHorizontal: 24, |
146 |
| - marginBottom: 20, |
| 94 | + borderColor: '#cccccc', |
| 95 | + borderRadius: 8, |
| 96 | + overflow: 'hidden', |
147 | 97 | },
|
148 | 98 | recursiveSandboxTitle: {
|
149 | 99 | fontSize: 16,
|
150 | 100 | fontWeight: 'bold',
|
151 | 101 | textAlign: 'center',
|
152 |
| - padding: 10, |
153 |
| - color: 'black', |
| 102 | + padding: 12, |
| 103 | + backgroundColor: '#f8f9fa', |
| 104 | + color: '#000000', |
154 | 105 | },
|
155 | 106 | recursiveSandbox: {
|
156 | 107 | flex: 1,
|
157 | 108 | },
|
| 109 | + maxDepthContainer: { |
| 110 | + padding: 20, |
| 111 | + backgroundColor: '#f8f9fa', |
| 112 | + borderRadius: 8, |
| 113 | + borderWidth: 1, |
| 114 | + borderColor: '#e9ecef', |
| 115 | + }, |
| 116 | + maxDepthTitle: { |
| 117 | + fontSize: 20, |
| 118 | + fontWeight: 'bold', |
| 119 | + marginBottom: 8, |
| 120 | + }, |
| 121 | + maxDepthDescription: { |
| 122 | + fontSize: 14, |
| 123 | + lineHeight: 20, |
| 124 | + }, |
158 | 125 | })
|
159 | 126 |
|
160 | 127 | export default App
|
0 commit comments