-
Notifications
You must be signed in to change notification settings - Fork 9
feat(mobile): add iOS Live Activity and widgets #5553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iscekic
wants to merge
13
commits into
audit-w8b-live-activities-3cf8
from
audit-w8b-live-activities-3cf8-s2
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a1c46cc
feat(mobile): add iOS widgets native config and module
iscekic d8d6f5b
chore(deps): dedupe @expo/ui native module
iscekic b49e6b3
feat(mobile): add iOS Live Activity and widgets
iscekic 6c75153
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic 7aada2b
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic 1a757a1
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic 119f2a2
fix(glanceable): use deep link and end leftover Live Activity
iscekic 5043f7a
fix(mobile): allow the staged Android widget dependency
iscekic a6209af
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic 2a47259
fix(mobile): preserve terminal iOS widget timelines
iscekic 7862ed8
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic 61bd849
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic 88b6f23
Merge branch 'audit-w8b-live-activities-3cf8' into audit-w8b-live-act…
iscekic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
apps/mobile/modules/active-agents-live-update/expo-module.config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "platforms": ["apple", "android"], | ||
| "apple": { | ||
| "modules": [] | ||
| }, | ||
| "android": { | ||
| "modules": [] | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
apps/mobile/modules/active-agents-live-update/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "name": "active-agents-live-update", | ||
| "version": "0.1.0", | ||
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "private": true, | ||
| "peerDependencies": { | ||
| "expo": "*", | ||
| "react": "*", | ||
| "react-native": "*" | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
apps/mobile/modules/active-agents-live-update/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Local Expo module for Android Live Updates. | ||
| // | ||
| // Slice `and` (level 3) adds the Android native implementation under | ||
| // modules/active-agents-live-update/android and the Android sink under | ||
| // src/glanceable-android. Until then every function is a no-op so the module | ||
| // loads in the main process on both platforms. | ||
|
|
||
| export function start(_snapshot: unknown): void { | ||
| // No-op until the Android native module lands. | ||
| } | ||
|
|
||
| export function update(_snapshot: unknown): void { | ||
| // No-op until the Android native module lands. | ||
| } | ||
|
|
||
| export function end(_immediate?: boolean): void { | ||
| // No-op until the Android native module lands. | ||
| } | ||
|
|
||
| export function isLiveUpdateCapable(): boolean { | ||
| return false; | ||
| } | ||
|
|
||
| // The Android sink registers itself from the main process once slice `and` | ||
| // provides @/glanceable-android/register. The try/catch keeps this import a | ||
| // no-op before that file exists. | ||
| try { | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| require('@/glanceable-android/register'); | ||
| } catch { | ||
| // glanceable-android/register does not exist until slice `and` lands. | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| // Wraps react-native-android-widget so its config plugin only applies once the | ||
| // Android widget actually exists. The widget config file is created by slice | ||
| // `and` (level 3) at apps/mobile/src/glanceable-android/widget-config.json; | ||
| // before then this plugin is a no-op, so level 2 prebuilds are unaffected. | ||
| const WIDGET_CONFIG_PATH = path.resolve(__dirname, '../src/glanceable-android/widget-config.json'); | ||
|
|
||
| function loadAndroidWidgetsPlugin() { | ||
| const resolved = require.resolve('react-native-android-widget/app.plugin.js'); | ||
| const mod = require(resolved); | ||
| return typeof mod === 'function' ? mod : mod.default; | ||
| } | ||
|
|
||
| module.exports = function withActiveAgentsAndroidWidget(config) { | ||
| if (!fs.existsSync(WIDGET_CONFIG_PATH)) { | ||
| // No Android widget yet: keep the config untouched. | ||
| return config; | ||
| } | ||
| const widgetConfig = JSON.parse(fs.readFileSync(WIDGET_CONFIG_PATH, 'utf8')); | ||
| const widgets = Array.isArray(widgetConfig.widgets) ? widgetConfig.widgets : []; | ||
| if (widgets.length === 0) { | ||
| return config; | ||
| } | ||
| return loadAndroidWidgetsPlugin()(config, { widgets }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| // Registers the local `active-agents-live-update` Expo module. | ||
| // | ||
| // The module is a `file:` dependency declared in apps/mobile/package.json, so | ||
| // pnpm links it into the app's node_modules and Expo autolinking reads its | ||
| // expo-module.config.json during prebuild. At this level it is JS-only (the | ||
| // native module lists are empty); slice `and` adds the Android native module. | ||
| // This plugin exists as the named hook in app.config.ts so a later level can | ||
| // extend registration without touching app.config.ts again. | ||
| module.exports = function withActiveAgentsLiveUpdate(config) { | ||
| const moduleDir = path.resolve(__dirname, '../modules/active-agents-live-update'); | ||
| const moduleConfig = path.join(moduleDir, 'expo-module.config.json'); | ||
| if (!fs.existsSync(moduleConfig)) { | ||
| throw new Error(`active-agents-live-update module config not found at ${moduleConfig}`); | ||
| } | ||
| return config; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
apps/mobile/src/glanceable-ios/active-agents-live-activity.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { Text, VStack } from '@expo/ui/swift-ui'; | ||
| import { | ||
| accessibilityElement, | ||
| accessibilityLabel, | ||
| font, | ||
| foregroundStyle, | ||
| } from '@expo/ui/swift-ui/modifiers'; | ||
| import { createLiveActivity } from 'expo-widgets'; | ||
| import { PlatformColor } from 'react-native'; | ||
|
|
||
| import { type GlanceableViewProps } from './view-props'; | ||
|
|
||
| /* eslint-disable new-cap -- PlatformColor is a React Native factory function, not a constructor */ | ||
|
|
||
| // The layout function below is marked with the `'widget'` directive, so Babel | ||
| // stringifies it and the watcher extension re-evaluates the source. Everything | ||
| // it references must be a watcher global (`Text`, `VStack`, the modifiers, | ||
| // `PlatformColor`) or a built-in. Do not call `@/` helpers or i18n from here — | ||
| // translated copy arrives through `props`. The inlined English fallbacks below | ||
| // only render while the gallery placeholder has no snapshot props. | ||
|
|
||
| export const ActiveAgentsLiveActivity = createLiveActivity<Partial<GlanceableViewProps>>( | ||
| 'ActiveAgentsLiveActivity', | ||
| (props, environment) => { | ||
| 'widget'; | ||
|
|
||
| const dark = environment.colorScheme === 'dark'; | ||
| const counts = props.countLines ?? []; | ||
| const hasCounts = counts.length > 0; | ||
| const primaryLabel = props.primaryLabel ?? null; | ||
| const primaryCount = String(props.primaryCount ?? 0); | ||
| const statusLine = props.statusLine ?? (hasCounts ? null : 'No work in progress'); | ||
| const elapsedAnchor = props.elapsedAnchor ?? null; | ||
|
|
||
| const primaryForeground = foregroundStyle(PlatformColor('label')); | ||
| const mutedForeground = foregroundStyle( | ||
| dark ? PlatformColor('secondaryLabel') : PlatformColor('tertiaryLabel') | ||
| ); | ||
|
|
||
| const countRows = counts.map(line => ( | ||
| <Text key={line.label} modifiers={[font({ textStyle: 'body' }), primaryForeground]}> | ||
| {`${line.count} ${line.label}`} | ||
| </Text> | ||
| )); | ||
|
|
||
| return { | ||
| banner: ( | ||
| <VStack | ||
| alignment="leading" | ||
| spacing={4} | ||
| modifiers={[ | ||
| accessibilityElement('combine'), | ||
| accessibilityLabel(props.accessibilityLabel ?? ''), | ||
| ]} | ||
| > | ||
| {hasCounts ? ( | ||
| <VStack alignment="leading" spacing={2}> | ||
| {countRows} | ||
| </VStack> | ||
| ) : null} | ||
| {statusLine !== null ? <Text modifiers={[mutedForeground]}>{statusLine}</Text> : null} | ||
| {elapsedAnchor !== null ? ( | ||
| <Text | ||
| date={new Date(elapsedAnchor)} | ||
| dateStyle="relative" | ||
| modifiers={[mutedForeground]} | ||
| /> | ||
| ) : null} | ||
| </VStack> | ||
| ), | ||
| compactLeading: ( | ||
| <Text modifiers={[font({ textStyle: 'headline', weight: 'bold' }), primaryForeground]}> | ||
| {hasCounts ? primaryCount : statusLine} | ||
| </Text> | ||
| ), | ||
| compactTrailing: ( | ||
| <Text modifiers={[font({ textStyle: 'footnote' }), primaryForeground]}> | ||
| {hasCounts ? (primaryLabel ?? primaryCount) : ''} | ||
| </Text> | ||
| ), | ||
| minimal: ( | ||
| <Text modifiers={[font({ textStyle: 'headline', weight: 'bold' }), primaryForeground]}> | ||
| {hasCounts ? primaryCount : ''} | ||
| </Text> | ||
| ), | ||
| expandedLeading: ( | ||
| <VStack alignment="leading" spacing={2}> | ||
| {countRows} | ||
| </VStack> | ||
| ), | ||
| expandedTrailing: ( | ||
| <VStack alignment="leading" spacing={2}> | ||
| {statusLine !== null ? <Text modifiers={[mutedForeground]}>{statusLine}</Text> : null} | ||
| {elapsedAnchor !== null ? ( | ||
| <Text | ||
| date={new Date(elapsedAnchor)} | ||
| dateStyle="relative" | ||
| modifiers={[mutedForeground]} | ||
| /> | ||
| ) : null} | ||
| </VStack> | ||
| ), | ||
| expandedBottom: ( | ||
| <VStack alignment="leading" spacing={2}> | ||
| {statusLine !== null && !hasCounts ? ( | ||
| <Text modifiers={[mutedForeground]}>{statusLine}</Text> | ||
| ) : null} | ||
| </VStack> | ||
| ), | ||
| }; | ||
| } | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.