@trycourier/courier-react-native 2.5.0 → 3.0.0

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 (93) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +187 -0
  3. package/android/src/main/java/com/courierreactnative/CourierPreferencesViewManager.kt +128 -0
  4. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +3 -1
  5. package/android/src/main/java/com/courierreactnative/Extensions.kt +68 -1
  6. package/courier-react-native.podspec +1 -1
  7. package/ios/{CourierReactNativeViewManager.m → CourierInboxReactNativeManager.m} +1 -1
  8. package/ios/CourierInboxReactNativeManager.swift +159 -0
  9. package/ios/CourierPreferencesReactNativeManager.m +11 -0
  10. package/ios/CourierPreferencesReactNativeManager.swift +140 -0
  11. package/ios/CourierReactNativeModule.swift +50 -36
  12. package/ios/Utils.swift +70 -0
  13. package/lib/commonjs/index.js +54 -36
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/models/Android_CourierSheet.js +6 -0
  16. package/lib/commonjs/models/Android_CourierSheet.js.map +1 -0
  17. package/lib/commonjs/models/CourierButton.js +6 -0
  18. package/lib/commonjs/models/CourierButton.js.map +1 -0
  19. package/lib/commonjs/models/CourierFont.js +2 -0
  20. package/lib/commonjs/models/CourierFont.js.map +1 -0
  21. package/lib/commonjs/models/CourierInboxTheme.js +4 -0
  22. package/lib/commonjs/models/CourierInfoViewStyle.js +6 -0
  23. package/lib/commonjs/models/CourierInfoViewStyle.js.map +1 -0
  24. package/lib/commonjs/models/CourierPreferencesTheme.js +6 -0
  25. package/lib/commonjs/models/CourierPreferencesTheme.js.map +1 -0
  26. package/lib/commonjs/models/iOS_CourierCell.js +2 -0
  27. package/lib/commonjs/models/iOS_CourierCell.js.map +1 -0
  28. package/lib/commonjs/models/iOS_CourierSheet.js +6 -0
  29. package/lib/commonjs/models/iOS_CourierSheet.js.map +1 -0
  30. package/lib/commonjs/views/CourierInboxView.js +1 -1
  31. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  32. package/lib/commonjs/views/CourierPreferencesView.js +37 -0
  33. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -0
  34. package/lib/module/index.js +25 -25
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/models/Android_CourierSheet.js +2 -0
  37. package/lib/module/models/Android_CourierSheet.js.map +1 -0
  38. package/lib/module/models/CourierButton.js +2 -0
  39. package/lib/module/models/CourierButton.js.map +1 -0
  40. package/lib/module/models/CourierFont.js +2 -0
  41. package/lib/module/models/CourierFont.js.map +1 -0
  42. package/lib/module/models/CourierInboxTheme.js +1 -1
  43. package/lib/module/models/CourierInfoViewStyle.js +2 -0
  44. package/lib/module/models/CourierInfoViewStyle.js.map +1 -0
  45. package/lib/module/models/CourierPreferencesTheme.js +2 -0
  46. package/lib/module/models/CourierPreferencesTheme.js.map +1 -0
  47. package/lib/module/models/iOS_CourierCell.js +2 -0
  48. package/lib/module/models/iOS_CourierCell.js.map +1 -0
  49. package/lib/module/models/iOS_CourierSheet.js +2 -0
  50. package/lib/module/models/iOS_CourierSheet.js.map +1 -0
  51. package/lib/module/views/CourierInboxView.js +1 -1
  52. package/lib/module/views/CourierInboxView.js.map +1 -1
  53. package/lib/module/views/CourierPreferencesView.js +29 -0
  54. package/lib/module/views/CourierPreferencesView.js.map +1 -0
  55. package/lib/typescript/index.d.ts +9 -3
  56. package/lib/typescript/index.d.ts.map +1 -1
  57. package/lib/typescript/models/Android_CourierSheet.d.ts +7 -0
  58. package/lib/typescript/models/Android_CourierSheet.d.ts.map +1 -0
  59. package/lib/typescript/models/CourierButton.d.ts +7 -0
  60. package/lib/typescript/models/CourierButton.d.ts.map +1 -0
  61. package/lib/typescript/models/CourierFont.d.ts +6 -0
  62. package/lib/typescript/models/CourierFont.d.ts.map +1 -0
  63. package/lib/typescript/models/CourierInboxTheme.d.ts +9 -19
  64. package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -1
  65. package/lib/typescript/models/CourierInfoViewStyle.d.ts +7 -0
  66. package/lib/typescript/models/CourierInfoViewStyle.d.ts.map +1 -0
  67. package/lib/typescript/models/CourierPreferencesTheme.d.ts +35 -0
  68. package/lib/typescript/models/CourierPreferencesTheme.d.ts.map +1 -0
  69. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts +3 -1
  70. package/lib/typescript/models/CourierUserPreferencesTopic.d.ts.map +1 -1
  71. package/lib/typescript/models/iOS_CourierCell.d.ts +12 -0
  72. package/lib/typescript/models/iOS_CourierCell.d.ts.map +1 -0
  73. package/lib/typescript/models/iOS_CourierSheet.d.ts +6 -0
  74. package/lib/typescript/models/iOS_CourierSheet.d.ts.map +1 -0
  75. package/lib/typescript/views/CourierPreferencesView.d.ts +15 -0
  76. package/lib/typescript/views/CourierPreferencesView.d.ts.map +1 -0
  77. package/package.json +5 -2
  78. package/src/index.tsx +27 -27
  79. package/src/models/Android_CourierSheet.tsx +7 -0
  80. package/src/models/CourierButton.tsx +7 -0
  81. package/src/models/CourierFont.tsx +5 -0
  82. package/src/models/CourierInboxTheme.tsx +9 -21
  83. package/src/models/CourierInfoViewStyle.tsx +7 -0
  84. package/src/models/CourierPreferencesTheme.tsx +34 -0
  85. package/src/models/CourierUserPreferencesTopic.tsx +3 -1
  86. package/src/models/iOS_CourierCell.tsx +6 -0
  87. package/src/models/iOS_CourierSheet.tsx +6 -0
  88. package/src/views/CourierInboxView.tsx +12 -12
  89. package/src/views/CourierPreferencesView.tsx +53 -0
  90. package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +0 -225
  91. package/ios/CourierAuthenticationListenerWrapper.swift +0 -14
  92. package/ios/CourierInboxListenerWrapper.swift +0 -24
  93. package/ios/CourierReactNativeViewManager.swift +0 -302
