-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
104 lines (94 loc) · 2.69 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
104
import React, { useState, useEffect } from 'react';
import { Alert, SafeAreaView, StatusBar, StyleSheet, View, Button, TextInput, Text } from 'react-native';
import { WebView } from 'react-native-webview';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Modal from 'react-native-modal';
const App = () => {
const [url, setUrl] = useState('');
const [isModalVisible, setModalVisible] = useState(false);
useEffect(() => {
checkIfPromptShown();
loadUrlFromStorage();
}, []);
const checkIfPromptShown = async () => {
try {
const promptShown = await AsyncStorage.getItem('promptShown');
if (!promptShown) {
setModalVisible(true);
}
} catch (e) {
console.error('Error checking if prompt has been shown:', e);
}
};
const promptForUrl = (newUrl: string) => {
if (newUrl) {
setUrl(newUrl);
saveUrlToStorage(newUrl);
markPromptAsShown();
}
setModalVisible(false);
};
const saveUrlToStorage = async (newUrl: string) => {
try {
await AsyncStorage.setItem('savedUrl', newUrl);
} catch (e) {
console.error('Error saving URL to AsyncStorage:', e);
}
};
const loadUrlFromStorage = async () => {
try {
const savedUrl = await AsyncStorage.getItem('savedUrl');
if (savedUrl) {
setUrl(savedUrl);
}
} catch (e) {
console.error('Error loading URL from AsyncStorage:', e);
}
};
const markPromptAsShown = async () => {
try {
await AsyncStorage.setItem('promptShown', 'true');
} catch (e) {
console.error('Error marking prompt as shown:', e);
}
};
return (
<SafeAreaView style={{ flex: 1 }}>
<StatusBar barStyle="dark-content" />
<View style={{ flex: 1 }}>
<WebView source={{ uri: url }} />
<Button title="Change URL" onPress={() => setModalVisible(true)} />
<Modal
isVisible={isModalVisible}
onBackdropPress={() => setModalVisible(false)}
backdropOpacity={0.5}
>
<View style={styles.modalContainer}>
<Text>Please enter the URL:</Text>
<TextInput
style={styles.input}
placeholder="Please Enter App URL"
onChangeText={(text) => setUrl(text)}
/>
<Button title="Save URL" onPress={() => promptForUrl(url)} />
</View>
</Modal>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
modalContainer: {
backgroundColor: 'white',
padding: 20,
borderRadius: 10,
},
input: {
height: 40,
borderColor: 'gray',
borderWidth: 1,
marginBottom: 10,
paddingLeft: 10,
},
});
export default App;