File tree Expand file tree Collapse file tree 1 file changed +25
-19
lines changed
packages/react-native-sdk/dev/expo Expand file tree Collapse file tree 1 file changed +25
-19
lines changed Original file line number Diff line number Diff line change @@ -32,25 +32,6 @@ function FlagCard() {
3232}
3333
3434export default function App ( ) {
35- const appState = useRef ( AppState . currentState ) ;
36-
37- useEffect ( ( ) => {
38- const subscription = AppState . addEventListener ( "change" , ( nextAppState ) => {
39- if (
40- appState . current . match ( / i n a c t i v e | b a c k g r o u n d / ) &&
41- nextAppState === "active"
42- ) {
43- console . log ( "App came to foreground" ) ;
44- // Your global logic here
45- }
46- appState . current = nextAppState ;
47- } ) ;
48-
49- return ( ) => {
50- subscription . remove ( ) ;
51- } ;
52- } , [ ] ) ;
53-
5435 return (
5536 < SafeAreaProvider >
5637 < SafeAreaView style = { styles . container } >
@@ -71,13 +52,38 @@ export default function App() {
7152 : "Set EXPO_PUBLIC_REFLAG_PUBLISHABLE_KEY to fetch real flags" }
7253 </ Text >
7354 </ View >
55+ < AppStateListener />
7456 < FlagCard />
7557 </ ReflagProvider >
7658 </ SafeAreaView >
7759 </ SafeAreaProvider >
7860 ) ;
7961}
8062
63+ function AppStateListener ( ) {
64+ const client = useClient ( ) ;
65+ const appState = useRef ( AppState . currentState ) ;
66+
67+ useEffect ( ( ) => {
68+ const subscription = AppState . addEventListener ( "change" , ( nextAppState ) => {
69+ if (
70+ appState . current . match ( / i n a c t i v e | b a c k g r o u n d / ) &&
71+ nextAppState === "active"
72+ ) {
73+ console . log ( "App came to foreground" ) ;
74+ void client . refresh ( ) ;
75+ }
76+ appState . current = nextAppState ;
77+ } ) ;
78+
79+ return ( ) => {
80+ subscription . remove ( ) ;
81+ } ;
82+ } , [ client ] ) ;
83+
84+ return null ;
85+ }
86+
8187const styles = StyleSheet . create ( {
8288 container : {
8389 flex : 1 ,
You can’t perform that action at this time.
0 commit comments