expo-live-activity 0.4.1 → 0.4.2

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.
package/README.md CHANGED
@@ -62,11 +62,14 @@ The module comes with a built-in config plugin that creates a target in iOS with
62
62
  2. **Assets configuration:**
63
63
  Place images intended for Live Activities in the `assets/liveActivity` folder. The plugin manages these assets automatically.
64
64
 
65
- Then prebuild your app with:
65
+ Then prebuild your app with:
66
66
 
67
- ```sh
68
- npx expo prebuild --clean
69
- ```
67
+ ```sh
68
+ npx expo prebuild --clean
69
+ ```
70
+
71
+ > [!NOTE]
72
+ > Because of iOS limitations, the assets can't be bigger than 4KB ([native Live Activity documentation](https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities#Understand-constraints))
70
73
 
71
74
  ### Step 3: Usage in Your React Native App
72
75
 
@@ -153,7 +156,9 @@ The `config` object should include:
153
156
  timerType?: DynamicIslandTimerType; // "circular" | "digital" - defines timer appearance on the dynamic island
154
157
  padding?: Padding // number | {top?: number bottom?: number ...}
155
158
  imagePosition?: ImagePosition; // 'left' | 'right';
156
- imageSize?: ImageSize // 'default' | number (points maxHeight)
159
+ imageAlign?: ImageAlign; // 'top' | 'center' | 'bottom'
160
+ imageSize?: ImageSize // { width: number|`${number}%`, height: number|`${number}%` } | undefined (defaults to 64pt)
161
+ contentFit?: ImageContentFit; // 'cover' | 'contain' | 'fill' | 'none' | 'scale-down'
157
162
  };
