expo-live-activity 0.2.1-alpha1 → 0.3.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/.prettierignore +5 -0
  2. package/.prettierrc +6 -0
  3. package/README.md +152 -56
  4. package/app.plugin.js +1 -1
  5. package/build/ExpoLiveActivityModule.d.ts.map +1 -1
  6. package/build/ExpoLiveActivityModule.js.map +1 -1
  7. package/build/index.d.ts +18 -2
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +21 -33
  10. package/build/index.js.map +1 -1
  11. package/eslint.config.js +42 -0
  12. package/ios/ExpoLiveActivityModule.swift +154 -91
  13. package/ios/Helpers.swift +1 -2
  14. package/ios-files/Assets.xcassets/AccentColor.colorset/Contents.json +5 -5
  15. package/ios-files/Assets.xcassets/AppIcon.appiconset/Contents.json +19 -19
  16. package/ios-files/Assets.xcassets/Contents.json +3 -3
  17. package/ios-files/Assets.xcassets/WidgetBackground.colorset/Contents.json +5 -5
  18. package/ios-files/View+applyWidgetURL.swift +15 -1
  19. package/package.json +18 -6
  20. package/plugin/build/index.d.ts +1 -1
  21. package/plugin/build/index.js +8 -3
  22. package/plugin/build/lib/getWidgetExtensionEntitlements.d.ts +6 -2
  23. package/plugin/build/lib/getWidgetExtensionEntitlements.js +1 -1
  24. package/plugin/build/lib/getWidgetFiles.js +18 -17
  25. package/plugin/build/types.d.ts +1 -1
  26. package/plugin/build/withConfig.d.ts +1 -1
  27. package/plugin/build/withPlist.d.ts +5 -0
  28. package/plugin/build/withPlist.js +25 -0
  29. package/plugin/build/withPodfile.d.ts +1 -1
  30. package/plugin/build/withPodfile.js +5 -5
  31. package/plugin/build/withPushNotifications.d.ts +1 -1
  32. package/plugin/build/withPushNotifications.js +2 -2
  33. package/plugin/build/withWidgetExtensionEntitlements.d.ts +1 -1
  34. package/plugin/build/withWidgetExtensionEntitlements.js +1 -1
  35. package/plugin/build/withXcode.d.ts +1 -1
  36. package/plugin/build/withXcode.js +8 -8
  37. package/plugin/build/xcode/addBuildPhases.d.ts +2 -2
  38. package/plugin/build/xcode/addBuildPhases.js +8 -10
  39. package/plugin/build/xcode/addPbxGroup.d.ts +2 -2
  40. package/plugin/build/xcode/addPbxGroup.js +2 -2
  41. package/plugin/build/xcode/addProductFile.d.ts +1 -1
  42. package/plugin/build/xcode/addProductFile.js +3 -3
  43. package/plugin/build/xcode/addTargetDependency.d.ts +1 -1
  44. package/plugin/build/xcode/addTargetDependency.js +5 -7
  45. package/plugin/build/xcode/addToPbxNativeTargetSection.d.ts +1 -1
  46. package/plugin/build/xcode/addToPbxNativeTargetSection.js +5 -5
  47. package/plugin/build/xcode/addToPbxProjectSection.d.ts +1 -1
  48. package/plugin/build/xcode/addToPbxProjectSection.js +1 -2
  49. package/plugin/build/xcode/addXCConfigurationList.d.ts +1 -1
  50. package/plugin/build/xcode/addXCConfigurationList.js +6 -6
  51. package/plugin/src/index.ts +19 -18
  52. package/plugin/src/lib/getWidgetExtensionEntitlements.ts +10 -13
  53. package/plugin/src/lib/getWidgetFiles.ts +70 -74
  54. package/plugin/src/types.ts +3 -5
  55. package/plugin/src/withConfig.ts +15 -15
  56. package/plugin/src/withPlist.ts +27 -0
  57. package/plugin/src/withPodfile.ts +17 -24
  58. package/plugin/src/withPushNotifications.ts +7 -11
  59. package/plugin/src/withWidgetExtensionEntitlements.ts +14 -14
  60. package/plugin/src/withXcode.ts +32 -41
  61. package/plugin/src/xcode/addBuildPhases.ts +26 -41
  62. package/plugin/src/xcode/addPbxGroup.ts +9 -16
  63. package/plugin/src/xcode/addProductFile.ts +7 -7
  64. package/plugin/src/xcode/addTargetDependency.ts +7 -12
  65. package/plugin/src/xcode/addToPbxNativeTargetSection.ts +13 -15
  66. package/plugin/src/xcode/addToPbxProjectSection.ts +7 -17
  67. package/plugin/src/xcode/addXCConfigurationList.ts +16 -16
  68. package/plugin/tsconfig.tsbuildinfo +1 -1
  69. package/scripts/update-version.sh +15 -0
  70. package/src/ExpoLiveActivityModule.ts +2 -2
  71. package/src/index.ts +69 -55
  72. package/.eslintrc.js +0 -5
