Skip to content

Instantly share code, notes, and snippets.

@thebiltheory
Created November 6, 2023 11:46
Show Gist options
  • Save thebiltheory/bb65203b7c2be0b66a9b7bdc3c486174 to your computer and use it in GitHub Desktop.
Save thebiltheory/bb65203b7c2be0b66a9b7bdc3c486174 to your computer and use it in GitHub Desktop.
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