158
163
  ```
159
164
 
@@ -186,7 +191,9 @@ const config: LiveActivity.LiveActivityConfig = {
186
191
  timerType: 'circular',
187
192
  padding: { horizontal: 20, top: 16, bottom: 16 },
188
193
  imagePosition: 'right',
189
- imageSize: 'default', // or a number e.g. 80 for custom image height
194
+ imageAlign: 'center',
195
+ imageSize: { height: '50%', width: '50%' }, // number (pt) or percentage of the image container, if empty by default is 64pt.
196
+ contentFit: 'cover',
190
197
  }
191
198
 
192
199
  const activityId = LiveActivity.startActivity(state, config)
package/build/index.d.ts CHANGED
@@ -33,7 +33,12 @@ export type Padding = {
33
33
  } | number;
34
34
  export type ImagePosition = 'left' | 'right' | 'leftStretch' | 'rightStretch';
35
35
  export type ImageAlign = 'top' | 'center' | 'bottom';
36
- export type ImageSize = number;
36
+ export type ImageDimension = number | `${number}%`;
37
+ export type ImageSize = {
38
+ width: ImageDimension;
39
+ height: ImageDimension;
40
+ };
41
+ export type ImageContentFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
37
42
  export type LiveActivityConfig = {
38
43
  backgroundColor?: string;
39
44
  titleColor?: string;
@@ -46,6 +51,7 @@ export type LiveActivityConfig = {
46
51
  imagePosition?: ImagePosition;
47
52
  imageAlign?: ImageAlign;
48
53
  imageSize?: ImageSize;
54
+ contentFit?: ImageContentFit;
49
55
  };
50
56
  export type ActivityTokenReceivedEvent = {
51
57
  activityID: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAKrD,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE3B,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,SAAS,CAAA;AAE3D,KAAK,eAAe,GAChB;IACE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,GACD;IACE,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAEL,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;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MAAM,CAAA;IACpB,aAAa,EAAE,aAAa,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,CAAC,MAAM,EAAE,0BAA0B,KAAK,IAAI,CAAA;IAC7D,0BAA0B,EAAE,CAAC,MAAM,EAAE,qCAAqC,KAAK,IAAI,CAAA;IACnF,aAAa,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;CACrD,CAAA;AA8DD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAErG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,OAEhE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,OAElE;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,GACpD,QAAQ,CAAC,iBAAiB,CAAC,CAE7B;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,CAAC,KAAK,EAAE,qCAAqC,KAAK,IAAI,GAC/D,QAAQ,CAAC,iBAAiB,CAAC,CAG7B;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAC7C,QAAQ,CAAC,iBAAiB,CAAC,CAE7B"}
package/build/index.js CHANGED
@@ -9,7 +9,7 @@ function assertIOS(name) {
9
9
  function normalizeConfig(config) {
10
10
  if (config === undefined)
11
11
  return config;
12
- const { padding, ...base } = config;
12
+ const { padding, imageSize, ...base } = config;
13
13
  const normalized = { ...base };
14
14
  // Normalize padding: keep number in padding, object in paddingDetails
15
15
  if (typeof padding === 'number') {
@@ -18,6 +18,35 @@ function normalizeConfig(config) {
18
18
  else if (typeof padding === 'object') {
19
19
  normalized.paddingDetails = padding;
20
20
  }
21
+ // Normalize imageSize: object with width/height each a number (points) or percent string like '50%'
22
+ if (imageSize) {
23
+ const regExp = /^(100(?:\.0+)?|\d{1,2}(?:\.\d+)?)%$/; // Matches 0.0% to 100.0%
24
+ const { width, height } = imageSize;
25
+ if (typeof width === 'number') {
26
+ normalized.imageWidth = width;
27
+ }
28
+ else if (typeof width === 'string') {
29
+ const match = width.trim().match(regExp);
30
+ if (match) {
31
+ normalized.imageWidthPercent = Number(match[1]);
32
+ }
33
+ else {
34
+ throw new Error('imageSize.width percent string must be in format "0%" to "100%"');
35
+ }
36
+ }
37
+ if (typeof height === 'number') {
38
+ normalized.imageHeight = height;
39
+ }
40
+ else if (typeof height === 'string') {
41
+ const match = height.trim().match(regExp);
42
+ if (match) {
43
+ normalized.imageHeightPercent = Number(match[1]);
44
+ }
45
+ else {
46
+ throw new Error('imageSize.height percent string must be in format "0%" to "100%"');
47
+ }
48
+ }
49
+ }
21
50
  return normalized;
22
51
  }
23
52
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC,OAAO,sBAAsB,MAAM,0BAA0B,CAAA;AAwF7D,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAA;IAEnC,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,2BAA2B,CAAC,CAAA;IAE7D,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,eAAe,CAAC,MAA2B;IAClD,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAA;IAEvC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAA;IAEnC,MAAM,UAAU,GAAqB,EAAE,GAAG,IAAI,E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QAAE,OAAO,sBAAsB,CAAC,WAAW,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;AACnH,CAAC","sourcesContent":["import { EventSubscription } from 'expo-modules-core'\nimport { Platform } from 'react-native'\n\nimport ExpoLiveActivityModule from './ExpoLiveActivityModule'\n\ntype Voidable<T> = T | void\n\nexport type DynamicIslandTimerType = 'circular' | 'digital'\n\ntype ProgressBarType =\n | {\n date?: number\n progress?: undefined\n }\n | {\n date?: undefined\n progress?: number\n }\n\nexport type LiveActivityState = {\n title: string\n subtitle?: string\n progressBar?: ProgressBarType\n imageName?: string\n dynamicIslandImageName?: string\n}\n\nexport type NativeLiveActivityState = {\n title: string\n subtitle?: string\n date?: number\n progress?: number\n imageName?: string\n dynamicIslandImageName?: string\n}\n\nexport type Padding =\n | {\n top?: number\n bottom?: number\n left?: number\n right?: number\n vertical?: number\n horizontal?: number\n }\n | number\n\nexport type ImagePosition = 'left' | 'right' | 'leftStretch' | 'rightStretch'\n\nexport type ImageAlign = 'top' | 'center' | 'bottom'\n\nexport type ImageSize = number\n\nexport type LiveActivityConfig = {\n backgroundColor?: string\n titleColor?: string\n subtitleColor?: string\n progressViewTint?: string\n progressViewLabelColor?: string\n deepLinkUrl?: string\n timerType?: DynamicIslandTimerType\n padding?: Padding\n imagePosition?: ImagePosition\n imageAlign?: ImageAlign\n imageSize?: ImageSize\n}\n\nexport type ActivityTokenReceivedEvent = {\n activityID: string\n activityName: string\n activityPushToken: string\n}\n\nexport type ActivityPushToStartTokenReceivedEvent = {\n activityPushToStartToken: string\n}\n\ntype ActivityState = 'active' | 'dismissed' | 'pending' | 'stale' | 'ended'\n\nexport type ActivityUpdateEvent = {\n activityID: string\n activityName: string\n activityState: ActivityState\n}\n\nexport type LiveActivityModuleEvents = {\n onTokenReceived: (params: ActivityTokenReceivedEvent) => void\n onPushToStartTokenReceived: (params: ActivityPushToStartTokenReceivedEvent) => void\n onStateChange: (params: ActivityUpdateEvent) => void\n}\n\nfunction assertIOS(name: string) {\n const isIOS = Platform.OS === 'ios'\n\n if (!isIOS) console.error(`${name} is only available on iOS`)\n\n return isIOS\n}\n\nfunction normalizeConfig(config?: LiveActivityConfig) {\n if (config === undefined) return config\n\n const { padding, ...base } = config\n type NormalizedConfig = LiveActivityConfig & { paddingDetails?: Padding }\n const normalized: NormalizedConfig = { ...base }\n\n // Normalize padding: keep number in padding, object in paddingDetails\n if (typeof padding === 'number') {\n normalized.padding = padding\n } else if (typeof padding === 'object') {\n normalized.paddingDetails = padding\n }\n\n return normalized\n}\n\n/**\n * @param {LiveActivityState} state The state for the live activity.\n * @param {LiveActivityConfig} config Live activity config object.\n * @returns {string} The identifier of the started activity or undefined if creating live activity failed.\n */\nexport function startActivity(state: LiveActivityState, config?: LiveActivityConfig): Voidable<string> {\n if (assertIOS('startActivity')) return ExpoLiveActivityModule.startActivity(state, normalizeConfig(config))\n}\n\n/**\n * @param {string} id The identifier of the activity to stop.\n * @param {LiveActivityState} state The updated state for the live activity.\n */\nexport function stopActivity(id: string, state: LiveActivityState) {\n if (assertIOS('stopActivity')) return ExpoLiveActivityModule.stopActivity(id, state)\n}\n\n/**\n * @param {string} id The identifier of the activity to update.\n * @param {LiveActivityState} state The updated state for the live activity.\n */\nexport function updateActivity(id: string, state: LiveActivityState) {\n if (assertIOS('updateActivity')) return ExpoLiveActivityModule.updateActivity(id, state)\n}\n\nexport function addActivityTokenListener(\n listener: (event: ActivityTokenReceivedEvent) => void\n): Voidable<EventSubscription> {\n if (assertIOS('addActivityTokenListener')) return ExpoLiveActivityModule.addListener('onTokenReceived', listener)\n}\n\nexport function addActivityPushToStartTokenListener(\n listener: (event: ActivityPushToStartTokenReceivedEvent) => void\n): Voidable<EventSubscription> {\n if (assertIOS('addActivityPushToStartTokenListener'))\n return ExpoLiveActivityModule.addListener('onPushToStartTokenReceived', listener)\n}\n\nexport function addActivityUpdatesListener(\n listener: (event: ActivityUpdateEvent) => void\n): Voidable<EventSubscription> {\n if (assertIOS('addActivityUpdatesListener')) return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Ac,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;AAC1F,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,QAAqD;IAErD,IAAI,SAAS,CAAC,0BAA0B,CAAC;QAAE,OAAO,sBAAsB,CAAC,WAAW,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;AACnH,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,QAAgE;IAEhE,IAAI,SAAS,CAAC,qCAAqC,CAAC;QAClD,OAAO,sBAAsB,CAAC,WAAW,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAA;AACrF,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,QAA8C;IAE9C,IAAI,SAAS,CAAC,4BAA4B,CAAC;QAAE,OAAO,sBAAsB,CAAC,WAAW,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;AACnH,CAAC","sourcesContent":["import { EventSubscription } from 'expo-modules-core'\nimport { Platform } from 'react-native'\n\nimport ExpoLiveActivityModule from './ExpoLiveActivityModule'\n\ntype Voidable<T> = T | void\n\nexport type DynamicIslandTimerType = 'circular' | 'digital'\n\ntype ProgressBarType =\n | {\n date?: number\n progress?: undefined\n }\n | {\n date?: undefined\n progress?: number\n }\n\nexport type LiveActivityState = {\n title: string\n subtitle?: string\n progressBar?: ProgressBarType\n imageName?: string\n dynamicIslandImageName?: string\n}\n\nexport type NativeLiveActivityState = {\n title: string\n subtitle?: string\n date?: number\n progress?: number\n imageName?: string\n dynamicIslandImageName?: string\n}\n\nexport type Padding =\n | {\n top?: number\n bottom?: number\n left?: number\n right?: number\n vertical?: number\n horizontal?: number\n }\n | number\n\nexport type ImagePosition = 'left' | 'right' | 'leftStretch' | 'rightStretch'\n\nexport type ImageAlign = 'top' | 'center' | 'bottom'\n\nexport type ImageDimension = number | `${number}%`\nexport type ImageSize = {\n width: ImageDimension\n height: ImageDimension\n}\n\nexport type ImageContentFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down'\n\nexport type LiveActivityConfig = {\n backgroundColor?: string\n titleColor?: string\n subtitleColor?: string\n progressViewTint?: string\n progressViewLabelColor?: string\n deepLinkUrl?: string\n timerType?: DynamicIslandTimerType\n padding?: Padding\n imagePosition?: ImagePosition\n imageAlign?: ImageAlign\n imageSize?: ImageSize\n contentFit?: ImageContentFit\n}\n\nexport type ActivityTokenReceivedEvent = {\n activityID: string\n activityName: string\n activityPushToken: string\n}\n\nexport type ActivityPushToStartTokenReceivedEvent = {\n activityPushToStartToken: string\n}\n\ntype ActivityState = 'active' | 'dismissed' | 'pending' | 'stale' | 'ended'\n\nexport type ActivityUpdateEvent = {\n activityID: string\n activityName: string\n activityState: ActivityState\n}\n\nexport type LiveActivityModuleEvents = {\n onTokenReceived: (params: ActivityTokenReceivedEvent) => void\n onPushToStartTokenReceived: (params: ActivityPushToStartTokenReceivedEvent) => void\n onStateChange: (params: ActivityUpdateEvent) => void\n}\n\nfunction assertIOS(name: string) {\n const isIOS = Platform.OS === 'ios'\n\n if (!isIOS) console.error(`${name} is only available on iOS`)\n\n return isIOS\n}\n\nfunction normalizeConfig(config?: LiveActivityConfig) {\n if (config === undefined) return config\n\n const { padding, imageSize, ...base } = config\n type NormalizedConfig = LiveActivityConfig & {\n paddingDetails?: Padding\n imageWidth?: number\n imageHeight?: number\n imageWidthPercent?: number\n imageHeightPercent?: number\n }\n const normalized: NormalizedConfig = { ...base }\n\n // Normalize padding: keep number in padding, object in paddingDetails\n if (typeof padding === 'number') {\n normalized.padding = padding\n } else if (typeof padding === 'object') {\n normalized.paddingDetails = padding\n }\n\n // Normalize imageSize: object with width/height each a number (points) or percent string like '50%'\n if (imageSize) {\n const regExp = /^(100(?:\\.0+)?|\\d{1,2}(?:\\.\\d+)?)%$/ // Matches 0.0% to 100.0%\n\n const { width, height } = imageSize\n\n if (typeof width === 'number') {\n normalized.imageWidth = width\n } else if (typeof width === 'string') {\n const match = width.trim().match(regExp)\n if (match) {\n normalized.imageWidthPercent = Number(match[1])\n } else {\n throw new Error('imageSize.width percent string must be in format \"0%\" to \"100%\"')\n }\n }\n\n if (typeof height === 'number') {\n normalized.imageHeight = height\n } else if (typeof height === 'string') {\n const match = height.trim().match(regExp)\n if (match) {\n normalized.imageHeightPercent = Number(match[1])\n } else {\n throw new Error('imageSize.height percent string must be in format \"0%\" to \"100%\"')\n }\n }\n }\n\n return normalized\n}\n\n/**\n * @param {LiveActivityState} state The state for the live activity.\n * @param {LiveActivityConfig} config Live activity config object.\n * @returns {string} The identifier of the started activity or undefined if creating live activity failed.\n */\nexport function startActivity(state: LiveActivityState, config?: LiveActivityConfig): Voidable<string> {\n if (assertIOS('startActivity')) return ExpoLiveActivityModule.startActivity(state, normalizeConfig(config))\n}\n\n/**\n * @param {string} id The identifier of the activity to stop.\n * @param {LiveActivityState} state The updated state for the live activity.\n */\nexport function stopActivity(id: string, state: LiveActivityState) {\n if (assertIOS('stopActivity')) return ExpoLiveActivityModule.stopActivity(id, state)\n}\n\n/**\n * @param {string} id The identifier of the activity to update.\n * @param {LiveActivityState} state The updated state for the live activity.\n */\nexport function updateActivity(id: string, state: LiveActivityState) {\n if (assertIOS('updateActivity')) return ExpoLiveActivityModule.updateActivity(id, state)\n}\n\nexport function addActivityTokenListener(\n listener: (event: ActivityTokenReceivedEvent) => void\n): Voidable<EventSubscription> {\n if (assertIOS('addActivityTokenListener')) return ExpoLiveActivityModule.addListener('onTokenReceived', listener)\n}\n\nexport function addActivityPushToStartTokenListener(\n listener: (event: ActivityPushToStartTokenReceivedEvent) => void\n): Voidable<EventSubscription> {\n if (assertIOS('addActivityPushToStartTokenListener'))\n return ExpoLiveActivityModule.addListener('onPushToStartTokenReceived', listener)\n}\n\nexport function addActivityUpdatesListener(\n listener: (event: ActivityUpdateEvent) => void\n): Voidable<EventSubscription> {\n if (assertIOS('addActivityUpdatesListener')) return ExpoLiveActivityModule.addListener('onStateChange', listener)\n}\n"]}
@@ -59,11 +59,23 @@ public class ExpoLiveActivityModule: Module {
59
59
  var imagePosition: String?
60
60
 
61
61
  @Field
62
- var imageSize: Int?
62
+ var imageWidth: Int?
63
+
64
+ @Field
65
+ var imageHeight: Int?
66
+
67
+ @Field
68
+ var imageWidthPercent: Double?
69
+
70
+ @Field
71
+ var imageHeightPercent: Double?
63
72
 
64
73
  @Field
65
74
  var imageAlign: String?
66
75
 
76
+ @Field
77
+ var contentFit: String?
78
+
67
79
  struct PaddingDetails: Record {
68
80
  @Field var top: Int?
69
81
  @Field var bottom: Int?
@@ -225,8 +237,12 @@ public class ExpoLiveActivityModule: Module {
225
237
  )
226
238
  },
227
239
  imagePosition: config.imagePosition,
228
- imageSize: config.imageSize,
229
- imageAlign: config.imageAlign
240
+ imageWidth: config.imageWidth,
241
+ imageHeight: config.imageHeight,
242
+ imageWidthPercent: config.imageWidthPercent,
243
+ imageHeightPercent: config.imageHeightPercent,
244
+ imageAlign: config.imageAlign,
245
+ contentFit: config.contentFit
230
246
  )
231
247
 
232
248
  let initialState = LiveActivityAttributes.ContentState(
@@ -22,8 +22,12 @@ struct LiveActivityAttributes: ActivityAttributes {
22
22
  var padding: Int?
23
23
  var paddingDetails: PaddingDetails?
24
24
  var imagePosition: String?
25
- var imageSize: Int?
25
+ var imageWidth: Int?
26
+ var imageHeight: Int?
27
+ var imageWidthPercent: Double?
28
+ var imageHeightPercent: Double?
26
29
  var imageAlign: String?
30
+ var contentFit: String?
27
31
 
28
32
  enum DynamicIslandTimerType: String, Codable {
29
33
  case circular
@@ -1,4 +1,5 @@
1
1
  import SwiftUI
2
+ import UIKit
2
3
 
3
4
  extension Image {
4
5
  static func dynamic(assetNameOrPath: String) -> Self {
@@ -15,3 +16,18 @@ extension Image {
15
16
  return Image(assetNameOrPath)
16
17
  }
17
18
  }
19
+
20
+ extension UIImage {
21
+ /// Attempts to load a UIImage either from the shared app group container or the main bundle.
22
+ static func dynamic(assetNameOrPath: String) -> UIImage? {
23
+ if let container = FileManager.default.containerURL(
24
+ forSecurityApplicationGroupIdentifier: "group.expoLiveActivity.sharedData"
25
+ ) {
26
+ let contentsOfFile = container.appendingPathComponent(assetNameOrPath).path
27
+ if let uiImage = UIImage(contentsOfFile: contentsOfFile) {
28
+ return uiImage
29
+ }
30
+ }
31
+ return UIImage(named: assetNameOrPath)
32
+ }
33
+ }
@@ -15,9 +15,29 @@ import WidgetKit
15
15
  }
16
16
  }
17
17
 
18
+ struct DebugLog: View {
19
+ #if DEBUG
20
+ private let message: String
21
+ init(_ message: String) {
22
+ self.message = message
23
+ print(message)
24
+ }
25
+
26
+ var body: some View {
27
+ Text(message)
28
+ .font(.caption2)
29
+ .foregroundStyle(.red)
30
+ }
31
+ #else
32
+ init(_: String) {}
33
+ var body: some View { EmptyView() }
34
+ #endif
35
+ }
36
+
18
37
  struct LiveActivityView: View {
19
38
  let contentState: LiveActivityAttributes.ContentState
20
39
  let attributes: LiveActivityAttributes
40
+ @State private var imageContainerSize: CGSize?
21
41
 
22
42
  var progressViewTint: Color? {
23
43
  attributes.progressViewTint.map { Color(hex: $0) }
@@ -34,13 +54,100 @@ import WidgetKit
34
54
  }
35
55
  }
36
56
 
37
- @ViewBuilder
38
57
  private func alignedImage(imageName: String) -> some View {
39
- VStack {
40
- resizableImage(imageName: imageName)
41
- .applyImageSize(attributes.imageSize)
58
+ let defaultHeight: CGFloat = 64
59
+ let defaultWidth: CGFloat = 64
60
+ let containerHeight = imageContainerSize?.height
61
+ let containerWidth = imageContainerSize?.width
62
+ let hasWidthConstraint = (attributes.imageWidthPercent != nil) || (attributes.imageWidth != nil)
63
+
64
+ let computedHeight: CGFloat? = {
65
+ if let percent = attributes.imageHeightPercent {
66
+ let clamped = min(max(percent, 0), 100) / 100.0
67
+ // Use the row height as a base. Fallback to default when row height is not measured yet.
68
+ let base = (containerHeight ?? defaultHeight)
69
+ return base * clamped
70
+ } else if let size = attributes.imageHeight {
71
+ return CGFloat(size)
72
+ } else if hasWidthConstraint {
73
+ // Mimic CSS: when only width is set, keep height automatic to preserve aspect ratio
74
+ return nil
75
+ } else {
76
+ // Mimic CSS: this works against CSS but provides a better default behavior.
77
+ // When no width/height is set, use a default size (64pt)
78
+ // Width will adjust automatically base on aspect ratio
79
+ return defaultHeight
80
+ }
81
+ }()
82
+
83
+ let computedWidth: CGFloat? = {
84
+ if let percent = attributes.imageWidthPercent {
85
+ let clamped = min(max(percent, 0), 100) / 100.0
86
+ let base = (containerWidth ?? defaultWidth)
87
+ return base * clamped
88
+ } else if let size = attributes.imageWidth {
89
+ return CGFloat(size)
90
+ } else {
91
+ return nil // Keep aspect fit based on height
92
+ }
93
+ }()
94
+
95
+ return ZStack(alignment: .center) {
96
+ Group {
97
+ let fit = attributes.contentFit ?? "cover"
98
+ switch fit {
99
+ case "contain":
100
+ Image.dynamic(assetNameOrPath: imageName).resizable().scaledToFit().frame(width: computedWidth, height: computedHeight)
101
+ case "fill":
102
+ Image.dynamic(assetNameOrPath: imageName).resizable().frame(
103
+ width: computedWidth,
104
+ height: computedHeight
105
+ )
106
+ case "none":
107
+ Image.dynamic(assetNameOrPath: imageName).renderingMode(.original).frame(width: computedWidth, height: computedHeight)
108
+ case "scale-down":
109
+ if let uiImage = UIImage.dynamic(assetNameOrPath: imageName) {
110
+ // Determine the target box. When width/height are nil, we use image's intrinsic dimension for comparison.
111
+ let targetHeight = computedHeight ?? uiImage.size.height
112
+ let targetWidth = computedWidth ?? uiImage.size.width
113
+ let shouldScaleDown = uiImage.size.height > targetHeight || uiImage.size.width > targetWidth
114
+
115
+ if shouldScaleDown {
116
+ Image(uiImage: uiImage)
117
+ .resizable()
118
+ .scaledToFit()
119
+ .frame(width: computedWidth, height: computedHeight)
120
+ } else {
121
+ Image(uiImage: uiImage)
122
+ .renderingMode(.original)
123
+ .frame(width: min(uiImage.size.width, targetWidth), height: min(uiImage.size.height, targetHeight))
124
+ }
125
+ } else {
126
+ DebugLog("⚠️[ExpoLiveActivity] assetNameOrPath couldn't resolve to UIImage")
127
+ }
128
+ case "cover":
129
+ Image.dynamic(assetNameOrPath: imageName).resizable().scaledToFill().frame(
130
+ width: computedWidth,
131
+ height: computedHeight
132
+ ).clipped()
133
+ default:
134
+ DebugLog("⚠️[ExpoLiveActivity] Unknown contentFit '\(fit)'")
135
+ }
136
+ }
42
137
  }
43
- .frame(maxHeight: .infinity, alignment: imageAlignment)
138
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: imageAlignment)
139
+ .background(
140
+ GeometryReader { proxy in
141
+ Color.clear
142
+ .onAppear {
143
+ let s = proxy.size
144
+ if s.width > 0, s.height > 0 { imageContainerSize = s }
145
+ }
146
+ .onChange(of: proxy.size) { s in
147
+ if s.width > 0, s.height > 0 { imageContainerSize = s }
148
+ }
149
+ }
150
+ )
44
151
  }
45
152
 
46
153
  var body: some View {
@@ -80,6 +187,7 @@ import WidgetKit
80
187
  let isLeftImage = position.hasPrefix("left")
81
188
  let hasImage = contentState.imageName != nil
82
189
  let effectiveStretch = isStretch && hasImage
190
+
83
191
  HStack(alignment: .center) {
84
192
  if hasImage, isLeftImage {
85
193
  if let imageName = contentState.imageName {
@@ -110,7 +218,7 @@ import WidgetKit
110
218
  .modifier(ConditionalForegroundViewModifier(color: attributes.progressViewLabelColor))
111
219
  }
112
220
  }
113
- }
221
+ }.layoutPriority(1)
114
222
 
115
223
  if hasImage, !isLeftImage { // right side (default)
116
224
  Spacer()
@@ -121,7 +229,6 @@ import WidgetKit
121
229
  }
122
230
 
123
231
  if !effectiveStretch {
124
- // Bottom progress (hidden when using Stretch variants where progress is inline)
125
232
  if let date = contentState.timerEndDateInMilliseconds {
126
233
  ProgressView(timerInterval: Date.toTimerInterval(miliseconds: date))
127
234
  .tint(progressViewTint)
@@ -23,8 +23,12 @@ struct LiveActivityAttributes: ActivityAttributes {
23
23
  var padding: Int?
24
24
  var paddingDetails: PaddingDetails?
25
25
  var imagePosition: String?
26
- var imageSize: Int?
26
+ var imageWidth: Int?
27
+ var imageHeight: Int?
28
+ var imageWidthPercent: Double?
29
+ var imageHeightPercent: Double?
27
30
  var imageAlign: String?
31
+ var contentFit: String?
28
32
 
29
33
  enum DynamicIslandTimerType: String, Codable {
30
34
  case circular
@@ -140,7 +144,6 @@ struct LiveActivityWidget: Widget {
140
144
  VStack {
141
145
  Spacer()
142
146
  resizableImage(imageName: imageName)
143
- .frame(maxHeight: 64)
144
147
  Spacer()
145
148
  }
146
149
  }
@@ -6,9 +6,28 @@ func resizableImage(imageName: String) -> some View {
6
6
  .scaledToFit()
7
7
  }
8
8
 
9
+ func resizableImage(imageName: String, height: CGFloat?, width: CGFloat?) -> some View {
10
+ resizableImage(imageName: imageName)
11
+ .frame(width: width, height: height)
12
+ }
13
+
14
+ private struct ContainerSizeKey: PreferenceKey {
15
+ static var defaultValue: CGSize?
16
+ static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
17
+ value = nextValue() ?? value
18
+ }
19
+ }
20
+
9
21
  extension View {
10
- @ViewBuilder
11
- func applyImageSize(_ size: Int?) -> some View {
12
- frame(maxHeight: CGFloat(size ?? 64))
22
+ func captureContainerSize() -> some View {
23
+ background(
24
+ GeometryReader { proxy in
25
+ Color.clear.preference(key: ContainerSizeKey.self, value: proxy.size)
26
+ }
27
+ )
28
+ }
29
+
30
+ func onContainerSize(_ perform: @escaping (CGSize?) -> Void) -> some View {
31
+ onPreferenceChange(ContainerSizeKey.self, perform: perform)
13
32
  }
14
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-live-activity",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A module for adding Live Activity to a React Native app for iOS.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -3,8 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_plugins_1 = require("@expo/config-plugins");
4
4
  const withPlist = (expoConfig) => (0, config_plugins_1.withInfoPlist)(expoConfig, (plistConfig) => {
5
5
  const scheme = typeof expoConfig.scheme === 'string' ? expoConfig.scheme : expoConfig.ios?.bundleIdentifier;
6
- if (scheme)
7
- plistConfig.modResults.CFBundleURLTypes = [{ CFBundleURLSchemes: [scheme] }];
6
+ if (scheme) {
7
+ const existingURLTypes = plistConfig.modResults.CFBundleURLTypes || [];
8
+ const schemeExists = existingURLTypes.some((urlType) => urlType.CFBundleURLSchemes?.includes(scheme));
9
+ if (!schemeExists) {
10
+ plistConfig.modResults.CFBundleURLTypes = [...existingURLTypes, { CFBundleURLSchemes: [scheme] }];
11
+ }
12
+ }
8
13
  return plistConfig;
9
14
  });
10
15
  exports.default = withPlist;
@@ -3,7 +3,16 @@ import { ConfigPlugin, withInfoPlist } from '@expo/config-plugins'
3
3
  const withPlist: ConfigPlugin = (expoConfig) =>
4
4
  withInfoPlist(expoConfig, (plistConfig) => {
5
5
  const scheme = typeof expoConfig.scheme === 'string' ? expoConfig.scheme : expoConfig.ios?.bundleIdentifier
6
- if (scheme) plistConfig.modResults.CFBundleURLTypes = [{ CFBundleURLSchemes: [scheme] }]
6
+
7
+ if (scheme) {
8
+ const existingURLTypes = plistConfig.modResults.CFBundleURLTypes || []
9
+ const schemeExists = existingURLTypes.some((urlType: any) => urlType.CFBundleURLSchemes?.includes(scheme))
10
+
11
+ if (!schemeExists) {
12
+ plistConfig.modResults.CFBundleURLTypes = [...existingURLTypes, { CFBundleURLSchemes: [scheme] }]
13
+ }
14
+ }
15
+
7
16
  return plistConfig
8
17
  })
9
18
 
package/src/index.ts CHANGED
@@ -49,7 +49,13 @@ export type ImagePosition = 'left' | 'right' | 'leftStretch' | 'rightStretch'
49
49
 
50
50
  export type ImageAlign = 'top' | 'center' | 'bottom'
51
51
 
52
- export type ImageSize = number
52
+ export type ImageDimension = number | `${number}%`
53
+ export type ImageSize = {
54
+ width: ImageDimension
55
+ height: ImageDimension
56
+ }
57
+
58
+ export type ImageContentFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down'
53
59
 
54
60
  export type LiveActivityConfig = {
55
61
  backgroundColor?: string
@@ -63,6 +69,7 @@ export type LiveActivityConfig = {
63
69
  imagePosition?: ImagePosition
64
70
  imageAlign?: ImageAlign
65
71
  imageSize?: ImageSize
72
+ contentFit?: ImageContentFit
66
73
  }
67
74
 
68
75
  export type ActivityTokenReceivedEvent = {
@@ -100,8 +107,14 @@ function assertIOS(name: string) {
100
107
  function normalizeConfig(config?: LiveActivityConfig) {
101
108
  if (config === undefined) return config
102
109
 
103
- const { padding, ...base } = config
104
- type NormalizedConfig = LiveActivityConfig & { paddingDetails?: Padding }
110
+ const { padding, imageSize, ...base } = config
111
+ type NormalizedConfig = LiveActivityConfig & {
112
+ paddingDetails?: Padding
113
+ imageWidth?: number
114
+ imageHeight?: number
115
+ imageWidthPercent?: number
116
+ imageHeightPercent?: number
117
+ }
105
118
  const normalized: NormalizedConfig = { ...base }
106
119
 
107
120
  // Normalize padding: keep number in padding, object in paddingDetails
@@ -111,6 +124,35 @@ function normalizeConfig(config?: LiveActivityConfig) {
111
124
  normalized.paddingDetails = padding
112
125
  }
113
126
 
127
+ // Normalize imageSize: object with width/height each a number (points) or percent string like '50%'
128
+ if (imageSize) {
129
+ const regExp = /^(100(?:\.0+)?|\d{1,2}(?:\.\d+)?)%$/ // Matches 0.0% to 100.0%
130
+
131
+ const { width, height } = imageSize
132
+
133
+ if (typeof width === 'number') {
134
+ normalized.imageWidth = width
135
+ } else if (typeof width === 'string') {
136
+ const match = width.trim().match(regExp)
137
+ if (match) {
138
+ normalized.imageWidthPercent = Number(match[1])
139
+ } else {
140
+ throw new Error('imageSize.width percent string must be in format "0%" to "100%"')
141
+ }
142
+ }
143
+
144
+ if (typeof height === 'number') {
145
+ normalized.imageHeight = height
146
+ } else if (typeof height === 'string') {
147
+ const match = height.trim().match(regExp)
148
+ if (match) {
149
+ normalized.imageHeightPercent = Number(match[1])
150
+ } else {
151
+ throw new Error('imageSize.height percent string must be in format "0%" to "100%"')
152
+ }
153
+ }
154
+ }
155
+
114
156
  return normalized
115
157
  }
116
158