|
| 1 | +diff --git a/build/Widgets.types.d.ts b/build/Widgets.types.d.ts |
| 2 | +index 15e026868625ce20a3e359e5cc8e5c7e937c4650..dec7371d74e4f36998a1a170e4fc6557c0962b86 100644 |
| 3 | +--- a/build/Widgets.types.d.ts |
| 4 | ++++ b/build/Widgets.types.d.ts |
| 5 | +@@ -90,6 +90,8 @@ export type LiveActivityEnvironment = { |
| 6 | + * The color scheme of the activity's environment. |
| 7 | + */ |
| 8 | + colorScheme: 'light' | 'dark'; |
| 9 | ++ /** The rendering mode supplied by WidgetKit for this presentation. */ |
| 10 | ++ widgetRenderingMode?: WidgetRenderingMode; |
| 11 | + /** |
| 12 | + * Whether the activity is displayed in a context with reduced luminance. |
| 13 | + * @platform iOS 16+ |
| 14 | +diff --git a/ios/Widgets/Utils.swift b/ios/Widgets/Utils.swift |
| 15 | +index 2b4c044b597de7e0fab42dbc47af14d8bb521838..8ca92fdf4c15b0d4e217556da7e1aa0345662c79 100644 |
| 16 | +--- a/ios/Widgets/Utils.swift |
| 17 | ++++ b/ios/Widgets/Utils.swift |
| 18 | +@@ -91,6 +91,7 @@ func getLiveActivityEnvironment(for environment: EnvironmentValues, in context: |
| 19 | + "colorScheme": "\(environment.colorScheme)" |
| 20 | + ] |
| 21 | + |
| 22 | ++ env["widgetRenderingMode"] = environment.widgetRenderingMode.description |
| 23 | + env["isLuminanceReduced"] = environment.isLuminanceReduced |
| 24 | + env["isActivityFullscreen"] = environment.isActivityFullscreen |
| 25 | + if #available(iOS 16.2, *) { |
| 26 | +diff --git a/ios/Widgets/WidgetLiveActivity.swift b/ios/Widgets/WidgetLiveActivity.swift |
| 27 | +index 24d4571a52d3ebe9d785b5d049d8e134a149d513..7051c23b17ac91552e5b5c54606c57086c0ebbea 100644 |
| 28 | +--- a/ios/Widgets/WidgetLiveActivity.swift |
| 29 | ++++ b/ios/Widgets/WidgetLiveActivity.swift |
| 30 | +@@ -20,53 +20,41 @@ struct LiveActivityAttributes: ActivityAttributes { |
| 31 | + |
| 32 | + @available(iOS 16.1, *) |
| 33 | + public struct WidgetLiveActivity: Widget { |
| 34 | +- @Environment(\.self) var env |
| 35 | +- |
| 36 | + let widgetContext: AppContext = AppContext() |
| 37 | + |
| 38 | + public init() {} |
| 39 | + |
| 40 | + public var body: some WidgetConfiguration { |
| 41 | + ActivityConfiguration(for: LiveActivityAttributes.self) { context in |
| 42 | +- let nodes = getLiveActivityNodes( |
| 43 | +- forName: context.state.name, |
| 44 | +- props: context.state.props, |
| 45 | +- environment: getLiveActivityEnvironment(for: env, in: context) |
| 46 | +- ) |
| 47 | + // Only apply widgetURL when the activity has one: a hierarchy with more than one |
| 48 | + // widgetURL modifier is undefined behavior, and layouts can set their own through |
| 49 | + // the widgetURL modifier from @expo/ui. |
| 50 | +- let banner = LiveActivityBannerView(context: context, nodes: nodes) |
| 51 | ++ let banner = LiveActivityBannerView(context: context) |
| 52 | + if let url = context.attributes.url.flatMap(URL.init(string:)) { |
| 53 | + banner.widgetURL(url) |
| 54 | + } else { |
| 55 | + banner |
| 56 | + } |
| 57 | + } dynamicIsland: { context in |
| 58 | +- let nodes = getLiveActivityNodes( |
| 59 | +- forName: context.state.name, |
| 60 | +- props: context.state.props, |
| 61 | +- environment: getLiveActivityEnvironment(for: env, in: context) |
| 62 | +- ) |
| 63 | + let island = DynamicIsland { |
| 64 | + DynamicIslandExpandedRegion(.center) { |
| 65 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedCenter") |
| 66 | ++ LiveActivitySectionView(context: context, sectionName: "expandedCenter") |
| 67 | + } |
| 68 | + DynamicIslandExpandedRegion(.leading) { |
| 69 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedLeading") |
| 70 | ++ LiveActivitySectionView(context: context, sectionName: "expandedLeading") |
| 71 | + } |
| 72 | + DynamicIslandExpandedRegion(.trailing) { |
| 73 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedTrailing") |
| 74 | ++ LiveActivitySectionView(context: context, sectionName: "expandedTrailing") |
| 75 | + } |
| 76 | + DynamicIslandExpandedRegion(.bottom) { |
| 77 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedBottom") |
| 78 | ++ LiveActivitySectionView(context: context, sectionName: "expandedBottom") |
| 79 | + } |
| 80 | + } compactLeading: { |
| 81 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "compactLeading") |
| 82 | ++ LiveActivitySectionView(context: context, sectionName: "compactLeading") |
| 83 | + } compactTrailing: { |
| 84 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "compactTrailing") |
| 85 | ++ LiveActivitySectionView(context: context, sectionName: "compactTrailing") |
| 86 | + } minimal: { |
| 87 | +- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "minimal") |
| 88 | ++ LiveActivitySectionView(context: context, sectionName: "minimal") |
| 89 | + } |
| 90 | + if let url = context.attributes.url.flatMap(URL.init(string:)) { |
| 91 | + return island.widgetURL(url) |
| 92 | +@@ -79,11 +67,16 @@ public struct WidgetLiveActivity: Widget { |
| 93 | + |
| 94 | + @available(iOS 16.1, *) |
| 95 | + private struct LiveActivitySectionView: View { |
| 96 | ++ @Environment(\.self) var env |
| 97 | + let context: ActivityViewContext<LiveActivityAttributes> |
| 98 | +- let nodes: [String: Any] |
| 99 | + let sectionName: String |
| 100 | + |
| 101 | + var body: some View { |
| 102 | ++ let nodes = getLiveActivityNodes( |
| 103 | ++ forName: context.state.name, |
| 104 | ++ props: context.state.props, |
| 105 | ++ environment: getLiveActivityEnvironment(for: env, in: context) |
| 106 | ++ ) |
| 107 | + if let node = nodes[sectionName] as? [String: Any] { |
| 108 | + WidgetsDynamicView(name: context.activityID, kind: .liveActivity, node: node) |
| 109 | + } else { |
| 110 | +@@ -94,10 +87,17 @@ private struct LiveActivitySectionView: View { |
| 111 | + |
| 112 | + @available(iOS 16.1, *) |
| 113 | + private struct LiveActivityBannerView: View { |
| 114 | ++ // Read inside the rendered view: Widget-level values do not include the |
| 115 | ++ // presentation's color scheme, rendering mode, or reduced-luminance state. |
| 116 | ++ @Environment(\.self) var env |
| 117 | + var context: ActivityViewContext<LiveActivityAttributes> |
| 118 | +- let nodes: [String: Any] |
| 119 | + |
| 120 | + var body: some View { |
| 121 | ++ let nodes = getLiveActivityNodes( |
| 122 | ++ forName: context.state.name, |
| 123 | ++ props: context.state.props, |
| 124 | ++ environment: getLiveActivityEnvironment(for: env, in: context) |
| 125 | ++ ) |
| 126 | + if #available(iOS 18.0, *) { |
| 127 | + LiveActivityBanner(context: context, nodes: nodes) |
| 128 | + } else if let node = nodes["banner"] as? [String: Any] { |
| 129 | +diff --git a/src/Widgets.types.ts b/src/Widgets.types.ts |
| 130 | +index fee5c7475b52218fa0e192a1d347dd32cb0fe1f8..82bf68f631d3a5689064b5acc559d1fc5b4aef85 100644 |
| 131 | +--- a/src/Widgets.types.ts |
| 132 | ++++ b/src/Widgets.types.ts |
| 133 | +@@ -104,6 +104,8 @@ export type LiveActivityEnvironment = { |
| 134 | + * The color scheme of the activity's environment. |
| 135 | + */ |
| 136 | + colorScheme: 'light' | 'dark'; |
| 137 | ++ /** The rendering mode supplied by WidgetKit for this presentation. */ |
| 138 | ++ widgetRenderingMode?: WidgetRenderingMode; |
| 139 | + /** |
| 140 | + * Whether the activity is displayed in a context with reduced luminance. |
| 141 | + * @platform iOS 16+ |
0 commit comments