11import React from "react" ;
2- import { Button , SafeAreaView , StyleSheet , Text , View } from "react-native" ;
2+ import { Button , StyleSheet , Text , View } from "react-native" ;
3+ import { SafeAreaProvider , SafeAreaView } from "react-native-safe-area-context" ;
34
4- import {
5- ReflagProvider ,
6- useFlag ,
7- useIsLoading ,
8- } from "@reflag/react-sdk" ;
5+ import { ReflagProvider , useClient , useFlag , useIsLoading } from "@reflag/react-sdk" ;
96
107const publishableKey =
118 process . env . EXPO_PUBLIC_REFLAG_PUBLISHABLE_KEY ?? "" ;
129const isConfigured = publishableKey . length > 0 ;
1310
1411function FlagCard ( ) {
12+ const client = useClient ( ) ;
1513 const isLoading = useIsLoading ( ) ;
1614 const { isEnabled, track } = useFlag ( "expo-demo" ) ;
1715
@@ -21,34 +19,39 @@ function FlagCard() {
2119 < Text style = { styles . cardBody } >
2220 Status: { isLoading ? "loading" : isEnabled ? "enabled" : "disabled" }
2321 </ Text >
24- < Button title = "Track usage" onPress = { ( ) => void track ( ) } />
22+ < View style = { styles . buttonRow } >
23+ < Button title = "Track usage" onPress = { ( ) => void track ( ) } />
24+ < Button title = "Refresh" onPress = { ( ) => void client . refresh ( ) } />
25+ </ View >
2526 </ View >
2627 ) ;
2728}
2829
2930export default function App ( ) {
3031 return (
31- < SafeAreaView style = { styles . container } >
32- < ReflagProvider
33- publishableKey = { publishableKey || "demo" }
34- offline = { ! isConfigured }
35- fallbackFlags = { [ "expo-demo" ] }
36- context = { {
37- user : { id : "expo-user" , name : "Expo User" } ,
38- other : { platform : "react-native" } ,
39- } }
40- >
41- < View style = { styles . header } >
42- < Text style = { styles . title } > Reflag React SDK + Expo</ Text >
43- < Text style = { styles . subtitle } >
44- { isConfigured
45- ? "Connected to Reflag"
46- : "Set EXPO_PUBLIC_REFLAG_PUBLISHABLE_KEY to fetch real flags" }
47- </ Text >
48- </ View >
49- < FlagCard />
50- </ ReflagProvider >
51- </ SafeAreaView >
32+ < SafeAreaProvider >
33+ < SafeAreaView style = { styles . container } >
34+ < ReflagProvider
35+ publishableKey = { publishableKey || "demo" }
36+ offline = { ! isConfigured }
37+ fallbackFlags = { [ "expo-demo" ] }
38+ context = { {
39+ user : { id : "expo-user" , name : "Expo User" } ,
40+ other : { platform : "react-native" } ,
41+ } }
42+ >
43+ < View style = { styles . header } >
44+ < Text style = { styles . title } > Reflag React SDK + Expo</ Text >
45+ < Text style = { styles . subtitle } >
46+ { isConfigured
47+ ? "Connected to Reflag"
48+ : "Set EXPO_PUBLIC_REFLAG_PUBLISHABLE_KEY to fetch real flags" }
49+ </ Text >
50+ </ View >
51+ < FlagCard />
52+ </ ReflagProvider >
53+ </ SafeAreaView >
54+ </ SafeAreaProvider >
5255 ) ;
5356}
5457
@@ -79,6 +82,9 @@ const styles = StyleSheet.create({
7982 borderWidth : 1 ,
8083 borderColor : "#1f2937" ,
8184 } ,
85+ buttonRow : {
86+ gap : 12 ,
87+ } ,
8288 cardTitle : {
8389 fontSize : 16 ,
8490 fontWeight : "600" ,
0 commit comments