@@ -1,7 +1,7 @@
1
- import { XcodeProject } from "@expo/config-plugins";
2
- import * as util from "util";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
+ import * as util from 'util'
3
3
 
4
- import { WidgetFiles } from "../lib/getWidgetFiles";
4
+ import { WidgetFiles } from '../lib/getWidgetFiles'
5
5
 
6
6
  export function addBuildPhases(
7
7
  xcodeProject: XcodeProject,
@@ -11,73 +11,58 @@ export function addBuildPhases(
11
11
  productFile,
12
12
  widgetFiles,
13
13
  }: {
14
- targetUuid: string;
15
- groupName: string;
14
+ targetUuid: string
15
+ groupName: string
16
16
  productFile: {
17
- uuid: string;
18
- target: string;
19
- basename: string;
20
- group: string;
21
- };
22
- widgetFiles: WidgetFiles;
17
+ uuid: string
18
+ target: string
19
+ basename: string
20
+ group: string
21
+ }
22
+ widgetFiles: WidgetFiles
23
23
  }
24
24
  ) {
25
- const buildPath = `""`;
26
- const folderType = "app_extension";
25
+ const buildPath = `""`
26
+ const folderType = 'app_extension'
27
27
 
28
- const {
29
- swiftFiles,
30
- intentFiles,
31
- assetDirectories,
32
- entitlementFiles,
33
- plistFiles,
34
- } = widgetFiles;
28
+ const { swiftFiles, intentFiles, assetDirectories } = widgetFiles
35
29
 
36
30
  // Sources build phase
37
31
  xcodeProject.addBuildPhase(
38
32
  [...swiftFiles, ...intentFiles],
39
- "PBXSourcesBuildPhase",
33
+ 'PBXSourcesBuildPhase',
40
34
  groupName,
41
35
  targetUuid,
42
36
  folderType,
43
37
  buildPath
44
- );
38
+ )
45
39
 
46
40
  // Copy files build phase
47
41
  xcodeProject.addBuildPhase(
48
42
  [],
49
- "PBXCopyFilesBuildPhase",
43
+ 'PBXCopyFilesBuildPhase',
50
44
  groupName,
51
45
  xcodeProject.getFirstTarget().uuid,
52
46
  folderType,
53
47
  buildPath
54
- );
48
+ )
55
49
 
56
- xcodeProject
57
- .buildPhaseObject("PBXCopyFilesBuildPhase", groupName, productFile.target)
58
- .files.push({
59
- value: productFile.uuid,
60
- comment: util.format("%s in %s", productFile.basename, productFile.group), // longComment(file);
61
- });
62
- xcodeProject.addToPbxBuildFileSection(productFile);
50
+ xcodeProject.buildPhaseObject('PBXCopyFilesBuildPhase', groupName, productFile.target).files.push({
51
+ value: productFile.uuid,
52
+ comment: util.format('%s in %s', productFile.basename, productFile.group), // longComment(file);
53
+ })
54
+ xcodeProject.addToPbxBuildFileSection(productFile)
63
55
 
64
56
  // Frameworks build phase
65
- xcodeProject.addBuildPhase(
66
- [],
67
- "PBXFrameworksBuildPhase",
68
- groupName,
69
- targetUuid,
70
- folderType,
71
- buildPath
72
- );
57
+ xcodeProject.addBuildPhase([], 'PBXFrameworksBuildPhase', groupName, targetUuid, folderType, buildPath)
73
58
 
74
59
  // Resources build phase
