diff --git a/example/app/testing-grounds/channel-updates.tsx b/example/app/testing-grounds/channel-updates.tsx new file mode 100644 index 00000000..8ef55865 --- /dev/null +++ b/example/app/testing-grounds/channel-updates.tsx @@ -0,0 +1,5 @@ +import ChannelUpdatesTestingScreen from '~/screens/testing-grounds/ChannelUpdatesTestingScreen' + +export default function ChannelUpdatesTestingIndex() { + return +} diff --git a/example/screens/testing-grounds/ChannelUpdatesTestingScreen.tsx b/example/screens/testing-grounds/ChannelUpdatesTestingScreen.tsx new file mode 100644 index 00000000..e5cece13 --- /dev/null +++ b/example/screens/testing-grounds/ChannelUpdatesTestingScreen.tsx @@ -0,0 +1,127 @@ +import { useRouter } from 'expo-router' +import React, { useMemo, useState } from 'react' +import { Alert, Platform, ScrollView, StyleSheet, Text, View } from 'react-native' +import { Voltra } from 'voltra' +import { useLiveActivity } from 'voltra/client' + +import { Button } from '~/components/Button' +import { Card } from '~/components/Card' +import { TextInput } from '~/components/TextInput' + +export default function ChannelUpdatesTestingScreen() { + const router = useRouter() + const [channelId, setChannelId] = useState('') + const [isSubmitting, setIsSubmitting] = useState(false) + + const trimmedChannelId = channelId.trim() + + const variants = useMemo( + () => ({ + lockScreen: { + content: Waiting for updates..., + }, + island: { + minimal: Waiting for updates..., + }, + }), + [] + ) + + const { start } = useLiveActivity(variants, { + activityName: 'channel-based-updates', + autoUpdate: false, + channelId: trimmedChannelId || undefined, + }) + + const handleShowLiveActivity = async () => { + if (!trimmedChannelId) { + Alert.alert('Channel ID required', 'Provide channel ID before starting a Live Activity.') + return + } + + setIsSubmitting(true) + try { + await start() + } catch (error) { + console.error('Failed to start channel-based Live Activity:', error) + Alert.alert('Unable to start', 'Check logs for more details.') + } finally { + setIsSubmitting(false) + } + } + + if (Platform.OS !== 'ios') { + return null + } + + return ( + + + Channel-Based Updates + + Start a minimal Live Activity subscribed to a specific broadcast channel. + + + + Live Activity Channel + Use an APNs broadcast channel ID for this activity. + + + + + +