@@ -0,0 +1,12 @@
1
+ export interface iOS_CourierCell {
2
+ separatorStyle?: 'none' | 'singleLine' | 'singleLineEtched';
3
+ separatorInsets?: {
4
+ top?: number;
5
+ left?: number;
6
+ bottom?: number;
7
+ right?: number;
8
+ };
9
+ separatorColor?: string;
10
+ selectionStyle?: 'none' | 'blue' | 'gray' | 'default';
11
+ }
12
+ //# sourceMappingURL=iOS_CourierCell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iOS_CourierCell.d.ts","sourceRoot":"","sources":["../../../src/models/iOS_CourierCell.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,kBAAkB,CAAA;IAC3D,eAAe,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAClF,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACtD"}
@@ -0,0 +1,6 @@
1
+ import { CourierFont } from "./CourierFont";
2
+ export interface iOS_CourierSheet {
3
+ font?: CourierFont;
4
+ toggleColor?: string;
5
+ }
6
+ //# sourceMappingURL=iOS_CourierSheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iOS_CourierSheet.d.ts","sourceRoot":"","sources":["../../../src/models/iOS_CourierSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import { ViewStyle } from "react-native";
3
+ import { CourierPreferencesMode, CourierPreferencesTheme } from "src/models/CourierPreferencesTheme";
4
+ type CourierPreferencesProps = {
5
+ mode?: CourierPreferencesMode;
6
+ theme?: {
7
+ light?: CourierPreferencesTheme;
8
+ dark?: CourierPreferencesTheme;
9
+ };
10
+ onPreferenceError?: (message: string) => void;
11
+ style?: ViewStyle;
12
+ };
13
+ export declare const CourierPreferencesView: (props: CourierPreferencesProps) => React.JSX.Element;
14
+ export {};
15
+ //# sourceMappingURL=CourierPreferencesView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CourierPreferencesView.d.ts","sourceRoot":"","sources":["../../../src/views/CourierPreferencesView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAA+C,SAAS,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAErG,KAAK,uBAAuB,GAAG;IAC7B,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAC9B,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,uBAAuB,CAAC;QAChC,IAAI,CAAC,EAAE,uBAAuB,CAAA;KAC/B,CAAC;IACF,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AAiBF,eAAO,MAAM,sBAAsB,UAAW,uBAAuB,sBAuBpE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "2.5.0",
3
+ "version": "3.0.0",
4
4
  "description": "Inbox & Push Notifications for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -72,7 +72,7 @@
72
72
  "pod-install": "^0.1.0",
73
73
  "prettier": "^2.0.5",
74
74
  "react": "18.2.0",
75
- "react-native": "0.72.4",
75
+ "react-native": "0.73.7",
76
76
  "react-native-builder-bob": "^0.21.3",
77
77
  "release-it": "^15.0.0",
78
78
  "turbo": "^1.10.7",
@@ -161,5 +161,8 @@
161
161
  }
162
162
  ]
163
163
  ]
164
+ },
165
+ "dependencies": {
166
+ "react-native-toast-message": "^2.2.0"
164
167
  }
165
168
  }
package/src/index.tsx CHANGED
@@ -19,13 +19,19 @@ import { Events, Utils } from './utils';
19
19
 
20
20
  // Exports
21
21
  export { CourierInboxView } from './views/CourierInboxView';
22
+ export { CourierPreferencesView } from './views/CourierPreferencesView';
22
23
  export { CourierInboxListener } from './models/CourierInboxListener';
23
24
  export { CourierPushListener } from './models/CourierPushListener';
24
25
  export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
25
26
  export { CourierUserPreferencesChannel } from './models/CourierUserPreferencesChannel';
26
27
  export { CourierUserPreferencesStatus } from './models/CourierUserPreferencesStatus';
27
28
  export { CourierPushProvider } from './models/CourierPushProvider';
28
- export { CourierInboxFont, CourierInboxButtonStyle, CourierInboxButton, CourierInboxTextStyle, CourierInboxInfoViewStyle, CourierInboxUnreadIndicatorStyle, CourierInboxTheme } from './models/CourierInboxTheme';
29
+ export { CourierFont } from './models/CourierFont';
30
+ export { CourierButton } from './models/CourierButton';
31
+ export { CourierInfoViewStyle } from './models/CourierInfoViewStyle';
32
+ export { iOS_CourierCell } from './models/iOS_CourierCell';
33
+ export { iOS_CourierSheet } from './models/iOS_CourierSheet';
34
+ export { CourierInboxButtonStyle, CourierInboxTextStyle, CourierInboxUnreadIndicatorStyle, CourierInboxTheme } from './models/CourierInboxTheme';
29
35
  export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
30
36
 
31
37
  const LINKING_ERROR =
@@ -207,8 +213,8 @@ class Courier {
207
213
  }
208
214
 
209
215
  /**
210
- * Gets the user id that is currently being used
211
- * This is the user id associated with the http requests the sdk does
216
+ * Gets the user id that is currently being used.
217
+ * This is the user id associated with the network requests the sdk does.
212
218
  */
