/
index.tsx
139 lines (129 loc) 路 5.63 KB
/
index.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
import React, { useEffect, useState } from 'react';
import { Button, Image, ScrollView, Text, View } from 'react-native';
import { Api } from '@rnv/renative';
import { OrientationLocker, PORTRAIT, LANDSCAPE } from '../components/OrientationLocker';
import { NewModuleButton } from '../components/NewModuleButton';
import { useSplashScreen } from '../components/SplashScreen';
import { ICON_LOGO, testProps } from '../config';
import styles from '../styles';
import { addNotificationListeners, removeNotificationListeners } from '../components/Notifications';
import { requestPermissions } from '../components/Permissions';
import { TestCase } from '../components/TestCase';
import config from '../../package.json';
import { LoggerProvider, useLoggerContext } from '../context';
import { NotificationCallback } from '../components/types';
import { PhotoEditorButton } from '../components/PhotoEditor';
const App = () => (
<LoggerProvider>
<AppContent />
</LoggerProvider>
);
const AppContent = () => {
const [showVideo, setShowVideo] = useState(false);
const { logDebug, logs } = useLoggerContext();
const { SplashScreen } = useSplashScreen();
useEffect(() => {
SplashScreen.hide();
addNotificationListeners(handleNotification);
return () => {
removeNotificationListeners(handleNotification);
};
}, []);
const handleNotification: NotificationCallback = (message) => logDebug(message);
const handleRequestPermissions = async () => {
try {
const permission = await requestPermissions();
logDebug(`Permissions: ${permission}`);
} catch (error) {
logDebug(`${error}`);
}
};
return (
<View style={styles.wrapper}>
<View style={styles.header}>
<Image
style={styles.logo}
source={ICON_LOGO}
{...testProps('template-starter-home-screen-renative-image')}
/>
<Text style={styles.introText} {...testProps('app-harness-home-screen-intro-text')}>
ReNative Harness
</Text>
<View style={{ flex: 1, alignItems: 'flex-end' }}>
<Text style={styles.dynamicText}>
{`v${config.version}, platform: ${Api.platform}, factor: ${Api.formFactor}, engine: ${Api.engine}`}
</Text>
</View>
</View>
<View style={{ flex: 1 }}>
<ScrollView
style={{ flex: 1 }}
contentContainerStyle={{
backgroundColor: 'white',
padding: 10,
}}
>
<TestCase id={1} title="Hermes support ">
<Text style={styles.text}>{`hermes: ${
typeof HermesInternal === 'object' && HermesInternal !== null ? 'yes' : 'no'
}`}</Text>
</TestCase>
<TestCase id={2} title="Native call">
<NewModuleButton />
</TestCase>
<TestCase id={3} title="Orientation support ">
<OrientationLocker
orientation={PORTRAIT}
onChange={(orientation) => logDebug(`onChange ${orientation}`)}
onDeviceChange={(orientation) => logDebug(`onDeviceChange ${orientation}`)}
/>
<Button title="Toggle Video" onPress={() => setShowVideo(!showVideo)} />
{showVideo && (
<View>
<OrientationLocker orientation={LANDSCAPE} />
<View style={{ width: 320, height: 180, backgroundColor: '#ccc' }}>
<Text style={styles.text}>Landscape video goes here</Text>
</View>
</View>
)}
</TestCase>
<TestCase id={4} title="Permissions">
<Button onPress={handleRequestPermissions} title="Request permissions" />
</TestCase>
<TestCase id={5} title="Image Support">
<Image source={ICON_LOGO} style={{ width: 100, height: 100 }} />
</TestCase>
<TestCase id={6} title="Splash Screen">
<Button onPress={() => SplashScreen.show()} title="Show SplashScreen" />
</TestCase>
<TestCase id={7} title="PhotoEditor">
<PhotoEditorButton />
</TestCase>
</ScrollView>
</View>
<ScrollView
style={{
backgroundColor: '#EEEEEE',
maxHeight: '20%',
width: '100%',
borderTopWidth: 1,
borderTopColor: 'black',
padding: 10,
}}
contentContainerStyle={{
paddingBottom: 10,
}}
>
<Text style={[styles.dynamicText, { fontWeight: 'bold' }]}>{`Logs: `}</Text>
{logs
? logs.map((it, idx) => (
<Text key={idx} style={styles.dynamicText}>
{it}
</Text>
))
: null}
</ScrollView>
</View>
);
};
export default App;