|
1 | | -import React, { Component } from 'react'; |
2 | | -import { Linking, StyleSheet, Text, View } from 'react-native'; |
| 1 | +/** |
| 2 | + * Sample React Native App |
| 3 | + * https://github.com/facebook/react-native |
| 4 | + * |
| 5 | + * @format |
| 6 | + * @flow strict-local |
| 7 | + */ |
| 8 | + |
| 9 | +import React, {useState, useEffect} from 'react'; |
| 10 | +import type {Node} from 'react'; |
| 11 | +import { |
| 12 | + SafeAreaView, |
| 13 | + ScrollView, |
| 14 | + StatusBar, |
| 15 | + StyleSheet, |
| 16 | + Text, |
| 17 | + useColorScheme, |
| 18 | + View, |
| 19 | +} from 'react-native'; |
3 | 20 | import VersionCheck from 'react-native-version-check'; |
4 | 21 |
|
| 22 | +import {Colors, Header} from 'react-native/Libraries/NewAppScreen'; |
| 23 | + |
| 24 | +/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's |
| 25 | + * LTI update could not be added via codemod */ |
| 26 | +const Section = ({children, title}): Node => { |
| 27 | + const isDarkMode = useColorScheme() === 'dark'; |
| 28 | + return ( |
| 29 | + <View style={styles.sectionContainer}> |
| 30 | + <Text |
| 31 | + style={[ |
| 32 | + styles.sectionTitle, |
| 33 | + { |
| 34 | + color: isDarkMode ? Colors.white : Colors.black, |
| 35 | + }, |
| 36 | + ]} |
| 37 | + > |
| 38 | + {title} |
| 39 | + </Text> |
| 40 | + <Text |
| 41 | + style={[ |
| 42 | + styles.sectionDescription, |
| 43 | + { |
| 44 | + color: isDarkMode ? Colors.light : Colors.dark, |
| 45 | + }, |
| 46 | + ]} |
| 47 | + > |
| 48 | + {children} |
| 49 | + </Text> |
| 50 | + </View> |
| 51 | + ); |
| 52 | +}; |
| 53 | + |
| 54 | +const App: () => Node = () => { |
| 55 | + const [currentVersion, setCurrentVersion] = useState(null); |
| 56 | + const [latestVersion, setLatestVersion] = useState(null); |
| 57 | + const [isNeeded, setIsNeeded] = useState(false); |
| 58 | + const [storeUrl, setStoreUrl] = useState(''); |
| 59 | + |
| 60 | + useEffect(() => { |
| 61 | + VersionCheck.needUpdate({ |
| 62 | + latestVersion: '1.0.0', |
| 63 | + }).then(res => { |
| 64 | + console.log(res); |
| 65 | + const {currentVersion, latestVersion, isNeeded} = res; |
| 66 | + setCurrentVersion(currentVersion); |
| 67 | + setLatestVersion(latestVersion); |
| 68 | + setIsNeeded(isNeeded); |
| 69 | + }); |
| 70 | + |
| 71 | + VersionCheck.getStoreUrl({appID: '364709193', country: 'KR'}).then( |
| 72 | + storeUrl => { |
| 73 | + console.log(storeUrl); |
| 74 | + setStoreUrl(storeUrl); |
| 75 | + }, |
| 76 | + ); |
| 77 | + }, []); |
| 78 | + |
| 79 | + const isDarkMode = useColorScheme() === 'dark'; |
| 80 | + |
| 81 | + const backgroundStyle = { |
| 82 | + backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, |
| 83 | + }; |
| 84 | + |
| 85 | + return ( |
| 86 | + <SafeAreaView style={backgroundStyle}> |
| 87 | + <StatusBar |
| 88 | + barStyle={isDarkMode ? 'light-content' : 'dark-content'} |
| 89 | + backgroundColor={backgroundStyle.backgroundColor} |
| 90 | + /> |
| 91 | + <ScrollView |
| 92 | + contentInsetAdjustmentBehavior="automatic" |
| 93 | + style={backgroundStyle} |
| 94 | + > |
| 95 | + <Header /> |
| 96 | + <View |
| 97 | + style={{ |
| 98 | + backgroundColor: isDarkMode ? Colors.black : Colors.white, |
| 99 | + }} |
| 100 | + > |
| 101 | + <Section title="Current Version">{currentVersion}</Section> |
| 102 | + <Section title="Latest Version">{latestVersion}</Section> |
| 103 | + <Section title="Is update needed?">{String(isNeeded)}</Section> |
| 104 | + <Section title="Store Url">{String(storeUrl)}</Section> |
| 105 | + </View> |
| 106 | + </ScrollView> |
| 107 | + </SafeAreaView> |
| 108 | + ); |
| 109 | +}; |
| 110 | + |
5 | 111 | const styles = StyleSheet.create({ |
6 | | - container: { |
7 | | - flex: 1, |
8 | | - justifyContent: 'center', |
9 | | - alignItems: 'center', |
10 | | - backgroundColor: '#F5FCFF', |
| 112 | + sectionContainer: { |
| 113 | + marginTop: 32, |
| 114 | + paddingHorizontal: 24, |
11 | 115 | }, |
12 | | - text: { |
13 | | - fontSize: 20, |
14 | | - textAlign: 'center', |
15 | | - margin: 10, |
| 116 | + sectionTitle: { |
| 117 | + fontSize: 24, |
| 118 | + fontWeight: '600', |
16 | 119 | }, |
17 | | - linkText: { |
18 | | - color: 'blue', |
| 120 | + sectionDescription: { |
| 121 | + marginTop: 8, |
| 122 | + fontSize: 18, |
| 123 | + fontWeight: '400', |
| 124 | + }, |
| 125 | + highlight: { |
| 126 | + fontWeight: '700', |
19 | 127 | }, |
20 | 128 | }); |
21 | 129 |
|
22 | | -export default class example extends Component { |
23 | | - state = { |
24 | | - currentVersion: null, |
25 | | - latestVersion: null, |
26 | | - isNeeded: false, |
27 | | - storeUrl: '', |
28 | | - }; |
29 | | - componentDidMount() { |
30 | | - VersionCheck.needUpdate({ |
31 | | - latestVersion: '1.0.0', |
32 | | - }).then(res => this.setState(res)); |
33 | | - |
34 | | - VersionCheck.getStoreUrl({ appID: '364709193' }).then(res => { |
35 | | - //App Store ID for iBooks. |
36 | | - this.setState({ storeUrl: res }); |
37 | | - }); |
38 | | - } |
39 | | - render() { |
40 | | - return ( |
41 | | - <View style={styles.container}> |
42 | | - <Text style={styles.text}> |
43 | | - Current Version: {this.state.currentVersion} |
44 | | - </Text> |
45 | | - <Text style={styles.text}> |
46 | | - Latest Version: {this.state.latestVersion} |
47 | | - </Text> |
48 | | - <Text style={styles.text}> |
49 | | - Is update needed?: {String(this.state.isNeeded)} |
50 | | - </Text> |
51 | | - <View> |
52 | | - <Text style={styles.text}>Store Url:</Text> |
53 | | - <Text |
54 | | - style={[styles.text, styles.linkText]} |
55 | | - onPress={() => Linking.openURL(this.state.storeUrl)} |
56 | | - > |
57 | | - {String(this.state.storeUrl)} |
58 | | - </Text> |
59 | | - </View> |
60 | | - </View> |
61 | | - ); |
62 | | - } |
63 | | -} |
| 130 | +export default App; |
0 commit comments