Skip to content

Commit 1dad992

Browse files
committed
chore: display device token for testing
1 parent a28747a commit 1dad992

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

examples/sync-demo-expo/src/App.tsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useMemo, useCallback, useRef } from 'react';
1+
import { useState, useMemo, useCallback, useRef, useEffect } from 'react';
22
import {
33
Text,
44
View,
@@ -9,6 +9,7 @@ import {
99
TouchableOpacity,
1010
FlatList,
1111
Modal,
12+
Clipboard,
1213
} from 'react-native';
1314
import {
1415
SQLiteSyncProvider,
@@ -83,7 +84,7 @@ registerBackgroundSyncCallback(
8384
* - Always uses writeDb (for atomic write operations)
8485
* - Triggers reactive queries when transaction commits
8586
*/
86-
function TestApp() {
87+
function TestApp({ deviceToken }: { deviceToken: string | null }) {
8788
const { writeDb, initError } = useSqliteDb();
8889
const { isSyncReady, isSyncing, lastSyncTime, syncError } = useSyncStatus();
8990
const [searchText, setSearchText] = useState('');
@@ -177,6 +178,18 @@ function TestApp() {
177178
<View style={styles.fixedHeader}>
178179
<Text style={styles.title}>SQLite Sync Demo</Text>
179180

181+
{deviceToken && (
182+
<TouchableOpacity
183+
style={styles.tokenBanner}
184+
onPress={() => Clipboard.setString(deviceToken)}
185+
>
186+
<Text style={styles.tokenLabel}>Device Token (tap to copy):</Text>
187+
<Text style={styles.tokenText} numberOfLines={2}>
188+
{deviceToken}
189+
</Text>
190+
</TouchableOpacity>
191+
)}
192+
180193
{/* Status Section */}
181194
<View style={styles.statusSection}>
182195
<Text style={styles.status}>
@@ -344,6 +357,13 @@ function PermissionDialog({
344357
export default function App() {
345358
const [showPermissionDialog, setShowPermissionDialog] = useState(false);
346359
const permissionResolverRef = useRef<((value: boolean) => void) | null>(null);
360+
const [deviceToken, setDeviceToken] = useState<string | null>(null);
361+
362+
useEffect(() => {
363+
Notifications.getExpoPushTokenAsync()
364+
.then((token) => setDeviceToken(token.data as string))
365+
.catch(() => setDeviceToken('Failed to get token'));
366+
}, []);
347367

348368
// Callback to show custom UI before system permission request
349369
const handleBeforePushPermissionRequest = useCallback(async () => {
@@ -412,7 +432,7 @@ export default function App() {
412432
apiKey={SQLITE_CLOUD_API_KEY}
413433
debug={true}
414434
>
415-
<TestApp />
435+
<TestApp deviceToken={deviceToken} />
416436
</SQLiteSyncProvider>
417437
</>
418438
);
@@ -697,4 +717,25 @@ const styles = StyleSheet.create({
697717
color: '#666',
698718
fontSize: 16,
699719
},
720+
tokenBanner: {
721+
backgroundColor: '#E8F5E9',
722+
padding: 12,
723+
marginHorizontal: 16,
724+
marginTop: 0,
725+
marginBottom: 8,
726+
borderRadius: 8,
727+
borderWidth: 1,
728+
borderColor: '#A5D6A7',
729+
},
730+
tokenLabel: {
731+
fontSize: 12,
732+
fontWeight: '600',
733+
color: '#2E7D32',
734+
marginBottom: 4,
735+
},
736+
tokenText: {
737+
fontSize: 11,
738+
color: '#333',
739+
fontFamily: 'monospace',
740+
},
700741
});

0 commit comments

Comments
 (0)