Created
November 6, 2023 11:46
-
-
Save thebiltheory/bb65203b7c2be0b66a9b7bdc3c486174 to your computer and use it in GitHub Desktop.
This file contains 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, { useState, useEffect } from 'react'; | |
import { View, Text, Image, AppState } from 'react-native'; | |
const App = () => { | |
const [appState, setAppState] = useState(AppState.currentState); | |
const [isAppBackgrounded, setIsAppBackgrounded] = useState(false); | |
useEffect(() => { | |
const subscription = AppState.addEventListener("change", nextAppState => { | |
setAppState(nextAppState); | |
setIsAppBackgrounded(nextAppState === 'background'); | |
}); | |
return () => { | |
subscription.remove(); | |
}; | |
}, []); | |
const renderContent = () => { | |
if (isAppBackgrounded) { | |
// Render a placeholder or branding image when the app is in the background | |
return <Image source={require('./path-to-your-placeholder-image.png')} />; | |
} else { | |
// Render the normal app content when it is in the foreground | |
return ( | |
<View> | |
<Text>Welcome to the app!</Text> | |
{/* Rest of your app UI */} | |
</View> | |
); | |
} | |
}; | |
return ( | |
<View style={{ flex: 1 }}> | |
{renderContent()} | |
</View> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment