Skip to content

Instantly share code, notes, and snippets.

@vaibhavgehani
Last active August 30, 2022 03:25
Show Gist options
  • Select an option

  • Save vaibhavgehani/c2f3e021da8813eb3d4048f67c6a25f0 to your computer and use it in GitHub Desktop.

Select an option

Save vaibhavgehani/c2f3e021da8813eb3d4048f67c6a25f0 to your computer and use it in GitHub Desktop.
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