Last active
August 30, 2022 03:25
-
-
Save vaibhavgehani/c2f3e021da8813eb3d4048f67c6a25f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { | |
| StyleSheet, | |
| Text, | |
| View, | |
| AppState | |
| } from 'react-native'; | |
| import { useEffect, useRef, useState } from 'react'; | |
| const App = () => { | |
| const appState = useRef(AppState.currentState); | |
| const [appStateVisible, setAppStateVisible] = useState(appState.current); | |
| useEffect(() => { | |
| const subscription = AppState.addEventListener("change", nextAppState => { | |
| appState.current = nextAppState; | |
| setAppStateVisible(appState.current); | |
| }); | |
| return () => { | |
| subscription.remove(); | |
| }; | |
| }, []); | |
| if (appStateVisible == 'active') { | |
| // The actual screen when you are on app again (main view logic) | |
| return ( | |
| <View> | |
| <Text>Hello world</Text> | |
| </View> | |
| ) | |
| } else { | |
| return ( | |
| // Blank screen (security screen) | |
| <View> | |
| </View> | |
| ) | |
| } | |
| }; | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment