expo-widgets 58.0.16 → 58.0.18
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/CHANGELOG.md +16 -0
- package/android/build.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +6 -1
- package/android/src/main/java/expo/modules/widgets/ExpoWidgetEmittableTree.kt +7 -7
- package/android/src/main/java/expo/modules/widgets/ExpoWidgetsPeekWidget.kt +1 -1
- package/android/src/main/java/expo/modules/widgets/WidgetInteractionAction.kt +34 -4
- package/android/src/main/java/expo/modules/widgets/WidgetsEvents.kt +8 -4
- package/android/src/main/java/expo/modules/widgets/WidgetsModule.kt +45 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotification.kt +28 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotificationBuilder.kt +116 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotificationExceptions.kt +50 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotificationFactory.kt +36 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotificationOptions.kt +86 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotificationRenderer.kt +44 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotificationState.kt +65 -0
- package/android/src/main/java/expo/modules/widgets/notifications/CustomNotifications.kt +107 -0
- package/android/src/main/java/expo/modules/widgets/notifications/ExpoWidgetsNotificationReceiver.kt +67 -0
- package/android/src/main/res/values/expo_widgets_notifications.xml +4 -0
- package/build/CustomNotifications.d.ts +128 -0
- package/build/CustomNotifications.js +162 -0
- package/build/CustomNotifications.js.map +1 -0
- package/build/CustomNotifications.types.d.ts +124 -0
- package/build/CustomNotifications.types.js +3 -0
- package/build/CustomNotifications.types.js.map +1 -0
- package/build/ExpoWidgets.d.ts +3 -0
- package/build/ExpoWidgets.js +26 -0
- package/build/ExpoWidgets.js.map +1 -1
- package/build/ExpoWidgets.native.d.ts +5 -0
- package/build/ExpoWidgets.native.js.map +1 -1
- package/build/Widgets.d.ts +14 -0
- package/build/Widgets.js +14 -0
- package/build/Widgets.js.map +1 -1
- package/build/Widgets.types.d.ts +24 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/bundle/decorator.ts +13 -0
- package/bundle/index.ts +19 -2
- package/bundle/layout-registry-stub.ts +19 -0
- package/ios/ExpoWidgets.podspec +5 -7
- package/package.json +5 -5
- package/plugin/build/android/withAndroidNotificationPermission.d.ts +6 -0
- package/plugin/build/android/withAndroidNotificationPermission.js +31 -0
- package/plugin/build/android/withAndroidNotificationPermission.js.map +1 -0
- package/plugin/build/android/withAndroidWidgets.d.ts +4 -2
- package/plugin/build/android/withAndroidWidgets.js +6 -1
- package/plugin/build/android/withAndroidWidgets.js.map +1 -1
- package/plugin/build/withWidgets.js +1 -0
- package/plugin/build/withWidgets.js.map +1 -1
- package/plugin/src/android/withAndroidNotificationPermission.ts +22 -0
- package/plugin/src/android/withAndroidWidgets.ts +11 -1
- package/plugin/src/withWidgets.ts +2 -2
- package/src/CustomNotifications.ts +213 -0
- package/src/CustomNotifications.types.ts +138 -0
- package/src/ExpoWidgets.native.ts +8 -0
- package/src/ExpoWidgets.ts +41 -0
- package/src/Widgets.ts +14 -0
- package/src/Widgets.types.ts +24 -0
- package/src/index.ts +8 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["android/withAndroidWidgets.ts"],"sourcesContent":[null],"names":["withAndroidWidgets","config","widgets","length","androidWidgets","filter","widget","android","nextConfig","withAndroidWidgetFiles","withAndroidWidgetManifest"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["android/withAndroidWidgets.ts"],"sourcesContent":[null],"names":["withAndroidWidgets","config","props","widgets","withAndroidNotificationPermission","enablePushNotifications","length","androidWidgets","filter","widget","android","nextConfig","withAndroidWidgetFiles","withAndroidWidgetManifest"],"mappings":";;;;+BA8BA;;;eAAA;;;0FA3B8C;+EACX;kFACG;;;;;;AAOtC,MAAMA,qBAAwD,CAACC,QAAQC;IACrE,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpBD,SAASG,IAAAA,0CAAiC,EAACH,QAAQ;QACjDI,yBAAyBH,MAAMG,uBAAuB,IAAI;IAC5D;IACA,IAAIF,QAAQG,MAAM,KAAK,GAAG;QACxB,OAAOL;IACT;IAEA,MAAMM,iBAAiBJ,QAAQK,MAAM,CAAC,CAACC,SAAWA,OAAOC,OAAO,KAAK;IACrE,IAAIC,aAAaV;IACjB,IAAIM,eAAeD,MAAM,GAAG,GAAG;QAC7BK,aAAaC,IAAAA,+BAAsB,EAACD,YAAYJ;IAClD;IAEA,OAAOM,IAAAA,kCAAyB,EAACF,YAAYJ;AAC/C;MAEA,WAAeP"}
|
|
@@ -27,6 +27,7 @@ const withWidgets = (config, props)=>{
|
|
|
27
27
|
const enableAndroid = props?.enableAndroid ?? false;
|
|
28
28
|
const widgets = props?.widgets ?? [];
|
|
29
29
|
const nextConfig = enableAndroid ? (0, _withAndroidWidgets.default)(config, {
|
|
30
|
+
...props,
|
|
30
31
|
widgets
|
|
31
32
|
}) : config;
|
|
32
33
|
return (0, _withIosWidgets.default)(nextConfig, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["withWidgets.ts"],"sourcesContent":[null],"names":["pkg","require","withWidgets","config","props","enableAndroid","widgets","nextConfig","withAndroidWidgets","withIosWidgets","createRunOncePlugin","name","version"],"mappings":";;;;+BAiCA;;;eAAA;;;;yBAjCkD;;;;;;2EAEnB;uEACJ;;;;;;AAG3B,MAAMA,MAAMC,QAAQ;AAmBpB,MAAMC,cAAsE,CAACC,QAAQC;IACnF,MAAMC,gBAAgBD,OAAOC,iBAAiB;IAC9C,MAAMC,UAAUF,OAAOE,WAAW,EAAE;IAEpC,MAAMC,aAAaF,gBAAgBG,IAAAA,2BAAkB,EAACL,QAAQ;
|
|
1
|
+
{"version":3,"sources":["withWidgets.ts"],"sourcesContent":[null],"names":["pkg","require","withWidgets","config","props","enableAndroid","widgets","nextConfig","withAndroidWidgets","withIosWidgets","createRunOncePlugin","name","version"],"mappings":";;;;+BAiCA;;;eAAA;;;;yBAjCkD;;;;;;2EAEnB;uEACJ;;;;;;AAG3B,MAAMA,MAAMC,QAAQ;AAmBpB,MAAMC,cAAsE,CAACC,QAAQC;IACnF,MAAMC,gBAAgBD,OAAOC,iBAAiB;IAC9C,MAAMC,UAAUF,OAAOE,WAAW,EAAE;IAEpC,MAAMC,aAAaF,gBAAgBG,IAAAA,2BAAkB,EAACL,QAAQ;QAAE,GAAGC,KAAK;QAAEE;IAAQ,KAAKH;IACvF,OAAOM,IAAAA,uBAAc,EAACF,YAAY;QAAE,GAAGH,KAAK;QAAEE;IAAQ;AACxD;MAEA,WAAeI,IAAAA,oCAAmB,EAACR,aAAaF,IAAIW,IAAI,EAAEX,IAAIY,OAAO"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AndroidConfig, ConfigPlugin, withAndroidManifest } from 'expo/config-plugins';
|
|
2
|
+
|
|
3
|
+
type NotificationPermissionProps = {
|
|
4
|
+
enablePushNotifications: boolean;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const withAndroidNotificationPermission: ConfigPlugin<NotificationPermissionProps> = (
|
|
8
|
+
config,
|
|
9
|
+
props
|
|
10
|
+
) => {
|
|
11
|
+
if (!props.enablePushNotifications) {
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
return withAndroidManifest(config, (config) => {
|
|
15
|
+
AndroidConfig.Permissions.ensurePermissions(config.modResults, [
|
|
16
|
+
'android.permission.POST_NOTIFICATIONS',
|
|
17
|
+
]);
|
|
18
|
+
return config;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default withAndroidNotificationPermission;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { ConfigPlugin } from 'expo/config-plugins';
|
|
2
2
|
|
|
3
3
|
import { WidgetConfig } from '../types/WidgetConfig.type';
|
|
4
|
+
import withAndroidNotificationPermission from './withAndroidNotificationPermission';
|
|
4
5
|
import withAndroidWidgetFiles from './withAndroidWidgetFiles';
|
|
5
6
|
import withAndroidWidgetManifest from './withAndroidWidgetManifest';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
type AndroidWidgetsProps = {
|
|
9
|
+
enablePushNotifications?: boolean;
|
|
10
|
+
widgets: WidgetConfig[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const withAndroidWidgets: ConfigPlugin<AndroidWidgetsProps> = (config, props) => {
|
|
14
|
+
const { widgets } = props;
|
|
15
|
+
config = withAndroidNotificationPermission(config, {
|
|
16
|
+
enablePushNotifications: props.enablePushNotifications ?? false,
|
|
17
|
+
});
|
|
8
18
|
if (widgets.length === 0) {
|
|
9
19
|
return config;
|
|
10
20
|
}
|
|
@@ -11,7 +11,7 @@ export type ExpoWidgetsConfigPluginProps = {
|
|
|
11
11
|
bundleIdentifier?: string;
|
|
12
12
|
// App group identifier used for communication between the main app and widgets. Defaults to `group.<main app bundle identifier>`.
|
|
13
13
|
groupIdentifier?: string;
|
|
14
|
-
// Enable push notifications for
|
|
14
|
+
// Enable push notifications for Live Activities and custom notifications. Defaults to false.
|
|
15
15
|
enablePushNotifications?: boolean;
|
|
16
16
|
// Enable frequent updates for widgets. Defaults to false.
|
|
17
17
|
frequentUpdates?: boolean;
|
|
@@ -27,7 +27,7 @@ const withWidgets: ConfigPlugin<ExpoWidgetsConfigPluginProps | undefined> = (con
|
|
|
27
27
|
const enableAndroid = props?.enableAndroid ?? false;
|
|
28
28
|
const widgets = props?.widgets ?? [];
|
|
29
29
|
|
|
30
|
-
const nextConfig = enableAndroid ? withAndroidWidgets(config, { widgets }) : config;
|
|
30
|
+
const nextConfig = enableAndroid ? withAndroidWidgets(config, { ...props, widgets }) : config;
|
|
31
31
|
return withIosWidgets(nextConfig, { ...props, widgets });
|
|
32
32
|
};
|
|
33
33
|
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { UnavailabilityError, uuid } from 'expo';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
CustomNotificationComponent,
|
|
6
|
+
CustomNotificationOptions,
|
|
7
|
+
CustomNotificationUpdateOptions,
|
|
8
|
+
NativeCustomNotification,
|
|
9
|
+
NativeCustomNotificationFactory,
|
|
10
|
+
} from './CustomNotifications.types';
|
|
11
|
+
import ExpoWidgetsModule from './ExpoWidgets';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A posted custom notification. It wraps a native object that knows the notification key, so an
|
|
15
|
+
* instance recovered with `CustomNotificationFactory.get()` or `getActive()` after a process restart
|
|
16
|
+
* behaves like the one returned by `post()`.
|
|
17
|
+
* @platform android
|
|
18
|
+
*/
|
|
19
|
+
export class CustomNotification<T extends object = object> {
|
|
20
|
+
/** @hidden */
|
|
21
|
+
private readonly nativeNotification: NativeCustomNotification;
|
|
22
|
+
|
|
23
|
+
/** @hidden */
|
|
24
|
+
constructor(nativeNotification: NativeCustomNotification) {
|
|
25
|
+
this.nativeNotification = nativeNotification;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The key of the notification, as passed to or generated by `post()`.
|
|
30
|
+
* @platform android
|
|
31
|
+
*/
|
|
32
|
+
get id(): string {
|
|
33
|
+
return this.nativeNotification.getId();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reads the props currently shown by the notification from the active notification, so they
|
|
38
|
+
* include changes made by button presses inside the notification.
|
|
39
|
+
*
|
|
40
|
+
* Rejects when the notification is no longer active, for example after dismissal or cancellation.
|
|
41
|
+
* @returns A promise that resolves to the current props.
|
|
42
|
+
* @platform android
|
|
43
|
+
*/
|
|
44
|
+
async getProps(): Promise<T> {
|
|
45
|
+
return (await this.nativeNotification.getProps()) as T;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Renders the layout with new props and replaces the notification in place. The notification
|
|
50
|
+
* does not alert again when `alertOnlyOnce` is `true`.
|
|
51
|
+
*
|
|
52
|
+
* Rejects when the notification is no longer active, for example after the user dismissed it or
|
|
53
|
+
* after `cancel()`. Post it again in that case. Also rejects when the notification is canceled
|
|
54
|
+
* while the update renders, or for the same reasons as `post()`, such as an invalid `color`.
|
|
55
|
+
* @param props The new props for the layout function.
|
|
56
|
+
* @param options Presentation options to change. Options that are omitted keep their previous value.
|
|
57
|
+
* @platform android
|
|
58
|
+
*/
|
|
59
|
+
update(props: T, options: CustomNotificationUpdateOptions = {}): Promise<void> {
|
|
60
|
+
return this.nativeNotification.update(props as Record<string, any>, toNativeOptions(options));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Removes the notification from the shade immediately.
|
|
65
|
+
* Cancels any pending post or update for this notification.
|
|
66
|
+
* @platform android
|
|
67
|
+
*/
|
|
68
|
+
cancel(): Promise<void> {
|
|
69
|
+
return this.nativeNotification.cancel();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Posts and manages custom notifications that share one layout.
|
|
75
|
+
* @platform android
|
|
76
|
+
*/
|
|
77
|
+
export class CustomNotificationFactory<T extends object = object> {
|
|
78
|
+
/**
|
|
79
|
+
* The name passed to `createCustomNotification()`.
|
|
80
|
+
* @platform android
|
|
81
|
+
*/
|
|
82
|
+
readonly name: string;
|
|
83
|
+
/** @hidden */
|
|
84
|
+
private readonly nativeFactory: NativeCustomNotificationFactory | null;
|
|
85
|
+
|
|
86
|
+
/** @hidden */
|
|
87
|
+
constructor(name: string, layout: CustomNotificationComponent<T>) {
|
|
88
|
+
this.name = name;
|
|
89
|
+
this.nativeFactory =
|
|
90
|
+
Platform.OS === 'android'
|
|
91
|
+
? new ExpoWidgetsModule.CustomNotificationFactory(name, layout as unknown as string)
|
|
92
|
+
: null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Renders the layout and posts the notification. Posting with the `id` of an active notification
|
|
97
|
+
* replaces that notification in place.
|
|
98
|
+
*
|
|
99
|
+
* Rejects in these cases:
|
|
100
|
+
* - Notifications are disabled for the app.
|
|
101
|
+
* - `channelId` names a channel that does not exist.
|
|
102
|
+
* - `smallIcon` names a drawable that does not exist.
|
|
103
|
+
* - `color` is not in `#RRGGBB` or `#AARRGGBB` format.
|
|
104
|
+
* - The layout returns no `collapsed` section.
|
|
105
|
+
* - The post is canceled before rendering finishes.
|
|
106
|
+
* @param props The props for the layout function.
|
|
107
|
+
* @param options Presentation options.
|
|
108
|
+
* @returns A promise that resolves to a handle for the posted notification.
|
|
109
|
+
* @platform android
|
|
110
|
+
*/
|
|
111
|
+
async post(props: T, options: CustomNotificationOptions = {}): Promise<CustomNotification<T>> {
|
|
112
|
+
const nativeFactory = this.requireNativeFactory('post');
|
|
113
|
+
const id = options.id ?? uuid.v4();
|
|
114
|
+
const nativeNotification = await nativeFactory.post(
|
|
115
|
+
id,
|
|
116
|
+
props as Record<string, any>,
|
|
117
|
+
toNativeOptions({
|
|
118
|
+
...options,
|
|
119
|
+
ongoing: options.ongoing ?? false,
|
|
120
|
+
alertOnlyOnce: options.alertOnlyOnce ?? true,
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
return new CustomNotification<T>(nativeNotification);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Returns the active notification with the given key.
|
|
128
|
+
* @param id The key passed to or generated by `post()`.
|
|
129
|
+
* @returns A promise that resolves to the notification, or to `null` when no such notification is active.
|
|
130
|
+
* @platform android
|
|
131
|
+
*/
|
|
132
|
+
async get(id: string): Promise<CustomNotification<T> | null> {
|
|
133
|
+
const nativeNotification = await this.requireNativeFactory('get').get(id);
|
|
134
|
+
return nativeNotification ? new CustomNotification<T>(nativeNotification) : null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Returns every active notification posted with this layout, including notifications posted
|
|
139
|
+
* before a process restart.
|
|
140
|
+
* @platform android
|
|
141
|
+
*/
|
|
142
|
+
async getActive(): Promise<CustomNotification<T>[]> {
|
|
143
|
+
const nativeNotifications = await this.requireNativeFactory('getActive').getActive();
|
|
144
|
+
return nativeNotifications.map(
|
|
145
|
+
(nativeNotification) => new CustomNotification<T>(nativeNotification)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Removes every active notification posted with this layout and cancels pending posts and updates.
|
|
151
|
+
* @platform android
|
|
152
|
+
*/
|
|
153
|
+
async cancelAll(): Promise<void> {
|
|
154
|
+
await this.requireNativeFactory('cancelAll').cancelAll();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private requireNativeFactory(methodName: string): NativeCustomNotificationFactory {
|
|
158
|
+
if (!this.nativeFactory) {
|
|
159
|
+
throw new UnavailabilityError('ExpoWidgets', `CustomNotificationFactory.${methodName}`);
|
|
160
|
+
}
|
|
161
|
+
return this.nativeFactory;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Creates a factory that posts notifications rendered from the given layout.
|
|
167
|
+
*
|
|
168
|
+
* The factory can be created on every platform. Its methods reject with `UnavailabilityError` on
|
|
169
|
+
* platforms other than Android.
|
|
170
|
+
* @param name A unique name for the layout. It identifies the layout when a notification button
|
|
171
|
+
* is pressed and when active notifications are recovered.
|
|
172
|
+
* @param layout The layout component, marked with the `'widget'` directive.
|
|
173
|
+
* @example
|
|
174
|
+
* ```tsx
|
|
175
|
+
* import { Row, Text } from '@expo/ui/jetpack-compose';
|
|
176
|
+
* import { createCustomNotification } from 'expo-widgets';
|
|
177
|
+
*
|
|
178
|
+
* type Props = { status: string };
|
|
179
|
+
*
|
|
180
|
+
* const OrderNotification = createCustomNotification('OrderNotification', (props: Props) => {
|
|
181
|
+
* 'widget';
|
|
182
|
+
* return {
|
|
183
|
+
* collapsed: (
|
|
184
|
+
* <Row>
|
|
185
|
+
* <Text>{props.status}</Text>
|
|
186
|
+
* </Row>
|
|
187
|
+
* ),
|
|
188
|
+
* };
|
|
189
|
+
* });
|
|
190
|
+
*
|
|
191
|
+
* const order = await OrderNotification.post({ status: 'Preparing' }, { id: 'order-1', ongoing: true });
|
|
192
|
+
* await order.update({ status: 'Delivered' }, { ongoing: false, timeoutAfter: 15 * 60 * 1000 });
|
|
193
|
+
* ```
|
|
194
|
+
* @platform android
|
|
195
|
+
*/
|
|
196
|
+
export function createCustomNotification<T extends object = object>(
|
|
197
|
+
name: string,
|
|
198
|
+
layout: CustomNotificationComponent<T>
|
|
199
|
+
): CustomNotificationFactory<T> {
|
|
200
|
+
return new CustomNotificationFactory<T>(name, layout);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Strip omitted values so native updates preserve the previous options.
|
|
204
|
+
function toNativeOptions(options: CustomNotificationOptions): CustomNotificationUpdateOptions {
|
|
205
|
+
const { id: _id, ongoing, autoCancel, ...rest } = options;
|
|
206
|
+
return Object.fromEntries(
|
|
207
|
+
Object.entries({
|
|
208
|
+
...rest,
|
|
209
|
+
ongoing,
|
|
210
|
+
autoCancel: autoCancel ?? (ongoing === undefined ? undefined : !ongoing),
|
|
211
|
+
}).filter(([, value]) => value !== undefined)
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { SharedObject } from 'expo';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The views of a custom notification. Each section is rendered into its own `RemoteViews` at a
|
|
6
|
+
* fixed size, so a section cannot depend on the size of another section.
|
|
7
|
+
* @platform android
|
|
8
|
+
*/
|
|
9
|
+
export type CustomNotificationLayout = {
|
|
10
|
+
/**
|
|
11
|
+
* The collapsed row shown in the notification shade. The system gives it about 64
|
|
12
|
+
* density-independent pixels (dp) of height.
|
|
13
|
+
*/
|
|
14
|
+
collapsed: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* The expanded view shown when the user expands the notification. The system gives it up to
|
|
17
|
+
* 256 dp of height. When omitted, the system derives the expanded view from `collapsed`.
|
|
18
|
+
*/
|
|
19
|
+
expanded?: ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* The heads-up view shown when the notification peeks over the current screen. The system gives
|
|
22
|
+
* it about 88 dp of height. When omitted, the system reuses `collapsed`. The channel importance
|
|
23
|
+
* decides whether a heads-up view is shown at all.
|
|
24
|
+
*/
|
|
25
|
+
headsUp?: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Values the system provides to a custom notification layout.
|
|
30
|
+
* @platform android
|
|
31
|
+
*/
|
|
32
|
+
export type CustomNotificationEnvironment = {
|
|
33
|
+
/**
|
|
34
|
+
* The color scheme of the device at render time.
|
|
35
|
+
*/
|
|
36
|
+
colorScheme: 'light' | 'dark';
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A function that returns the views of a custom notification. It must start with the `'widget'`
|
|
41
|
+
* directive and use `@expo/ui/jetpack-compose` components.
|
|
42
|
+
* @platform android
|
|
43
|
+
*/
|
|
44
|
+
export type CustomNotificationComponent<T extends object = object> = (
|
|
45
|
+
props: T,
|
|
46
|
+
environment: CustomNotificationEnvironment
|
|
47
|
+
) => CustomNotificationLayout;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Presentation options of a custom notification.
|
|
51
|
+
* @platform android
|
|
52
|
+
*/
|
|
53
|
+
export type CustomNotificationOptions = {
|
|
54
|
+
/**
|
|
55
|
+
* The key of the notification. Posting with the key of an active notification replaces that
|
|
56
|
+
* notification in place. Defaults to a random UUID.
|
|
57
|
+
*/
|
|
58
|
+
id?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The notification channel the notification is posted to. The channel must exist, for example,
|
|
61
|
+
* one created with `expo-notifications`. Defaults to a low-importance channel with the ID
|
|
62
|
+
* `expo_widgets_notifications`, which `expo-widgets` creates on first use. The system settings
|
|
63
|
+
* list it as "Notifications".
|
|
64
|
+
*/
|
|
65
|
+
channelId?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The content title. Screen readers announce it, and the system uses it when it cannot show the
|
|
68
|
+
* custom views.
|
|
69
|
+
*/
|
|
70
|
+
title?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The content text. The system uses it when it cannot show the custom views.
|
|
73
|
+
*/
|
|
74
|
+
text?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the user cannot dismiss the notification with a swipe.
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
ongoing?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Whether a tap removes the notification. Defaults to the opposite of `ongoing`.
|
|
82
|
+
*/
|
|
83
|
+
autoCancel?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether sound, vibration, and the heads-up view are used only for the first post and not for
|
|
86
|
+
* updates.
|
|
87
|
+
* @default true
|
|
88
|
+
*/
|
|
89
|
+
alertOnlyOnce?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Time in milliseconds after which the system removes the notification. Useful after a final
|
|
92
|
+
* update that sets `ongoing` to `false`.
|
|
93
|
+
*/
|
|
94
|
+
timeoutAfter?: number;
|
|
95
|
+
/**
|
|
96
|
+
* A deep link opened in this app when the user taps the notification. Defaults to the launch
|
|
97
|
+
* intent of the app.
|
|
98
|
+
*/
|
|
99
|
+
url?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The name of a drawable resource used as the small icon. Defaults to the icon configured by
|
|
102
|
+
* the `expo-notifications` config plugin, and then to the app icon.
|
|
103
|
+
*/
|
|
104
|
+
smallIcon?: string;
|
|
105
|
+
/**
|
|
106
|
+
* The accent color in `#RRGGBB` or `#AARRGGBB` format. Defaults to the color configured by the
|
|
107
|
+
* `expo-notifications` config plugin.
|
|
108
|
+
*/
|
|
109
|
+
color?: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Presentation options that an update can override. Options that an update omits keep the value
|
|
114
|
+
* from the previous post or update.
|
|
115
|
+
* @platform android
|
|
116
|
+
*/
|
|
117
|
+
export type CustomNotificationUpdateOptions = Omit<CustomNotificationOptions, 'id'>;
|
|
118
|
+
|
|
119
|
+
/** @hidden */
|
|
120
|
+
export declare class NativeCustomNotification extends SharedObject {
|
|
121
|
+
getId(): string;
|
|
122
|
+
getProps(): Promise<Record<string, any>>;
|
|
123
|
+
update(props: Record<string, any>, options: CustomNotificationUpdateOptions): Promise<void>;
|
|
124
|
+
cancel(): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @hidden */
|
|
128
|
+
export declare class NativeCustomNotificationFactory extends SharedObject {
|
|
129
|
+
constructor(name: string, layout: string);
|
|
130
|
+
post(
|
|
131
|
+
id: string,
|
|
132
|
+
props: Record<string, any>,
|
|
133
|
+
options: CustomNotificationUpdateOptions
|
|
134
|
+
): Promise<NativeCustomNotification>;
|
|
135
|
+
get(id: string): Promise<NativeCustomNotification | null>;
|
|
136
|
+
getActive(): Promise<NativeCustomNotification[]>;
|
|
137
|
+
cancelAll(): Promise<void>;
|
|
138
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { NativeModule, requireNativeModule } from 'expo';
|
|
2
2
|
|
|
3
|
+
import type {
|
|
4
|
+
NativeCustomNotification,
|
|
5
|
+
NativeCustomNotificationFactory,
|
|
6
|
+
} from './CustomNotifications.types';
|
|
3
7
|
import type {
|
|
4
8
|
ExpoWidgetsEvents,
|
|
5
9
|
NativeLiveActivity,
|
|
@@ -11,8 +15,12 @@ declare class ExpoWidgetsModule extends NativeModule<ExpoWidgetsEvents> {
|
|
|
11
15
|
widgetsDirectory: string;
|
|
12
16
|
reloadAllWidgets(): void;
|
|
13
17
|
readonly Widget: typeof NativeWidgetObject;
|
|
18
|
+
/** iOS only. */
|
|
14
19
|
readonly LiveActivityFactory: typeof NativeLiveActivityFactory;
|
|
15
20
|
readonly LiveActivity: typeof NativeLiveActivity;
|
|
21
|
+
/** Android only. */
|
|
22
|
+
readonly CustomNotificationFactory: typeof NativeCustomNotificationFactory;
|
|
23
|
+
readonly CustomNotification: typeof NativeCustomNotification;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
export default requireNativeModule<ExpoWidgetsModule>('ExpoWidgets');
|
package/src/ExpoWidgets.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { EventSubscription } from 'expo';
|
|
2
2
|
|
|
3
|
+
import type {
|
|
4
|
+
CustomNotificationUpdateOptions,
|
|
5
|
+
NativeCustomNotification,
|
|
6
|
+
NativeCustomNotificationFactory,
|
|
7
|
+
} from './CustomNotifications.types';
|
|
3
8
|
import type {
|
|
4
9
|
ExpoTimelineEntry,
|
|
5
10
|
ExpoWidgetsEvents,
|
|
@@ -56,12 +61,48 @@ class LiveActivityFactoryStub {
|
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
|
|
64
|
+
class CustomNotificationStub {
|
|
65
|
+
getId(): string {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
async getProps(): Promise<Record<string, any>> {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
async update(
|
|
72
|
+
_props: Record<string, any>,
|
|
73
|
+
_options: CustomNotificationUpdateOptions
|
|
74
|
+
): Promise<void> {}
|
|
75
|
+
async cancel(): Promise<void> {}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
class CustomNotificationFactoryStub {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
80
|
+
constructor(_name: string, _layout: string) {}
|
|
81
|
+
async post(
|
|
82
|
+
_id: string,
|
|
83
|
+
_props: Record<string, any>,
|
|
84
|
+
_options: CustomNotificationUpdateOptions
|
|
85
|
+
): Promise<NativeCustomNotification> {
|
|
86
|
+
return new CustomNotificationStub() as unknown as NativeCustomNotification;
|
|
87
|
+
}
|
|
88
|
+
async get(_id: string): Promise<NativeCustomNotification | null> {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
async getActive(): Promise<NativeCustomNotification[]> {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
async cancelAll(): Promise<void> {}
|
|
95
|
+
}
|
|
96
|
+
|
|
59
97
|
const ExpoWidgetsModule = {
|
|
60
98
|
widgetsDirectory: '',
|
|
61
99
|
reloadAllWidgets(): void {},
|
|
62
100
|
Widget: WidgetStub as typeof NativeWidgetObject,
|
|
63
101
|
LiveActivityFactory: LiveActivityFactoryStub as typeof NativeLiveActivityFactory,
|
|
64
102
|
LiveActivity: LiveActivityStub as typeof NativeLiveActivity,
|
|
103
|
+
CustomNotificationFactory:
|
|
104
|
+
CustomNotificationFactoryStub as typeof NativeCustomNotificationFactory,
|
|
105
|
+
CustomNotification: CustomNotificationStub as typeof NativeCustomNotification,
|
|
65
106
|
addListener<EventName extends keyof ExpoWidgetsEvents>(
|
|
66
107
|
_eventName: EventName,
|
|
67
108
|
_listener: ExpoWidgetsEvents[EventName]
|
package/src/Widgets.ts
CHANGED
|
@@ -49,6 +49,7 @@ export class Widget<
|
|
|
49
49
|
/**
|
|
50
50
|
* Schedules a series of updates for the widget's content and reloads the widget.
|
|
51
51
|
* @param entries Timeline entries, each specifying a date and the props to display at that time.
|
|
52
|
+
* @platform ios
|
|
52
53
|
*/
|
|
53
54
|
updateTimeline(entries: WidgetTimelineEntry<PropsType>[]) {
|
|
54
55
|
if (Platform.OS === 'android') {
|
|
@@ -73,6 +74,7 @@ export class Widget<
|
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
76
|
* Returns the current timeline entries for the widget, including past and future entries.
|
|
77
|
+
* @platform ios
|
|
76
78
|
*/
|
|
77
79
|
async getTimeline(): Promise<WidgetTimelineEntry<PropsType>[]> {
|
|
78
80
|
return (await this.nativeWidgetObject.getTimeline()).map((entry) => ({
|
|
@@ -84,6 +86,7 @@ export class Widget<
|
|
|
84
86
|
/**
|
|
85
87
|
* Replaces the runtime options for a dynamic enum configuration parameter.
|
|
86
88
|
* The app config values remain the fallback when no runtime options are set.
|
|
89
|
+
* @platform ios
|
|
87
90
|
*/
|
|
88
91
|
setConfigurationParameterEnum(
|
|
89
92
|
parameterName: keyof ConfigurationType & string,
|
|
@@ -95,6 +98,7 @@ export class Widget<
|
|
|
95
98
|
|
|
96
99
|
/**
|
|
97
100
|
* Represents a Live Activity instance. Provides methods to update its content and end it.
|
|
101
|
+
* @platform ios
|
|
98
102
|
*/
|
|
99
103
|
export class LiveActivity<T extends object = object> {
|
|
100
104
|
/** @hidden */
|
|
@@ -105,6 +109,7 @@ export class LiveActivity<T extends object = object> {
|
|
|
105
109
|
|
|
106
110
|
/**
|
|
107
111
|
* Returns the stable ActivityKit identifier for this Live Activity.
|
|
112
|
+
* @platform ios
|
|
108
113
|
*/
|
|
109
114
|
getId(): string {
|
|
110
115
|
return this.nativeLiveActivity.getId();
|
|
@@ -114,6 +119,7 @@ export class LiveActivity<T extends object = object> {
|
|
|
114
119
|
* Updates the Live Activity's content. The UI reflects the new properties immediately.
|
|
115
120
|
* @param props The updated content properties.
|
|
116
121
|
* @param staleDate When set, the system may de-emphasize the activity after this date if content has not been refreshed.
|
|
122
|
+
* @platform ios
|
|
117
123
|
*/
|
|
118
124
|
update(props: T, staleDate?: Date): Promise<void> {
|
|
119
125
|
return this.nativeLiveActivity.update(JSON.stringify(props), staleDate?.getTime());
|
|
@@ -125,6 +131,7 @@ export class LiveActivity<T extends object = object> {
|
|
|
125
131
|
* Can be `'default'`, `'immediate'`, or `after(date)`.
|
|
126
132
|
* @param props Final content properties to update after the activity ends.
|
|
127
133
|
* @param contentDate The time the data in the payload was generated. If this is older than a previous update or push payload, the system ignores this update.
|
|
134
|
+
* @platform ios
|
|
128
135
|
*/
|
|
129
136
|
end(dismissalPolicy?: LiveActivityDismissalPolicy, props?: T, contentDate?: Date): Promise<void> {
|
|
130
137
|
const serializedProps = props ? JSON.stringify(props) : undefined;
|
|
@@ -151,6 +158,7 @@ export class LiveActivity<T extends object = object> {
|
|
|
151
158
|
/**
|
|
152
159
|
* Returns the push token for this Live Activity, used to send push notification updates via APNs.
|
|
153
160
|
* Returns `null` if push notifications are not enabled or the token is not yet available.
|
|
161
|
+
* @platform ios
|
|
154
162
|
*/
|
|
155
163
|
getPushToken(): Promise<string | null> {
|
|
156
164
|
return this.nativeLiveActivity.getPushToken();
|
|
@@ -161,6 +169,7 @@ export class LiveActivity<T extends object = object> {
|
|
|
161
169
|
* The token can be used to send content updates to this specific activity via APNs.
|
|
162
170
|
* @param listener Callback invoked when a new push token is available.
|
|
163
171
|
* @returns An event subscription that can be used to remove the listener.
|
|
172
|
+
* @platform ios
|
|
164
173
|
*/
|
|
165
174
|
addPushTokenListener(listener: (event: PushTokenEvent) => void): EventSubscription {
|
|
166
175
|
return this.nativeLiveActivity.addListener('onExpoWidgetsTokenReceived', listener);
|
|
@@ -169,6 +178,7 @@ export class LiveActivity<T extends object = object> {
|
|
|
169
178
|
|
|
170
179
|
/**
|
|
171
180
|
* Manages Live Activity instances of a specific type. Use it to start new activities and retrieve currently active ones.
|
|
181
|
+
* @platform ios
|
|
172
182
|
*/
|
|
173
183
|
export class LiveActivityFactory<T extends object = object> {
|
|
174
184
|
/** @hidden */
|
|
@@ -186,6 +196,7 @@ export class LiveActivityFactory<T extends object = object> {
|
|
|
186
196
|
* @param url An optional URL to associate with the Live Activity, used for deep linking.
|
|
187
197
|
* @param staleDate When set, the system may de-emphasize the activity after this date if content has not been refreshed.
|
|
188
198
|
* @returns The new Live Activity instance.
|
|
199
|
+
* @platform ios
|
|
189
200
|
*/
|
|
190
201
|
start(props: T, url?: string, staleDate?: Date) {
|
|
191
202
|
return new LiveActivity<T>(
|
|
@@ -195,6 +206,7 @@ export class LiveActivityFactory<T extends object = object> {
|
|
|
195
206
|
|
|
196
207
|
/**
|
|
197
208
|
* Returns all currently active instances of this Live Activity type.
|
|
209
|
+
* @platform ios
|
|
198
210
|
*/
|
|
199
211
|
getInstances() {
|
|
200
212
|
return this.nativeLiveActivityFactory
|
|
@@ -233,6 +245,7 @@ export function createWidget<
|
|
|
233
245
|
* Creates a Live Activity Factory for managing Live Activities of a specific type.
|
|
234
246
|
* @param name The Live Activity name. Must match the `'name'` field in your widget configuration in the app config.
|
|
235
247
|
* @param liveActivity The Live Activity component, marked with the `'widget'` directive.
|
|
248
|
+
* @platform ios
|
|
236
249
|
*/
|
|
237
250
|
export function createLiveActivity<T extends object = object>(
|
|
238
251
|
name: string,
|
|
@@ -257,6 +270,7 @@ export function addUserInteractionListener(
|
|
|
257
270
|
* This token can be used to start live activities remotely via APNs.
|
|
258
271
|
* @param listener Callback function to handle push-to-start token events.
|
|
259
272
|
* @return An event subscription that can be used to remove the listener.
|
|
273
|
+
* @platform ios
|
|
260
274
|
*/
|
|
261
275
|
export function addPushToStartTokenListener(
|
|
262
276
|
listener: ExpoWidgetsEvents['onExpoWidgetsPushToStartTokenReceived']
|