75
60
  xcodeProject.addBuildPhase(
76
61
  [...assetDirectories],
77
- "PBXResourcesBuildPhase",
62
+ 'PBXResourcesBuildPhase',
78
63
  groupName,
79
64
  targetUuid,
80
65
  folderType,
81
66
  buildPath
82
- );
67
+ )
83
68
  }
@@ -1,6 +1,6 @@
1
- import { XcodeProject } from "@expo/config-plugins";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
2
 
3
- import { WidgetFiles } from "../lib/getWidgetFiles";
3
+ import { WidgetFiles } from '../lib/getWidgetFiles'
4
4
 
5
5
  export function addPbxGroup(
6
6
  xcodeProject: XcodeProject,
@@ -8,18 +8,11 @@ export function addPbxGroup(
8
8
  targetName,
9
9
  widgetFiles,
10
10
  }: {
11
- targetName: string;
12
- widgetFiles: WidgetFiles;
11
+ targetName: string
12
+ widgetFiles: WidgetFiles
13
13
  }
14
14
  ) {
15
- const {
16
- swiftFiles,
17
- intentFiles,
18
- otherFiles,
19
- assetDirectories,
20
- entitlementFiles,
21
- plistFiles,
22
- } = widgetFiles;
15
+ const { swiftFiles, intentFiles, otherFiles, assetDirectories, entitlementFiles, plistFiles } = widgetFiles
23
16
 
24
17
  // Add PBX group
25
18
  const { uuid: pbxGroupUuid } = xcodeProject.addPbxGroup(
@@ -34,15 +27,15 @@ export function addPbxGroup(
34
27
  ],
35
28
  targetName,
36
29
  targetName
37
- );
30
+ )
38
31
 
39
32
  // Add PBXGroup to top level group
40
- const groups = xcodeProject.hash.project.objects["PBXGroup"];
33
+ const groups = xcodeProject.hash.project.objects['PBXGroup']
41
34
  if (pbxGroupUuid) {
42
35
  Object.keys(groups).forEach(function (key) {
43
36
  if (groups[key].name === undefined && groups[key].path === undefined) {
44
- xcodeProject.addToPbxGroup(pbxGroupUuid, key);
37
+ xcodeProject.addToPbxGroup(pbxGroupUuid, key)
45
38
  }
46
- });
39
+ })
47
40
  }
48
41
  }
@@ -1,4 +1,4 @@
1
- import { XcodeProject } from "@expo/config-plugins";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
2
 
3
3
  export function addProductFile(
4
4
  xcodeProject: XcodeProject,
@@ -9,17 +9,17 @@ export function addProductFile(
9
9
  // fileRef: xcodeProject.generateUuid(),
10
10
  // uuid: xcodeProject.generateUuid(),
11
11
  group: groupName,
12
- explicitFileType: "wrapper.app-extension",
12
+ explicitFileType: 'wrapper.app-extension',
13
13
  /* fileEncoding: 4, */
14
14
  settings: {
15
- ATTRIBUTES: ["RemoveHeadersOnCopy"],
15
+ ATTRIBUTES: ['RemoveHeadersOnCopy'],
16
16
  },
17
17
  includeInIndex: 0,
18
18
  path: `${targetName}.appex`,
19
- sourceTree: "BUILT_PRODUCTS_DIR",
20
- };
19
+ sourceTree: 'BUILT_PRODUCTS_DIR',
20
+ }
21
21
 
22
- const productFile = xcodeProject.addProductFile(targetName, options);
22
+ const productFile = xcodeProject.addProductFile(targetName, options)
23
23
 
24
- return productFile;
24
+ return productFile
25
25
  }
@@ -1,17 +1,12 @@
1
- import { XcodeProject } from "@expo/config-plugins";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
2
 
