Skip to content

Commit d424cf9

Browse files
committed
Update Expo demo safe area and add refresh
1 parent d96254b commit d424cf9

2 files changed

Lines changed: 36 additions & 29 deletions

File tree

packages/react-sdk/dev/expo/App.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import 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

107
const publishableKey =
118
process.env.EXPO_PUBLIC_REFLAG_PUBLISHABLE_KEY ?? "";
129
const isConfigured = publishableKey.length > 0;
1310

1411
function 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

2930
export 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",

packages/react-sdk/dev/expo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@reflag/react-sdk": "workspace:*",
2020
"expo": "~54.0.0",
2121
"react": "19.1.0",
22-
"react-native": "0.81.5"
22+
"react-native": "0.81.5",
23+
"react-native-safe-area-context": "^5.6.0"
2324
}
2425
}

0 commit comments

Comments
 (0)