-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
103 lines (97 loc) · 3.87 KB
/
App.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
import { StatusBar } from 'expo-status-bar';
import { useState } from 'react';
import { Linking, Modal, SafeAreaView, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
import WebView from 'react-native-webview';
const script = `
const host = window.ReactNativeWebView || window.parent;
window.AbaPayway = {
miniApp: (data) =>{
host.postMessage(JSON.stringify({data,'event':'miniApp'},null,2))
},
miniAppGetProfile : (callback = ()=>{})=> {
callback({
"firstName": "John",
"middleName": "Unknown",
"lastName": "Doe",
"fullName": "",
"sex": "M",
"dobShort": "DD-MM",
"nationality": "KHM",
"phone": "+85512345678",
"email": "",
"lang": "en",
"id": "123456",
"appVersion": "4.9.12",
"osVersion": "14.7.1"
})
}
}
`
const defaultUrl = 'mywhateverurl';
export default function App() {
const [url, setUrl] = useState(defaultUrl);
const [tmpUrl, setTmpUrl] = useState('');
const [mv, setMv] = useState(false);
const [p, setP] = useState<{ merchantName?: string; barTitle?: { title?: string; color?: string, bgColor?: string; }, safeAreaColor?: string }>({ safeAreaColor: 'white' });
return (
<SafeAreaView style={[styles.container, { backgroundColor: p.safeAreaColor }]}>
<View style={{ backgroundColor: p?.barTitle?.bgColor?.replace('##', '#') || 'red', height: 50, alignItems: 'center', paddingHorizontal: 16, flexDirection: 'row' }}>
<View style={{ flex: 1 }}>
<Text style={{ color: p.barTitle?.color || 'black', fontSize: 18, fontWeight: 'bold' }}>{p?.barTitle?.title || p.merchantName}</Text>
</View>
<TouchableOpacity onPress={() => {
setMv(true);
setTmpUrl(url)
}}><Text style={{ color: p.barTitle?.color || 'black' }}>ooo</Text></TouchableOpacity>
</View>
<WebView
originWhitelist={['*']}
javaScriptEnabled={true}
onMessage={(e) => {
const data = JSON.parse(e.nativeEvent.data);
if (data?.event === 'miniApp') { setP(data.data) }
}}
onShouldStartLoadWithRequest={({ url }) => {
if (url.startsWith('abamobilebank://')) {
Linking.openURL(url);
return false;
}
return true;
}}
injectedJavaScriptBeforeContentLoaded={script}
source={{ uri: url || defaultUrl }}
style={{ flex: 1, backgroundColor: '#fff' }}
/>
<Modal visible={mv}>
<View style={{ flex: 1, justifyContent: 'center', 'alignItems': 'center' }}>
<View style={{ width: '100%', padding: 30 }}>
<TextInput
autoFocus
value={tmpUrl}
onChangeText={text => setTmpUrl(text)}
placeholder="URL" placeholderTextColor={""}
selectTextOnFocus
multiline
keyboardType="url"
style={{ width: '100%', minHeight: 80, backgroundColor: 'lightgrey', borderRadius: 8, paddingHorizontal: 16, marginBottom: 16 }}
/>
<TouchableOpacity onPress={() => {
setUrl(tmpUrl);
setMv(false);
}} style={{ width: '100%', height: 40, backgroundColor: 'blue', borderRadius: 8, paddingHorizontal: 16, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ color: 'white' }}>Go</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMv(false)} style={{ width: '100%', height: 40, marginTop: 40, borderRadius: 8, paddingHorizontal: 16, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ color: 'black' }}>Cancel</Text>
</TouchableOpacity>
</View>
</View>
</Modal>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});