3
- export function addTargetDependency(
4
- xcodeProject: XcodeProject,
5
- target: { uuid: string }
6
- ) {
7
- if (!xcodeProject.hash.project.objects["PBXTargetDependency"]) {
8
- xcodeProject.hash.project.objects["PBXTargetDependency"] = {};
3
+ export function addTargetDependency(xcodeProject: XcodeProject, target: { uuid: string }) {
4
+ if (!xcodeProject.hash.project.objects['PBXTargetDependency']) {
5
+ xcodeProject.hash.project.objects['PBXTargetDependency'] = {}
9
6
  }
10
- if (!xcodeProject.hash.project.objects["PBXContainerItemProxy"]) {
11
- xcodeProject.hash.project.objects["PBXContainerItemProxy"] = {};
7
+ if (!xcodeProject.hash.project.objects['PBXContainerItemProxy']) {
8
+ xcodeProject.hash.project.objects['PBXContainerItemProxy'] = {}
12
9
  }
13
10
 
14
- xcodeProject.addTargetDependency(xcodeProject.getFirstTarget().uuid, [
15
- target.uuid,
16
- ]);
11
+ xcodeProject.addTargetDependency(xcodeProject.getFirstTarget().uuid, [target.uuid])
17
12
  }
@@ -1,4 +1,4 @@
1
- import { XcodeProject } from "@expo/config-plugins";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
2
 
3
3
  export function addToPbxNativeTargetSection(
4
4
  xcodeProject: XcodeProject,
@@ -8,16 +8,16 @@ export function addToPbxNativeTargetSection(
8
8
  productFile,
9
9
  xCConfigurationList,
10
10
  }: {
11
- targetName: string;
12
- targetUuid: string;
13
- productFile: { fileRef: string };
14
- xCConfigurationList: { uuid: string };
11
+ targetName: string
12
+ targetUuid: string
13
+ productFile: { fileRef: string }
14
+ xCConfigurationList: { uuid: string }
15
15
  }
16
16
  ) {
17
17
  const target = {
18
18
  uuid: targetUuid,
19
19
  pbxNativeTarget: {
20
- isa: "PBXNativeTarget",
20
+ isa: 'PBXNativeTarget',
21
21
  name: targetName,
22
22
  productName: targetName,
23
23
  productReference: productFile.fileRef,
@@ -27,20 +27,18 @@ export function addToPbxNativeTargetSection(
27
27
  buildRules: [],
28
28
  dependencies: [],
29
29
  },
30
- };
30
+ }
31
31
 
32
- xcodeProject.addToPbxNativeTargetSection(target);
32
+ xcodeProject.addToPbxNativeTargetSection(target)
33
33
 
34
- const frameworksGroup = xcodeProject.findPBXGroupKey({ name: "Frameworks" });
35
- const file1 = xcodeProject.addFile("WidgetKit.framework", frameworksGroup);
36
- const file2 = xcodeProject.addFile("SwiftUI.framework", frameworksGroup);
37
- const frameworksBuildPhaseObj = xcodeProject.pbxFrameworksBuildPhaseObj(
38
- target.uuid
39
- );
34
+ // const frameworksGroup = xcodeProject.findPBXGroupKey({ name: 'Frameworks' })
35
+ // const file1 = xcodeProject.addFile('WidgetKit.framework', frameworksGroup)
36
+ // const file2 = xcodeProject.addFile('SwiftUI.framework', frameworksGroup)
37
+ // const frameworksBuildPhaseObj = xcodeProject.pbxFrameworksBuildPhaseObj(target.uuid)
40
38
  /* console.log(
41
39
  { file1, file2, frameworksBuildPhaseObj },
42
40
  frameworksBuildPhaseObj.files
43
41
  ); */
44
42
 
45
- return target;
43
+ return target
46
44
  }
@@ -1,23 +1,13 @@
1
- import { XcodeProject } from "@expo/config-plugins";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
2
 
3
- export function addToPbxProjectSection(
4
- xcodeProject: XcodeProject,
5
- target: { uuid: string }
6
- ) {
7
- xcodeProject.addToPbxProjectSection(target);
3
+ export function addToPbxProjectSection(xcodeProject: XcodeProject, target: { uuid: string }) {
4
+ xcodeProject.addToPbxProjectSection(target)
8
5
 
9
6
  // Add target attributes to project section
10
- if (
11
- !xcodeProject.pbxProjectSection()[xcodeProject.getFirstProject().uuid]
12
- .attributes.TargetAttributes
13
- ) {
14
- xcodeProject.pbxProjectSection()[
15
- xcodeProject.getFirstProject().uuid
16
- ].attributes.TargetAttributes = {};
7
+ if (!xcodeProject.pbxProjectSection()[xcodeProject.getFirstProject().uuid].attributes.TargetAttributes) {
8
+ xcodeProject.pbxProjectSection()[xcodeProject.getFirstProject().uuid].attributes.TargetAttributes = {}
17
9
  }
18
- xcodeProject.pbxProjectSection()[
19
- xcodeProject.getFirstProject().uuid
20
- ].attributes.TargetAttributes[target.uuid] = {
10
+ xcodeProject.pbxProjectSection()[xcodeProject.getFirstProject().uuid].attributes.TargetAttributes[target.uuid] = {
21
11
  LastSwiftMigration: 1250,
22
- };
12
+ }
23
13
  }
@@ -1,4 +1,4 @@
1
- import { XcodeProject } from "@expo/config-plugins";
1
+ import { XcodeProject } from '@expo/config-plugins'
2
2
 
3
3
  export function addXCConfigurationList(
4
4
  xcodeProject: XcodeProject,
@@ -9,11 +9,11 @@ export function addXCConfigurationList(
9
9
  deploymentTarget,
10
10
  marketingVersion,
11
11
  }: {
12
- targetName: string;
13
- currentProjectVersion: string;
14
- bundleIdentifier: string;
15
- deploymentTarget: string;
16
- marketingVersion?: string;
12
+ targetName: string
13
+ currentProjectVersion: string
14
+ bundleIdentifier: string
15
+ deploymentTarget: string
16
+ marketingVersion?: string
17
17
  }
18
18
  ) {
19
19
  const commonBuildSettings: any = {
@@ -41,7 +41,7 @@ export function addXCConfigurationList(
41
41
  SWIFT_OPTIMIZATION_LEVEL = "-Onone"; */
42
42
 
43
43
  PRODUCT_NAME: `"$(TARGET_NAME)"`,
44
- SWIFT_VERSION: "5.0",
44
+ SWIFT_VERSION: '5.0',
45
45
  TARGETED_DEVICE_FAMILY: `"1,2"`,
46
46
  INFOPLIST_FILE: `${targetName}/Info.plist`,
47
47
  CURRENT_PROJECT_VERSION: `"${currentProjectVersion}"`,
@@ -54,30 +54,30 @@ export function addXCConfigurationList(
54
54
  SWIFT_OPTIMIZATION_LEVEL: `"-Onone"`,
55
55
  CODE_SIGN_ENTITLEMENTS: `"${targetName}/${targetName}.entitlements"`,
56
56
  // DEVELOPMENT_TEAM: `"G76836P2D4"`,
57
- };
57
+ }
58
58
 
59
59
  const buildConfigurationsList = [
60
60
  {
61
- name: "Debug",
62
- isa: "XCBuildConfiguration",
61
+ name: 'Debug',
62
+ isa: 'XCBuildConfiguration',
63
63
  buildSettings: {
64
64
  ...commonBuildSettings,
65
65
  },
66
66
  },
67
67
  {
68
- name: "Release",
69
- isa: "XCBuildConfiguration",
68
+ name: 'Release',
69
+ isa: 'XCBuildConfiguration',
70
70
  buildSettings: {
71
71
  ...commonBuildSettings,
72
72
  },
73
73
  },
74
- ];
74
+ ]
75
75
 
76
76
  const xCConfigurationList = xcodeProject.addXCConfigurationList(
77
77
  buildConfigurationsList,
78
- "Release",
78
+ 'Release',
79
79
  `Build configuration list for PBXNativeTarget "${targetName}"`
80
- );
80
+ )
81
81
 
82
- return xCConfigurationList;
82
+ return xCConfigurationList
83
83
  }
@@ -1 +1 @@
1
- {"root":["./src/index.ts","./src/types.ts","./src/withConfig.ts","./src/withPodfile.ts","./src/withPushNotifications.ts","./src/withWidgetExtensionEntitlements.ts","./src/withXcode.ts","./src/lib/getWidgetExtensionEntitlements.ts","./src/lib/getWidgetFiles.ts","./src/xcode/addBuildPhases.ts","./src/xcode/addPbxGroup.ts","./src/xcode/addProductFile.ts","./src/xcode/addTargetDependency.ts","./src/xcode/addToPbxNativeTargetSection.ts","./src/xcode/addToPbxProjectSection.ts","./src/xcode/addXCConfigurationList.ts"],"version":"5.8.3"}
1
+ {"root":["./src/index.ts","./src/types.ts","./src/withConfig.ts","./src/withPlist.ts","./src/withPodfile.ts","./src/withPushNotifications.ts","./src/withWidgetExtensionEntitlements.ts","./src/withXcode.ts","./src/lib/getWidgetExtensionEntitlements.ts","./src/lib/getWidgetFiles.ts","./src/xcode/addBuildPhases.ts","./src/xcode/addPbxGroup.ts","./src/xcode/addProductFile.ts","./src/xcode/addTargetDependency.ts","./src/xcode/addToPbxNativeTargetSection.ts","./src/xcode/addToPbxProjectSection.ts","./src/xcode/addXCConfigurationList.ts"],"version":"5.8.3"}
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ TAG=$(git describe --tags --exact-match HEAD 2>/dev/null || true)
5
+
6
+ if [[ "$TAG" =~ ^alpha_v([0-9]+\.[0-9]+\.[0-9]+)\(([0-9]+)\)$ ]]; then
7
+ NEW_VERSION="${BASH_REMATCH[1]}-alpha${BASH_REMATCH[2]}"
8
+ elif [[ "$TAG" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
9
+ NEW_VERSION="${BASH_REMATCH[1]}"
10
+ fi
11
+
12
+ if [[ -n "${NEW_VERSION:-}" ]]; then
13
+ jq --arg v "$NEW_VERSION" '.version = $v' package.json > package.json.tmp \
14
+ && mv package.json.tmp package.json
15
+ fi
@@ -1,3 +1,3 @@
1
- import { requireOptionalNativeModule } from 'expo';
1
+ import { requireOptionalNativeModule } from 'expo'
2
2
 
3
- export default requireOptionalNativeModule('ExpoLiveActivity');
3
+ export default requireOptionalNativeModule('ExpoLiveActivity')
package/src/index.ts CHANGED
@@ -1,52 +1,69 @@
1
- import ExpoLiveActivityModule from "./ExpoLiveActivityModule";
2
- import { Platform } from "react-native";
3
- import { EventSubscription } from 'expo-modules-core';
1
+ import { EventSubscription } from 'expo-modules-core'
2
+ import { Platform } from 'react-native'
3
+
4
+ import ExpoLiveActivityModule from './ExpoLiveActivityModule'
5
+
6
+ type Voidable<T> = T | void
4
7
 
5
8
  export type DynamicIslandTimerType = 'circular' | 'digital'
6
9
 
7
10
  export type LiveActivityState = {
8
- title: string;
9
- subtitle?: string;
10
- date?: number;
11
- imageName?: string;
12
- dynamicIslandImageName?: string;
13
- };
11
+ title: string
12
+ subtitle?: string
13
+ date?: number
14
+ imageName?: string
15
+ dynamicIslandImageName?: string
16
+ }
14
17
 
15
18
  export type LiveActivityConfig = {
16
- backgroundColor?: string;
17
- titleColor?: string;
18
- subtitleColor?: string;
19
- progressViewTint?: string;
20
- progressViewLabelColor?: string;
21
- deepLinkUrl?: string;
22
- timerType?: DynamicIslandTimerType;
23
- };
19
+ backgroundColor?: string
20
+ titleColor?: string
21
+ subtitleColor?: string
22
+ progressViewTint?: string
23
+ progressViewLabelColor?: string
24
+ deepLinkUrl?: string
25
+ timerType?: DynamicIslandTimerType
26
+ }
24
27
 
25
28
  export type ActivityTokenReceivedEvent = {
26
- activityID: string;
27
- activityPushToken: string;
28
- };
29
+ activityID: string
30
+ activityName: string
31
+ activityPushToken: string
32
+ }
33
+
34
+ export type ActivityPushToStartTokenReceivedEvent = {
35
+ activityPushToStartToken: string
36
+ }
37
+
38
+ type ActivityState = 'active' | 'dismissed' | 'pending' | 'stale' | 'ended'
39
+
40
+ export type ActivityUpdateEvent = {
41
+ activityID: string
42
+ activityName: string
43
+ activityState: ActivityState
44
+ }
29
45
 
30
46
  export type LiveActivityModuleEvents = {
31
- onTokenReceived: (params: ActivityTokenReceivedEvent) => void;
32
- };
47
+ onTokenReceived: (params: ActivityTokenReceivedEvent) => void
48
+ onPushToStartTokenReceived: (params: ActivityPushToStartTokenReceivedEvent) => void
49
+ onStateChange: (params: ActivityUpdateEvent) => void
50
+ }
51
+
52
+ function assertIOS(name: string) {
53
+ const isIOS = Platform.OS === 'ios'
54
+
55
+ if (!isIOS) console.error(`${name} is only available on iOS`)
56
+
57
+ return isIOS
58
+ }
33
59
 
34
60
  /**
35
61
  * @param {LiveActivityState} state The state for the live activity.
36
62
  * @param {LiveActivityConfig} config Live activity config object.
37
63
  * @returns {string} The identifier of the started activity or undefined if creating live activity failed.
38
64
  */
39
- export function startActivity(state: LiveActivityState, config?: LiveActivityConfig): string | undefined {
40
- if (Platform.OS !== "ios") {
41
- console.error("startActivity is only available on iOS");
42
- return undefined
43
- }
44
- try {
45
- return ExpoLiveActivityModule.startActivity(state, config);
46
- } catch (error) {
47
- console.error(`startActivity failed with an error: ${error}`);
48
- return undefined
49
- }
65
+ export function startActivity(state: LiveActivityState, config?: LiveActivityConfig): Voidable<string> {
66
+ if (assertIOS('startActivity')) return ExpoLiveActivityModule.startActivity(state, config)
50
67
  }
51
68
 
52
69
  /**
@@ -54,14 +71,7 @@ export function startActivity(state: LiveActivityState, config?: LiveActivityCon
54
71
  * @param {LiveActivityState} state The updated state for the live activity.
55
72
  */
56
73
  export function stopActivity(id: string, state: LiveActivityState) {
57
- if (Platform.OS !== "ios") {
58
- console.error("stopActivity is only available on iOS");
59
- }
60
- try {
61
- return ExpoLiveActivityModule.stopActivity(id, state);
62
- } catch (error) {
63
- console.error(`stopActivity failed with an error: ${error}`);
64
- }
74
+ if (assertIOS('stopActivity')) return ExpoLiveActivityModule.stopActivity(id, state)
65
75
  }
66
76
 
67
77
  /**
@@ -69,20 +79,24 @@ export function stopActivity(id: string, state: LiveActivityState) {
69
79
  * @param {LiveActivityState} state The updated state for the live activity.
70
80
  */
71
81
  export function updateActivity(id: string, state: LiveActivityState) {
72
- if (Platform.OS !== "ios") {
73
- console.error("updateActivity is only available on iOS");
74
- }
75
- try {
76
- return ExpoLiveActivityModule.updateActivity(id, state);
77
- } catch (error) {
78
- console.error(`updateActivity failed with an error: ${error}`);
79
- }
82
+ if (assertIOS('updateActivity')) return ExpoLiveActivityModule.updateActivity(id, state)
83
+ }
84
+
85
+ export function addActivityTokenListener(
86
+ listener: (event: ActivityTokenReceivedEvent) => void
87
+ ): Voidable<EventSubscription> {
88
+ if (assertIOS('addActivityTokenListener')) return ExpoLiveActivityModule.addListener('onTokenReceived', listener)
89
+ }
90
+
91
+ export function addActivityPushToStartTokenListener(
92
+ listener: (event: ActivityPushToStartTokenReceivedEvent) => void
93
+ ): Voidable<EventSubscription> {
94
+ if (assertIOS('addActivityPushToStartTokenListener'))
95
+ return ExpoLiveActivityModule.addListener('onPushToStartTokenReceived', listener)
80
96
  }
81
97
 
82
- export function addActivityTokenListener(listener: (event: ActivityTokenReceivedEvent) => void): EventSubscription | undefined {
83
- if (Platform.OS !== "ios") {
84
- console.error("addActivityTokenListener is only available on iOS");
85
- return undefined
86
- }
87
- return ExpoLiveActivityModule.addListener('onTokenReceived', listener);
98
+ export function addActivityUpdatesListener(
99
+ listener: (event: ActivityUpdateEvent) => void
100
+ ): Voidable<EventSubscription> {
101
+ if (assertIOS('addActivityUpdatesListener')) return ExpoLiveActivityModule.addListener('onStateChange', listener)
88
102
  }
package/.eslintrc.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ['universe/native', 'universe/web'],
4
- ignorePatterns: ['build'],
5
- };