213
219
  get userId(): string | undefined {
214
220
  return CourierReactNativeModules.getUserId() ?? undefined
@@ -234,7 +240,7 @@ class Courier {
234
240
  public addAuthenticationListener(props: { onUserChanged: (userId?: string) => void }): CourierAuthenticationListener {
235
241
 
236
242
  // Event listener id
237
- const authId = Utils.generateUUID();
243
+ const authId = `authentication_${Utils.generateUUID()}`;
238
244
 
239
245
  // Get the id
240
246
  const id = CourierReactNativeModules.addAuthenticationListener(authId);
@@ -310,9 +316,9 @@ class Courier {
310
316
  public addInboxListener(props: { onInitialLoad?: () => void, onError?: (error: string) => void, onMessagesChanged?: (messages: InboxMessage[], unreadMessageCount: number, totalMessageCount: number, canPaginate: boolean) => void }): CourierInboxListener {
311
317
 
312
318
  const listenerIds = {
313
- loading: Utils.generateUUID(),
314
- error: Utils.generateUUID(),
315
- messages: Utils.generateUUID()
319
+ loading: `inbox_loading_${Utils.generateUUID()}`,
320
+ error: `inbox_error_${Utils.generateUUID()}`,
321
+ messages: `inbox_messages_${Utils.generateUUID()}`
316
322
  }
317
323
 
318
324
  // Set the listener id
@@ -325,28 +331,22 @@ class Courier {
325
331
  // Create the initial listeners
326
332
  const listener = new CourierInboxListener(id);
327
333
 
328
- if (props.onInitialLoad) {
329
- listener.onInitialLoad = Utils.addEventListener(listenerIds.loading, CourierEventEmitter, (_: any) => {
330
- props.onInitialLoad?.();
331
- });
332
- }
334
+ listener.onInitialLoad = Utils.addEventListener(listenerIds.loading, CourierEventEmitter, (_: any) => {
335
+ props.onInitialLoad?.();
336
+ });
333
337
 
334
- if (props.onError) {
335
- listener.onError = Utils.addEventListener(listenerIds.error, CourierEventEmitter, (event: any) => {
336
- props.onError?.(event);
337
- });
338
- }
338
+ listener.onError = Utils.addEventListener(listenerIds.error, CourierEventEmitter, (event: any) => {
339
+ props.onError?.(event);
340
+ });
339
341
 
340
- if (props.onMessagesChanged) {
341
- listener.onMessagesChanged = Utils.addEventListener(listenerIds.messages, CourierEventEmitter, (event: any) => {
342
- props.onMessagesChanged?.(
343
- event.messages,
344
- event.unreadMessageCount,
345
- event.totalMessageCount,
346
- event.canPaginate,
347
- );
348
- });
349
- }
342
+ listener.onMessagesChanged = Utils.addEventListener(listenerIds.messages, CourierEventEmitter, (event: any) => {
343
+ props.onMessagesChanged?.(
344
+ event.messages,
345
+ event.unreadMessageCount,
346
+ event.totalMessageCount,
347
+ event.canPaginate,
348
+ );
349
+ });
350
350
 
351
351
  // Add listener to manager
352
352
  this.inboxListeners.set(id, listener);
@@ -0,0 +1,7 @@
1
+ import { CourierFont } from "./CourierFont"
2
+
3
+ export interface Android_CourierSheet {
4
+ font?: CourierFont
5
+ toggleTrackColor?: string
6
+ toggleThumbColor?: string
7
+ }
@@ -0,0 +1,7 @@
1
+ import { CourierFont } from "./CourierFont"
2
+
3
+ export interface CourierButton {
4
+ font?: CourierFont
5
+ backgroundColor?: string
6
+ cornerRadius?: number
7
+ }
@@ -0,0 +1,5 @@
1
+ export interface CourierFont {
2
+ family?: string
3
+ size?: number
4
+ color?: string
5
+ }
@@ -1,28 +1,15 @@
1
- export interface CourierInboxFont {
2
- family?: string
3
- size?: number
4
- color?: string
5
- }
1
+ import { CourierButton } from "./CourierButton"
2
+ import { CourierFont } from "./CourierFont"
3
+ import { CourierInfoViewStyle } from "./CourierInfoViewStyle"
6
4
 
7
5
  export interface CourierInboxButtonStyle {
8
- unread?: CourierInboxButton
9
- read?: CourierInboxButton
10
- }
11
-
12
- export interface CourierInboxButton {
13
- font?: CourierInboxFont
14
- backgroundColor?: string
15
- cornerRadius?: number
6
+ unread?: CourierButton
7
+ read?: CourierButton
16
8
  }
17
9
 
18
10
  export interface CourierInboxTextStyle {
19
- unread?: CourierInboxFont
20
- read?: CourierInboxFont
21
- }
22
-
23
- export interface CourierInboxInfoViewStyle {
24
- font?: CourierInboxFont
25
- button?: CourierInboxButton
11
+ unread?: CourierFont
12
+ read?: CourierFont
26
13
  }
27
14
 
28
15
  export interface CourierInboxUnreadIndicatorStyle {
@@ -31,13 +18,14 @@ export interface CourierInboxUnreadIndicatorStyle {
31
18
  }
32
19
 
33
20
  export interface CourierInboxTheme {
21
+ brandId?: string,
34
22
  loadingIndicatorColor?: string
35
23
  unreadIndicatorStyle?: CourierInboxUnreadIndicatorStyle
36
24
  titleStyle?: CourierInboxTextStyle
37
25
  timeStyle?: CourierInboxTextStyle
38
26
  bodyStyle?: CourierInboxTextStyle
39
27
  buttonStyle?: CourierInboxButtonStyle
40
- infoViewStyle?: CourierInboxInfoViewStyle
28
+ infoViewStyle?: CourierInfoViewStyle
41
29
  iOS?: {
42
30
  messageAnimationStyle?: 'fade' | 'right' | 'left' | 'top' | 'bottom' | 'none' | 'middle' | 'automatic',
43
31
  cellStyles?: {
@@ -0,0 +1,7 @@
1
+ import { CourierButton } from "./CourierButton"
2
+ import { CourierFont } from "./CourierFont"
3
+
4
+ export interface CourierInfoViewStyle {
5
+ font?: CourierFont
6
+ button?: CourierButton
7
+ }
@@ -0,0 +1,34 @@
1
+ import { Android_CourierSheet } from "./Android_CourierSheet";
2
+ import { CourierButton } from "./CourierButton";
3
+ import { CourierFont } from "./CourierFont"
4
+ import { CourierInfoViewStyle } from "./CourierInfoViewStyle";
5
+ import { iOS_CourierCell } from "./iOS_CourierCell";
6
+ import { iOS_CourierSheet } from "./iOS_CourierSheet";
7
+
8
+ export type CourierPreferencesChannel = 'direct_message' | 'email' | 'push' | 'sms' | 'webhook';
9
+
10
+ export type CourierPreferencesMode =
11
+ | { type: 'topic' }
12
+ | { type: 'channels', channels: CourierPreferencesChannel[] };
13
+
14
+ export interface CourierPreferencesTheme {
15
+ brandId?: string
16
+ loadingIndicatorColor?: string
17
+ sectionTitleFont?: CourierFont
18
+ topicTitleFont?: CourierFont
19
+ topicSubtitleFont?: CourierFont
20
+ topicButton?: CourierButton
21
+ sheetTitleFont?: CourierFont
22
+ infoViewStyle?: CourierInfoViewStyle
23
+ iOS?: {
24
+ topicCellStyles?: iOS_CourierCell
25
+ sheetSettingStyles?: iOS_CourierSheet
26
+ sheetCornerRadius?: number
27
+ sheetCellStyles?: iOS_CourierCell
28
+ },
29
+ android?: {
30
+ topicDividerItemDecoration?: 'none' | 'vertical'
31
+ sheetDividerItemDecoration?: 'none' | 'vertical'
32
+ sheetSettingStyles?: Android_CourierSheet
33
+ }
34
+ }
@@ -3,9 +3,11 @@ import { CourierUserPreferencesStatus } from "./CourierUserPreferencesStatus";
3
3
 
4
4
  export interface CourierUserPreferencesTopic {
5
5
  defaultStatus?: string;
6
- hasCustomRouting?: string;
6
+ hasCustomRouting?: boolean;
7
7
  customRouting?: CourierUserPreferencesChannel[];
8
8
  status?: CourierUserPreferencesStatus;
9
+ setionName?: string;
10
+ setionId?: string;
9
11
  topicId?: string;
10
12
  topicName?: string;
11
13
  }
@@ -0,0 +1,6 @@
1
+ export interface iOS_CourierCell {
2
+ separatorStyle?: 'none' | 'singleLine' | 'singleLineEtched'
3
+ separatorInsets?: { top?: number, left?: number, bottom?: number, right?: number }
4
+ separatorColor?: string
5
+ selectionStyle?: 'none' | 'blue' | 'gray' | 'default'
6
+ }
@@ -0,0 +1,6 @@
1
+ import { CourierFont } from "./CourierFont"
2
+
3
+ export interface iOS_CourierSheet {
4
+ font?: CourierFont
5
+ toggleColor?: string
6
+ }
@@ -15,7 +15,7 @@ type CourierInboxViewProps = {
15
15
  style?: ViewStyle;
16
16
  };
17
17
 
18
- const ComponentName = 'CourierReactNativeView';
18
+ const ComponentName = 'CourierInboxView';
19
19
 
20
20
  const LINKING_ERROR =
21
21
  `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -44,7 +44,7 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
44
44
  onScrollInboxListener?.remove();
45
45
  }
46
46
 
47
- }, [])
47
+ }, []);
48
48
 
49
49
  useEffect(() => {
50
50
 
@@ -54,17 +54,17 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
54
54
  onClickInboxMessageAtIndexListener = DeviceEventEmitter.addListener('courierClickMessageAtIndex', onClickInboxMessageAtIndex);
55
55
  }
56
56
 
57
- }, [props.onClickInboxMessageAtIndex])
57
+ }, [props.onClickInboxMessageAtIndex]);
58
58
 
59
59
  const onClickInboxMessageAtIndex = (event: any) => {
60
60
 
61
61
  // Parse the native event data
62
62
  if (props.onClickInboxMessageAtIndex) {
63
63
 
64
- const index = event["index"]
65
- const message = event["message"] as InboxMessage
64
+ const index = event["index"];
65
+ const message = event["message"] as InboxMessage;
66
66
 
67
- props.onClickInboxMessageAtIndex(message, index)
67
+ props.onClickInboxMessageAtIndex(message, index);
68
68
 
69
69
  }
70
70
 
@@ -85,11 +85,11 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
85
85
  // Parse the native event data
86
86
  if (props.onClickInboxActionForMessageAtIndex) {
87
87
 
88
- const index = event["index"]
89
- const action = event["action"] as InboxAction
90
- const message = event["message"] as InboxMessage
88
+ const index = event["index"];
89
+ const action = event["action"] as InboxAction;
90
+ const message = event["message"] as InboxMessage;
91
91
 
92
- props.onClickInboxActionForMessageAtIndex(action, message, index)
92
+ props.onClickInboxActionForMessageAtIndex(action, message, index);
93
93
 
94
94
  }
95
95
 
@@ -110,8 +110,8 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
110
110
  // Parse the native event data
111
111
  if (props.onScrollInbox) {
112
112
 
113
- const contentOffset = event["contentOffset"]
114
- props.onScrollInbox(contentOffset["y"], contentOffset["x"])
113
+ const contentOffset = event["contentOffset"];
114
+ props.onScrollInbox(contentOffset["y"], contentOffset["x"]);
115
115
 
116
116
  }
117
117
 
@@ -0,0 +1,53 @@
1
+ import React from "react";
2
+ import { Platform, requireNativeComponent, UIManager, ViewStyle } from "react-native";
3
+ import { CourierPreferencesMode, CourierPreferencesTheme } from "src/models/CourierPreferencesTheme";
4
+
5
+ type CourierPreferencesProps = {
6
+ mode?: CourierPreferencesMode,
7
+ theme?: {
8
+ light?: CourierPreferencesTheme,
9
+ dark?: CourierPreferencesTheme
10
+ };
11
+ onPreferenceError?: (message: string) => void;
12
+ style?: ViewStyle;
13
+ };
14
+
15
+ const ComponentName = 'CourierPreferencesView';
16
+
17
+ const LINKING_ERROR =
18
+ `The package '@trycourier/courier-react-native' doesn't seem to be linked. Make sure: \n\n` +
19
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
20
+ '- You rebuilt the app after installing the package\n' +
21
+ '- You are not using Expo Go\n';
22
+
23
+ const CourierPreferences =
24
+ UIManager.getViewManagerConfig(ComponentName) != null
25
+ ? requireNativeComponent<CourierPreferencesProps>(ComponentName)
26
+ : () => {
27
+ throw new Error(LINKING_ERROR);
28
+ };
29
+
30
+ export const CourierPreferencesView = (props: CourierPreferencesProps) => {
31
+
32
+ const onPreferenceError = (event: any) => {
33
+
34
+ // Parse the native event data
35
+ if (props.onPreferenceError) {
36
+
37
+ const message = event["error"];
38
+ props.onPreferenceError(message);
39
+
40
+ }
41
+
42
+ }
43
+
44
+ return (
45
+ <CourierPreferences
46
+ mode={props.mode}
47
+ theme={props.theme ?? { light: undefined, dark: undefined }}
48
+ onPreferenceError={(event: any) => onPreferenceError(event.nativeEvent)}
49
+ style={props.style}
50
+ />
51
+ )
52
+
53
+ }
@@ -1,225 +0,0 @@
1
- package com.courierreactnative
2
-
3
- import android.content.Context
4
- import android.graphics.Color
5
- import android.graphics.Typeface
6
- import android.view.View
7
- import androidx.recyclerview.widget.DividerItemDecoration
8
- import com.courier.android.inbox.*
9
- import com.facebook.react.bridge.Arguments
10
- import com.facebook.react.bridge.ReadableMap
11
- import com.facebook.react.uimanager.SimpleViewManager
12
- import com.facebook.react.uimanager.ThemedReactContext
13
- import com.facebook.react.uimanager.annotations.ReactProp
14
-
15
-
16
- class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
17
-
18
- private companion object {
19
- const val ON_CLICK_MESSAGE_AT_INDEX = "courierClickMessageAtIndex"
20
- const val ON_CLICK_ACTION_AT_INDEX = "courierClickActionAtIndex"
21
- const val ON_SCROLL = "courierScrollInbox"
22
- }
23
-
24
- override fun getName() = "CourierReactNativeView"
25
-
26
- override fun createViewInstance(reactContext: ThemedReactContext): CourierInbox = CourierInbox(reactContext)
27
-
28
- private val View.reactContext: ThemedReactContext get() = context as ThemedReactContext
29
-
30
- @ReactProp(name = "onClickInboxMessageAtIndex")
31
- fun setOnClickInboxMessageAtIndex(view: CourierInbox, callback: Boolean) {
32
-
33
- view.setOnClickMessageListener { message, index ->
34
-
35
- val map = Arguments.createMap()
36
- map.putMap("message", message.toWritableMap())
37
- map.putInt("index", index)
38
-
39
- view.reactContext.sendEvent(ON_CLICK_MESSAGE_AT_INDEX, map)
40
-
41
- }
42
-
43
- }
44
-
45
- @ReactProp(name = "onClickInboxActionForMessageAtIndex")
46
- fun setOnClickInboxActionForMessageAtIndex(view: CourierInbox, callback: Boolean) {
47
-
48
- view.setOnClickActionListener { action, message, index ->
49
-
50
- val map = Arguments.createMap()
51
- map.putMap("action", action.toWritableMap())
52
- map.putMap("message", message.toWritableMap())
53
- map.putInt("index", index)
54
-
55
- view.reactContext.sendEvent(ON_CLICK_ACTION_AT_INDEX, map)
56
-
57
- }
58
-
59
- }
60
-
61
- @ReactProp(name = "onScrollInbox")
62
- fun setOnScrollInbox(view: CourierInbox, callback: Boolean) {
63
-
64
- view.setOnScrollInboxListener { offsetInDp ->
65
-
66
- val offset = Arguments.createMap()
67
- offset.putInt("y", offsetInDp)
68
- offset.putInt("x", 0)
69
-
70
- val map = Arguments.createMap()
71
- map.putMap("contentOffset", offset)
72
-
73
- view.reactContext.sendEvent(ON_SCROLL, map)
74
-
75
- }
76
-
77
- }
78
-
79
- @ReactProp(name = "theme")
80
- fun setTheme(view: CourierInbox, theme: ReadableMap) {
81
- view.lightTheme = theme.getMap("light")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_LIGHT
82
- view.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_DARK
83
- }
84
-
85
- private fun ReadableMap.toTheme(view: View): CourierInboxTheme {
86
-
87
- val android = getMap("android")
88
- val dividerItemDecoration = android?.getString("dividerItemDecoration")
89
-
90
- val unreadIndicatorStyle = getMap("unreadIndicatorStyle")
91
- val loadingIndicatorColor = getString("loadingIndicatorColor")
92
-
93
- val titleStyle = getMap("titleStyle")
94
- val timeStyle = getMap("timeStyle")
95
- val bodyStyle = getMap("bodyStyle")
96
- val infoViewStyle = getMap("infoViewStyle")
97
- val buttonStyles = getMap("buttonStyles")
98
-
99
- val context = view.context
100
-
101
- return CourierInboxTheme(
102
- unreadIndicatorStyle = unreadIndicatorStyle?.toUnreadIndicatorStyle() ?: CourierInboxUnreadIndicatorStyle(),
103
- loadingIndicatorColor = loadingIndicatorColor?.toColor(),
104
- titleStyle = titleStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
105
- unread = CourierInboxFont(),
106
- read = CourierInboxFont(),
107
- ),
108
- timeStyle = timeStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
109
- unread = CourierInboxFont(),
110
- read = CourierInboxFont(),
111
- ),
112
- bodyStyle = bodyStyle?.toTextStyle(context) ?: CourierInboxTextStyle(
113
- unread = CourierInboxFont(),
114
- read = CourierInboxFont(),
115
- ),
116
- buttonStyle = buttonStyles?.toButtonStyle(context) ?: CourierInboxButtonStyle(
117
- unread = CourierInboxButton(),
118
- read = CourierInboxButton(),
119
- ),
120
- infoViewStyle = infoViewStyle?.toInfoStyle(context) ?: CourierInboxInfoViewStyle(
121
- font = CourierInboxFont(),
122
- button = CourierInboxButton(),
123
- ),
124
- dividerItemDecoration = dividerItemDecoration?.toDivider(context),
125
- )
126
-
127
- }
128
-
129
- private fun String.toColor(): Int = Color.parseColor(this)
130
-
131
- private fun String.toFont(context: Context): Typeface? {
132
- return try {
133
- val assetManager = context.assets
134
- Typeface.createFromAsset(assetManager, this)
135
- } catch (e: Exception) {
136
- e.printStackTrace()
137
- null
138
- }
139
- }
140
-
141
- private fun String.toDivider(context: Context): DividerItemDecoration? = if (this == "vertical") DividerItemDecoration(context, DividerItemDecoration.VERTICAL) else null
142
-
143
- private fun ReadableMap.toFont(context: Context): CourierInboxFont {
144
-
145
- val typeface = getString("family")
146
- val size = if (isNull("size")) null else getDouble("size")
147
- val color = getString("color")
148
-
149
- return CourierInboxFont(
150
- typeface = typeface?.toFont(context),
151
- color = color?.toColor(),
152
- sizeInSp = size?.toInt()
153
- )
154
-
155
- }
156
-
157
- private fun ReadableMap.toTextStyle(context: Context): CourierInboxTextStyle {
158
-
159
- val unread = getMap("unread")
160
- val read = getMap("read")
161
-
162
- return CourierInboxTextStyle(
163
- unread = unread?.toFont(context) ?: CourierInboxFont(),
164
- read = read?.toFont(context) ?: CourierInboxFont(),
165
- )
166
-
167
- }
168
-
169
- private fun ReadableMap.toUnreadIndicatorStyle(): CourierInboxUnreadIndicatorStyle {
170
-
171
- val indicator = getString("indicator")
172
- val color = getString("color")
173
-
174
- var style = CourierInboxUnreadIndicator.LINE
175
-
176
- if (indicator == "dot") {
177
- style = CourierInboxUnreadIndicator.DOT
178
- }
179
-
180
- return CourierInboxUnreadIndicatorStyle(
181
- indicator = style,
182
- color = color?.toColor(),
183
- )
184
-
185
- }
186
-
187
- private fun ReadableMap.toButton(context: Context): CourierInboxButton {
188
-
189
- val font = getMap("font")
190
- val backgroundColor = getString("backgroundColor")
191
- val cornerRadius = if (isNull("cornerRadius")) null else getDouble("cornerRadius")
192
-
193
- return CourierInboxButton(
194
- font = font?.toFont(context),
195
- backgroundColor = backgroundColor?.toColor(),
196
- cornerRadiusInDp = cornerRadius?.toInt()
197
- )
198
-
199
- }
200
-
201
- private fun ReadableMap.toButtonStyle(context: Context): CourierInboxButtonStyle {
202
-
203
- val unread = getMap("unread")
204
- val read = getMap("read")
205
-
206
- return CourierInboxButtonStyle(
207
- unread = unread?.toButton(context) ?: CourierInboxButton(),
208
- read = read?.toButton(context) ?: CourierInboxButton()
209
- )
210
-
211
- }
212
-
213
- private fun ReadableMap.toInfoStyle(context: Context): CourierInboxInfoViewStyle {
214
-
215
- val font = getMap("font")
216
- val button = getMap("button")
217
-
218
- return CourierInboxInfoViewStyle(
219
- font = font?.toFont(context) ?: CourierInboxFont(),
220
- button = button?.toButton(context) ?: CourierInboxButton()
221
- )
222
-
223
- }
224
-
225
- }