@@ -14,15 +14,69 @@ module FetchResult = {
1414 external resultFailed : t = "ResultFailed" ;
1515};
1616
17+ /**
18+ * Alert Object that can be included in the aps `alert` object
19+ */
20+ type notificationAlert = {
21+ title: option (string ),
22+ subtitle: option (string ),
23+ body: option (string ),
24+ };
25+
26+ type notificationActionOptions = {
27+ foreground: option (bool ),
28+ destructive: option (bool ),
29+ authenticationRequired: option (bool ),
30+ };
31+
32+ type notificationActionTextInput = {
33+ /**
34+ * Text to be shown on button when user finishes text input.
35+ * Default is "Send" or its equivalent word in user's language setting.
36+ */
37+ buttonTitle: option (string ),
38+ /**
39+ * Placeholder for text input for text input action.
40+ */
41+ placeholder: option (string ),
42+ };
43+
44+ /**
45+ * Notification Action that can be added to specific categories
46+ */
47+ type notificationAction = {
48+ /**
49+ * Id of Action.
50+ * This value will be returned as actionIdentifier when notification is received.
51+ */
52+ id: string ,
53+ /**
54+ * Text to be shown on notification action button.
55+ */
56+ title: string ,
57+ /**
58+ * Option for notification action.
59+ */
60+ options: option (notificationActionOptions ),
61+ /**
62+ * Option for textInput action.
63+ * If textInput prop exists, then user action will automatically become a text input action.
64+ * The text user inputs will be in the userText field of the received notification.
65+ */
66+ textInput: option (notificationActionTextInput ),
67+ };
68+
1769module Notification = {
1870 type t ;
1971
2072 [@ bs . send ] [@ bs . return nullable]
73+ // string | notificationAlert
2174 external getAlert : t => option (Js . Json . t ) = "getAlert" ;
2275
2376 [@ bs . send ] external getTitle : t => string = "getTitle" ;
2477
2578 [@ bs . send ] [@ bs . return nullable]
79+ // string | notificationAlert
2680 external getMessage : t => option (Js . Json . t ) = "getMessage" ;
2781
2882 [@ bs . send ] [@ bs . return nullable]
@@ -40,12 +94,101 @@ module Notification = {
4094 [@ bs . send ] [@ bs . return nullable]
4195 external getData : t => option (Js . Json . t ) = "getData" ;
4296
97+ /**
98+ * Get's the action id of the notification action user has taken.
99+ */
100+ [@ bs . send ] [@ bs . return nullable]
101+ external getActionIdentifier : t => option (string ) = "getActionIdentifier" ;
102+
103+ /**
104+ * Gets the text user has inputed if user has taken the text action response.
105+ */
106+ [@ bs . send ] [@ bs . return nullable]
107+ external getUserText : t => option (string ) = "getUserText" ;
108+
43109 [@ bs . send ] [@ bs . return nullable]
44110 external getThreadID : t => option (string ) = "getThreadID" ;
45111
46112 [@ bs . send ] external finish : (t , FetchResult . t ) => unit = "finish" ;
47113};
48114
115+ type notificationRequest = {
116+ /**
117+ * identifier of the notification.
118+ * Required in order to retrieve specific notification.
119+ */
120+ id: string ,
121+ /**
122+ * A short description of the reason for the alert.
123+ */
124+ title: option (string ),
125+ /**
126+ * A secondary description of the reason for the alert.
127+ */
128+ subtitle: option (string ),
129+ /**
130+ * The message displayed in the notification alert.
131+ */
132+ body: option (string ),
133+ /**
134+ * The number to display as the app's icon badge.
135+ */
136+ badge: option (int ),
137+ /**
138+ * The sound to play when the notification is delivered.
139+ */
140+ sound: option (string ),
141+ /**
142+ * The category of this notification. Required for actionable notifications.
143+ */
144+ category: option (string ),
145+ /**
146+ * The thread identifier of this notification.
147+ */
148+ threadId: option (string ),
149+ /**
150+ * The date which notification triggers.
151+ */
152+ fireDate: option (Js . Date . t ),
153+ /**
154+ * Sets notification to repeat daily.
155+ * Must be used with fireDate.
156+ */
157+ repeats: option (bool ),
158+ /**
159+ * Sets notification to be silent
160+ */
161+ isSilent: option (bool ),
162+ /**
163+ * Optional data to be added to the notification
164+ */
165+ userInfo: option (Js . Json . t ),
166+ };
167+
168+ [@ bs . obj ]
169+ external notificationRequest :
170+ (
171+ ~id : string ,
172+ ~title : string =?,
173+ ~subtitle : string =?,
174+ ~body : string =?,
175+ ~badge : int =?,
176+ ~sound : string =?,
177+ ~category : string =?,
178+ ~threadId : string =?,
179+ ~fireDate : Js . Date . t =?,
180+ ~repeats : bool =?,
181+ ~isSilent : bool =?,
182+ ~userInfo : Js . Json . t =?,
183+ unit
184+ ) =>
185+ notificationRequest ;
186+
187+ [@ bs . module "@react-native-community/push-notification-ios" ]
188+ [@ bs . scope "default" ]
189+ external addNotificationRequest : notificationRequest => unit =
190+ "addNotificationRequest" ;
191+
49192type localNotification ;
50193
51194[@ bs . obj ]
@@ -65,21 +208,29 @@ external localNotification:
65208 ) =>
66209 localNotification ;
67210
211+ [@ deprecated "Please use addNotificationRequest instead" ]
68212[@ bs . module "@react-native-community/push-notification-ios" ]
69213[@ bs . scope "default" ]
70214external presentLocalNotification : localNotification => unit =
71215 "presentLocalNotification" ;
72216
217+ [@ deprecated "Please use addNotificationRequest instead" ]
73218[@ bs . module "@react-native-community/push-notification-ios" ]
74219[@ bs . scope "default" ]
75220external scheduleLocalNotification : localNotification => unit =
76221 "scheduleLocalNotification" ;
77222
223+ [@ deprecated "Please use removeAllPendingNotificationRequests instead" ]
78224[@ bs . module "@react-native-community/push-notification-ios" ]
79225[@ bs . scope "default" ]
80226external cancelAllLocalNotifications : unit => unit =
81227 "cancelAllLocalNotifications" ;
82228
229+ [@ bs . module "@react-native-community/push-notification-ios" ]
230+ [@ bs . scope "default" ]
231+ external removeAllPendingNotificationRequests : unit => unit =
232+ "removeAllPendingNotificationRequests" ;
233+
83234[@ bs . module "@react-native-community/push-notification-ios" ]
84235[@ bs . scope "default" ]
85236external removeAllDeliveredNotifications : unit => unit =
@@ -89,10 +240,13 @@ type deliveredNotification = {
89240 identifier: string ,
90241 date: option (string ),
91242 title: option (string ),
243+ subtitle: option (string ),
92244 body: option (string ),
93245 category: option (string ),
246+ actionIdentifier: option (string ),
94247 [@bs.as "thread-id"]
95248 threadId: option (string ),
249+ userText: option (string ),
96250 userInfo: option (Js . Json . t ),
97251};
98252
@@ -140,12 +294,19 @@ type formattedLocalNotification = {
140294 userInfo: option (Js . Json . t ),
141295};
142296
297+ [@ deprecated "Please use getPendingNotificationRequests instead" ]
143298[@ bs . module "@react-native-community/push-notification-ios" ]
144299[@ bs . scope "default" ]
145300external getScheduledLocalNotifications :
146301 (array (formattedLocalNotification ) => unit ) => unit =
147302 "getScheduledLocalNotifications" ;
148303
304+ [@ bs . module "@react-native-community/push-notification-ios" ]
305+ [@ bs . scope "default" ]
306+ external getPendingNotificationRequests :
307+ (array (notificationRequest ) => unit ) => unit =
308+ "getPendingNotificationRequests" ;
309+
149310type registrationError (' a ) = {
150311 message: string,
151312 code: int,
@@ -182,12 +343,20 @@ external removeEventListener:
182343 unit =
183344 "removeEventListener" ;
184345
185- type permissions = {
346+ type requestedPermissions = {
347+ alert: bool ,
348+ badge: bool ,
349+ sound: bool ,
350+ };
351+
352+ type checkedPermissions = {
186353 alert: bool ,
187354 badge: bool ,
188355 sound: bool ,
189356 lockScreen: bool ,
190357 notificationCenter: bool ,
358+ // https://developer.apple.com/documentation/usernotifications/unauthorizationstatus
359+ authorizationStatus: int ,
191360};
192361
193362type requestPermissionsOptions ;
@@ -199,14 +368,14 @@ external requestPermissionsOptions:
199368// multiple externals
200369[@ bs . module "@react-native-community/push-notification-ios" ]
201370[@ bs . scope "default" ]
202- external requestPermissions : unit => Js . Promise . t (permissions ) =
371+ external requestPermissions : unit => Js . Promise . t (requestedPermissions ) =
203372 "requestPermissions" ;
204373
205374// multiple externals
206375[@ bs . module "@react-native-community/push-notification-ios" ]
207376[@ bs . scope "default" ]
208377external requestPermissionsWithOptions :
209- requestPermissionsOptions => Js . Promise . t (permissions ) =
378+ requestPermissionsOptions => Js . Promise . t (requestedPermissions ) =
210379 "requestPermissions" ;
211380
212381[@ bs . module "@react-native-community/push-notification-ios" ]
@@ -215,10 +384,24 @@ external abandonPermissions: unit => unit = "abandonPermissions";
215384
216385[@ bs . module "@react-native-community/push-notification-ios" ]
217386[@ bs . scope "default" ]
218- external checkPermissions : (unit => permissions ) => unit = "checkPermissions" ;
387+ external checkPermissions : (unit => checkedPermissions ) => unit =
388+ "checkPermissions" ;
219389
220390[@ bs . module "@react-native-community/push-notification-ios" ]
221391[@ bs . scope "default" ]
222392external getInitialNotification :
223393 unit => Js . Promise . t (Js . Nullable . t (Notification . t )) =
224394 "getInitialNotification" ;
395+
396+ /**
397+ * Notification Category that can include specific actions
398+ */
399+ type notificationCategory = {
400+ id: string ,
401+ actions: array (notificationAction ),
402+ };
403+ [@ bs . module "@react-native-community/push-notification-ios" ]
404+ [@ bs . scope "default" ]
405+ external setNotificationCategories :
406+ array (notificationCategory ) => Js . Promise . t (unit ) =
407+ "setNotificationCategories" ;
0 commit comments