@trycourier/courier-react-native 5.6.16 → 5.7.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 (222) hide show
  1. package/README.md +66 -135
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +1 -0
  4. package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +3 -0
  5. package/android/src/main/java/com/courierreactnative/Utils.kt +11 -1
  6. package/courier-react-native.podspec +1 -1
  7. package/ios/CourierClientModule.swift +1 -0
  8. package/ios/CourierReactNativeDelegate.m +1 -1
  9. package/ios/CourierReactNativeEventEmitter.swift +1 -1
  10. package/ios/CourierReactNativeModule.m +1 -0
  11. package/ios/CourierSharedModule.swift +10 -3
  12. package/ios/Utils.swift +10 -0
  13. package/lib/commonjs/Broadcaster.js +5 -5
  14. package/lib/commonjs/Broadcaster.js.map +1 -1
  15. package/lib/commonjs/CourierApiUrls.js +29 -0
  16. package/lib/commonjs/CourierApiUrls.js.map +1 -0
  17. package/lib/commonjs/Modules.js.map +1 -1
  18. package/lib/commonjs/client/BrandClient.js.map +1 -1
  19. package/lib/commonjs/client/ClientModule.js.map +1 -1
  20. package/lib/commonjs/client/CourierClient.js +4 -1
  21. package/lib/commonjs/client/CourierClient.js.map +1 -1
  22. package/lib/commonjs/client/InboxClient.js.map +1 -1
  23. package/lib/commonjs/client/PreferenceClient.js.map +1 -1
  24. package/lib/commonjs/client/TokenClient.js.map +1 -1
  25. package/lib/commonjs/client/TrackingClient.js.map +1 -1
  26. package/lib/commonjs/index.js +22 -2
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
  29. package/lib/commonjs/models/CourierPushListener.js.map +1 -1
  30. package/lib/commonjs/models/CourierUserPreferences.js +13 -13
  31. package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
  32. package/lib/commonjs/models/InboxAction.js.map +1 -1
  33. package/lib/commonjs/models/InboxMessage.js.map +1 -1
  34. package/lib/commonjs/utils.js.map +1 -1
  35. package/lib/commonjs/views/CourierInboxView.js +13 -13
  36. package/lib/commonjs/views/CourierInboxView.js.map +1 -1
  37. package/lib/commonjs/views/CourierPreferencesView.js +4 -4
  38. package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
  39. package/lib/module/Broadcaster.js +7 -7
  40. package/lib/module/Broadcaster.js.map +1 -1
  41. package/lib/module/CourierApiUrls.js +20 -0
  42. package/lib/module/CourierApiUrls.js.map +1 -0
  43. package/lib/module/Modules.js +1 -1
  44. package/lib/module/Modules.js.map +1 -1
  45. package/lib/module/client/BrandClient.js +1 -1
  46. package/lib/module/client/BrandClient.js.map +1 -1
  47. package/lib/module/client/ClientModule.js +1 -1
  48. package/lib/module/client/ClientModule.js.map +1 -1
  49. package/lib/module/client/CourierClient.js +10 -7
  50. package/lib/module/client/CourierClient.js.map +1 -1
  51. package/lib/module/client/InboxClient.js +1 -1
  52. package/lib/module/client/InboxClient.js.map +1 -1
  53. package/lib/module/client/PreferenceClient.js +1 -1
  54. package/lib/module/client/PreferenceClient.js.map +1 -1
  55. package/lib/module/client/TokenClient.js +1 -1
  56. package/lib/module/client/TokenClient.js.map +1 -1
  57. package/lib/module/client/TrackingClient.js +1 -1
  58. package/lib/module/client/TrackingClient.js.map +1 -1
  59. package/lib/module/index.js +5 -2
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/module/models/CourierAuthenticationListener.js +1 -1
  62. package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
  63. package/lib/module/models/CourierInboxListener.js +1 -1
  64. package/lib/module/models/CourierPushListener.js.map +1 -1
  65. package/lib/module/models/CourierUserPreferences.js +13 -13
  66. package/lib/module/models/CourierUserPreferences.js.map +1 -1
  67. package/lib/module/models/InboxAction.js.map +1 -1
  68. package/lib/module/models/InboxMessage.js +1 -1
  69. package/lib/module/models/InboxMessage.js.map +1 -1
  70. package/lib/module/utils.js.map +1 -1
  71. package/lib/module/views/CourierInboxView.js +18 -18
  72. package/lib/module/views/CourierInboxView.js.map +1 -1
  73. package/lib/module/views/CourierPreferencesView.js +7 -7
  74. package/lib/module/views/CourierPreferencesView.js.map +1 -1
  75. package/lib/typescript/src/Broadcaster.d.ts +7 -7
  76. package/lib/typescript/src/Broadcaster.d.ts.map +1 -1
  77. package/lib/typescript/src/CourierApiUrls.d.ts +11 -0
  78. package/lib/typescript/src/CourierApiUrls.d.ts.map +1 -0
  79. package/lib/typescript/src/Modules.d.ts.map +1 -1
  80. package/lib/typescript/src/client/BrandClient.d.ts +1 -1
  81. package/lib/typescript/src/client/BrandClient.d.ts.map +1 -1
  82. package/lib/typescript/src/client/ClientModule.d.ts +1 -1
  83. package/lib/typescript/src/client/ClientModule.d.ts.map +1 -1
  84. package/lib/typescript/src/client/CourierClient.d.ts +9 -6
  85. package/lib/typescript/src/client/CourierClient.d.ts.map +1 -1
  86. package/lib/typescript/src/client/InboxClient.d.ts +1 -1
  87. package/lib/typescript/src/client/InboxClient.d.ts.map +1 -1
  88. package/lib/typescript/src/client/PreferenceClient.d.ts +1 -1
  89. package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -1
  90. package/lib/typescript/src/client/TokenClient.d.ts +1 -1
  91. package/lib/typescript/src/client/TokenClient.d.ts.map +1 -1
  92. package/lib/typescript/src/client/TrackingClient.d.ts +1 -1
  93. package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -1
  94. package/lib/typescript/src/index.d.ts +6 -2
  95. package/lib/typescript/src/index.d.ts.map +1 -1
  96. package/lib/typescript/src/models/Android_CourierSheet.d.ts +1 -1
  97. package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -1
  98. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts +1 -1
  99. package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -1
  100. package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -1
  101. package/lib/typescript/src/models/CourierButton.d.ts +1 -1
  102. package/lib/typescript/src/models/CourierButton.d.ts.map +1 -1
  103. package/lib/typescript/src/models/CourierFont.d.ts.map +1 -1
  104. package/lib/typescript/src/models/CourierInboxListener.d.ts +1 -1
  105. package/lib/typescript/src/models/CourierInboxMessages.d.ts +1 -1
  106. package/lib/typescript/src/models/CourierInboxTheme.d.ts +3 -3
  107. package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -1
  108. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts +2 -2
  109. package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -1
  110. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts +6 -6
  111. package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -1
  112. package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -1
  113. package/lib/typescript/src/models/CourierUserPreferences.d.ts +1 -1
  114. package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -1
  115. package/lib/typescript/src/models/InboxAction.d.ts.map +1 -1
  116. package/lib/typescript/src/models/InboxMessage.d.ts +1 -1
  117. package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -1
  118. package/lib/typescript/src/models/InboxMessageEvent.d.ts.map +1 -1
  119. package/lib/typescript/src/models/InboxMessageSet.d.ts +1 -1
  120. package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -1
  121. package/lib/typescript/src/models/iOS_CourierSheet.d.ts +1 -1
  122. package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -1
  123. package/lib/typescript/src/utils.d.ts.map +1 -1
  124. package/lib/typescript/src/views/CourierInboxView.d.ts +5 -5
  125. package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -1
  126. package/lib/typescript/src/views/CourierPreferencesView.d.ts +3 -3
  127. package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -1
  128. package/package.json +8 -4
  129. package/src/Broadcaster.tsx +21 -15
  130. package/src/CourierApiUrls.tsx +30 -0
  131. package/src/Modules.tsx +22 -13
  132. package/src/client/BrandClient.tsx +6 -6
  133. package/src/client/ClientModule.tsx +4 -6
  134. package/src/client/CourierClient.tsx +20 -13
  135. package/src/client/InboxClient.tsx +40 -13
  136. package/src/client/PreferenceClient.tsx +47 -21
  137. package/src/client/TokenClient.tsx +14 -7
  138. package/src/client/TrackingClient.tsx +7 -6
  139. package/src/index.tsx +208 -115
  140. package/src/models/Android_CourierSheet.tsx +5 -5
  141. package/src/models/CourierAuthenticationListener.tsx +5 -9
  142. package/src/models/CourierBrand.tsx +6 -6
  143. package/src/models/CourierButton.tsx +5 -5
  144. package/src/models/CourierDevice.tsx +1 -1
  145. package/src/models/CourierFont.tsx +4 -4
  146. package/src/models/CourierInboxListener.tsx +3 -3
  147. package/src/models/CourierInboxMessages.tsx +2 -2
  148. package/src/models/CourierInboxTheme.tsx +55 -42
  149. package/src/models/CourierInfoViewStyle.tsx +5 -5
  150. package/src/models/CourierPaging.tsx +1 -1
  151. package/src/models/CourierPreferencesTheme.tsx +32 -27
  152. package/src/models/CourierPushListener.tsx +9 -7
  153. package/src/models/CourierPushProvider.tsx +1 -1
  154. package/src/models/CourierTrackingEvent.tsx +6 -6
  155. package/src/models/CourierUserPreferences.tsx +32 -28
  156. package/src/models/InboxAction.tsx +2 -6
  157. package/src/models/InboxMessage.tsx +4 -5
  158. package/src/models/InboxMessageEvent.tsx +7 -1
  159. package/src/models/InboxMessageFeed.tsx +1 -1
  160. package/src/models/InboxMessageSet.tsx +1 -1
  161. package/src/models/iOS_CourierCell.tsx +10 -5
  162. package/src/models/iOS_CourierSheet.tsx +4 -4
  163. package/src/utils.tsx +4 -7
  164. package/src/views/CourierInboxView.tsx +79 -71
  165. package/src/views/CourierPreferencesView.tsx +34 -35
  166. package/lib/example/src/App.js +0 -11
  167. package/lib/example/src/Emitter.js +0 -11
  168. package/lib/example/src/Env.js +0 -6
  169. package/lib/example/src/Home.js +0 -67
  170. package/lib/example/src/Poke.js +0 -75
  171. package/lib/example/src/Tabs.js +0 -36
  172. package/lib/example/src/Utils.js +0 -71
  173. package/lib/example/src/pages/Auth.js +0 -224
  174. package/lib/example/src/pages/Inbox.js +0 -38
  175. package/lib/example/src/pages/Preferences.js +0 -13
  176. package/lib/example/src/pages/PreferencesStack.js +0 -11
  177. package/lib/example/src/pages/Push.js +0 -93
  178. package/lib/example/src/pages/Styles.js +0 -26
  179. package/lib/example/src/pages/Tests.js +0 -1068
  180. package/lib/example/src/pages/inbox/InboxCustom.js +0 -141
  181. package/lib/example/src/pages/inbox/InboxDefault.js +0 -22
  182. package/lib/example/src/pages/inbox/InboxStyled.js +0 -220
  183. package/lib/example/src/pages/preferences/PreferencesCustom.js +0 -91
  184. package/lib/example/src/pages/preferences/PreferencesDefault.js +0 -17
  185. package/lib/example/src/pages/preferences/PreferencesDetail.js +0 -127
  186. package/lib/example/src/pages/preferences/PreferencesStyled.js +0 -110
  187. package/lib/package.json +0 -171
  188. package/lib/src/Broadcaster.js +0 -24
  189. package/lib/src/Modules.js +0 -26
  190. package/lib/src/client/BrandClient.js +0 -17
  191. package/lib/src/client/ClientModule.js +0 -14
  192. package/lib/src/client/CourierClient.js +0 -31
  193. package/lib/src/client/InboxClient.js +0 -99
  194. package/lib/src/client/PreferenceClient.js +0 -63
  195. package/lib/src/client/TokenClient.js +0 -27
  196. package/lib/src/client/TrackingClient.js +0 -17
  197. package/lib/src/index.js +0 -567
  198. package/lib/src/models/Android_CourierSheet.js +0 -1
  199. package/lib/src/models/CourierAuthenticationListener.js +0 -14
  200. package/lib/src/models/CourierBrand.js +0 -1
  201. package/lib/src/models/CourierButton.js +0 -1
  202. package/lib/src/models/CourierDevice.js +0 -1
  203. package/lib/src/models/CourierFont.js +0 -1
  204. package/lib/src/models/CourierInboxListener.js +0 -20
  205. package/lib/src/models/CourierInboxMessages.js +0 -1
  206. package/lib/src/models/CourierInboxTheme.js +0 -1
  207. package/lib/src/models/CourierInfoViewStyle.js +0 -1
  208. package/lib/src/models/CourierPaging.js +0 -1
  209. package/lib/src/models/CourierPreferencesTheme.js +0 -1
  210. package/lib/src/models/CourierPushListener.js +0 -14
  211. package/lib/src/models/CourierPushProvider.js +0 -8
  212. package/lib/src/models/CourierTrackingEvent.js +0 -8
  213. package/lib/src/models/CourierUserPreferences.js +0 -51
  214. package/lib/src/models/InboxAction.js +0 -1
  215. package/lib/src/models/InboxMessage.js +0 -1
  216. package/lib/src/models/InboxMessageFeed.js +0 -1
  217. package/lib/src/models/InboxMessageSet.js +0 -1
  218. package/lib/src/models/iOS_CourierCell.js +0 -1
  219. package/lib/src/models/iOS_CourierSheet.js +0 -1
  220. package/lib/src/utils.js +0 -27
  221. package/lib/src/views/CourierInboxView.js +0 -75
  222. package/lib/src/views/CourierPreferencesView.js +0 -33
@@ -1,19 +1,31 @@
1
- import React, { useEffect } from "react";
2
- import { Platform, ViewStyle, DeviceEventEmitter, EmitterSubscription } from "react-native";
3
- import { InboxAction } from "../models/InboxAction";
4
- import { InboxMessage } from "../models/InboxMessage";
5
- import { CourierInboxTheme } from "../models/CourierInboxTheme";
6
- import { Modules } from "../Modules";
1
+ import React, { useEffect } from 'react';
2
+ import {
3
+ Platform,
4
+ ViewStyle,
5
+ DeviceEventEmitter,
6
+ EmitterSubscription,
7
+ } from 'react-native';
8
+ import { InboxAction } from '../models/InboxAction';
9
+ import { InboxMessage } from '../models/InboxMessage';
10
+ import { CourierInboxTheme } from '../models/CourierInboxTheme';
11
+ import { Modules } from '../Modules';
7
12
 
8
13
  type CourierInboxViewProps = {
9
- canSwipePages?: boolean,
10
- theme?: {
11
- light?: CourierInboxTheme,
12
- dark?: CourierInboxTheme
14
+ canSwipePages?: boolean;
15
+ theme?: {
16
+ light?: CourierInboxTheme;
17
+ dark?: CourierInboxTheme;
13
18
  };
14
19
  onClickInboxMessageAtIndex?: (message: InboxMessage, index: number) => void;
15
- onLongPressInboxMessageAtIndex?: (message: InboxMessage, index: number) => void;
16
- onClickInboxActionForMessageAtIndex?: (action: InboxAction, message: InboxMessage, index: number) => void;
20
+ onLongPressInboxMessageAtIndex?: (
21
+ message: InboxMessage,
22
+ index: number
23
+ ) => void;
24
+ onClickInboxActionForMessageAtIndex?: (
25
+ action: InboxAction,
26
+ message: InboxMessage,
27
+ index: number
28
+ ) => void;
17
29
  onScrollInbox?: (offsetY: number, offsetX: number) => void;
18
30
  style?: ViewStyle;
19
31
  };
@@ -21,128 +33,124 @@ type CourierInboxViewProps = {
21
33
  const CourierInbox = Modules.getNativeComponent('CourierInboxView');
22
34
 
23
35
  export const CourierInboxView = (props: CourierInboxViewProps) => {
24
-
25
- let onClickInboxMessageAtIndexListener: EmitterSubscription | undefined = undefined;
26
- let onLongPressInboxMessageAtIndexListener: EmitterSubscription | undefined = undefined;
27
- let onClickInboxActionForMessageAtIndexListener: EmitterSubscription | undefined = undefined;
28
- let onScrollInboxListener: EmitterSubscription | undefined = undefined;
36
+ let onClickInboxMessageAtIndexListener: EmitterSubscription | undefined;
37
+ let onLongPressInboxMessageAtIndexListener: EmitterSubscription | undefined;
38
+ let onClickInboxActionForMessageAtIndexListener:
39
+ | EmitterSubscription
40
+ | undefined;
41
+ let onScrollInboxListener: EmitterSubscription | undefined;
29
42
 
30
43
  useEffect(() => {
31
-
32
44
  return () => {
33
45
  onClickInboxMessageAtIndexListener?.remove();
34
46
  onLongPressInboxMessageAtIndexListener?.remove();
35
47
  onClickInboxActionForMessageAtIndexListener?.remove();
36
48
  onScrollInboxListener?.remove();
37
- }
38
-
49
+ };
39
50
  }, []);
40
51
 
41
52
  useEffect(() => {
42
-
43
53
  onClickInboxMessageAtIndexListener?.remove();
44
54
 
45
55
  if (Platform.OS === 'android' && props.onClickInboxMessageAtIndex) {
46
- onClickInboxMessageAtIndexListener = DeviceEventEmitter.addListener('courierClickMessageAtIndex', onClickInboxMessageAtIndex);
56
+ onClickInboxMessageAtIndexListener = DeviceEventEmitter.addListener(
57
+ 'courierClickMessageAtIndex',
58
+ onClickInboxMessageAtIndex
59
+ );
47
60
  }
48
-
49
61
  }, [props.onClickInboxMessageAtIndex]);
50
62
 
51
63
  const onClickInboxMessageAtIndex = (event: any) => {
52
-
53
64
  // Parse the native event data
54
65
  if (props.onClickInboxMessageAtIndex) {
55
-
56
- const index = event["index"];
57
- const message = InboxMessage.fromJson(event["message"]);
66
+ const index = event.index;
67
+ const message = InboxMessage.fromJson(event.message);
58
68
 
59
69
  props.onClickInboxMessageAtIndex(message, index);
60
-
61
70
  }
62
-
63
- }
71
+ };
64
72
 
65
73
  useEffect(() => {
66
-
67
74
  onLongPressInboxMessageAtIndexListener?.remove();
68
75
 
69
76
  if (Platform.OS === 'android' && props.onLongPressInboxMessageAtIndex) {
70
- onLongPressInboxMessageAtIndexListener = DeviceEventEmitter.addListener('courierLongPressMessageAtIndex', onLongPressInboxMessageAtIndex);
77
+ onLongPressInboxMessageAtIndexListener = DeviceEventEmitter.addListener(
78
+ 'courierLongPressMessageAtIndex',
79
+ onLongPressInboxMessageAtIndex
80
+ );
71
81
  }
72
-
73
82
  }, [props.onLongPressInboxMessageAtIndex]);
74
83
 
75
84
  const onLongPressInboxMessageAtIndex = (event: any) => {
76
-
77
85
  // Parse the native event data
78
86
  if (props.onLongPressInboxMessageAtIndex) {
79
-
80
- const index = event["index"];
81
- const message = InboxMessage.fromJson(event["message"]);
87
+ const index = event.index;
88
+ const message = InboxMessage.fromJson(event.message);
82
89
 
83
90
  props.onLongPressInboxMessageAtIndex(message, index);
84
-
85
91
  }
86
-
87
- }
92
+ };
88
93
 
89
94
  useEffect(() => {
90
-
91
95
  onClickInboxActionForMessageAtIndexListener?.remove();
92
96
 
93
- if (Platform.OS === 'android' && props.onClickInboxActionForMessageAtIndex) {
94
- onClickInboxActionForMessageAtIndexListener = DeviceEventEmitter.addListener('courierClickActionAtIndex', onClickInboxActionForMessageAtIndex);
97
+ if (
98
+ Platform.OS === 'android' &&
99
+ props.onClickInboxActionForMessageAtIndex
100
+ ) {
101
+ onClickInboxActionForMessageAtIndexListener =
102
+ DeviceEventEmitter.addListener(
103
+ 'courierClickActionAtIndex',
104
+ onClickInboxActionForMessageAtIndex
105
+ );
95
106
  }
96
-
97
107
  }, [props.onClickInboxActionForMessageAtIndex]);
98
108
 
99
109
  const onClickInboxActionForMessageAtIndex = (event: any) => {
100
-
101
110
  // Parse the native event data
102
111
  if (props.onClickInboxActionForMessageAtIndex) {
103
-
104
- const index = event["index"];
105
- const action = InboxAction.fromJson(event["action"]);
106
- const message = InboxMessage.fromJson(event["message"]);
112
+ const index = event.index;
113
+ const action = InboxAction.fromJson(event.action);
114
+ const message = InboxMessage.fromJson(event.message);
107
115
 
108
116
  props.onClickInboxActionForMessageAtIndex(action, message, index);
109
-
110
117
  }
111
-
112
- }
118
+ };
113
119
 
114
120
  useEffect(() => {
115
-
116
121
  onScrollInboxListener?.remove();
117
122
 
118
123
  if (Platform.OS === 'android' && props.onScrollInbox) {
119
- onScrollInboxListener = DeviceEventEmitter.addListener('courierScrollInbox', onScrollInbox);
124
+ onScrollInboxListener = DeviceEventEmitter.addListener(
125
+ 'courierScrollInbox',
126
+ onScrollInbox
127
+ );
120
128
  }
121
-
122
- }, [props.onScrollInbox])
129
+ }, [props.onScrollInbox]);
123
130
 
124
131
  const onScrollInbox = (event: any) => {
125
-
126
132
  // Parse the native event data
127
133
  if (props.onScrollInbox) {
128
-
129
- const contentOffset = event["contentOffset"];
130
- props.onScrollInbox(contentOffset["y"], contentOffset["x"]);
131
-
134
+ const contentOffset = event.contentOffset;
135
+ props.onScrollInbox(contentOffset.y, contentOffset.x);
132
136
  }
133
-
134
- }
137
+ };
135
138
 
136
139
  return (
137
- <CourierInbox
140
+ <CourierInbox
138
141
  canSwipePages={props.canSwipePages ?? false}
139
- theme={props.theme ?? { light: undefined, dark: undefined }}
140
- onClickInboxMessageAtIndex={(event: any) => onClickInboxMessageAtIndex(event.nativeEvent)}
141
- onLongPressInboxMessageAtIndex={(event: any) => onLongPressInboxMessageAtIndex(event.nativeEvent)}
142
- onClickInboxActionForMessageAtIndex={(event: any) => onClickInboxActionForMessageAtIndex(event.nativeEvent)}
142
+ theme={props.theme ?? { light: undefined, dark: undefined }}
143
+ onClickInboxMessageAtIndex={(event: any) =>
144
+ onClickInboxMessageAtIndex(event.nativeEvent)
145
+ }
146
+ onLongPressInboxMessageAtIndex={(event: any) =>
147
+ onLongPressInboxMessageAtIndex(event.nativeEvent)
148
+ }
149
+ onClickInboxActionForMessageAtIndex={(event: any) =>
150
+ onClickInboxActionForMessageAtIndex(event.nativeEvent)
151
+ }
143
152
  onScrollInbox={(event: any) => onScrollInbox(event.nativeEvent)}
144
153
  style={props.style}
145
154
  />
146
- )
147
-
148
- }
155
+ );
156
+ };
@@ -1,13 +1,21 @@
1
- import React, { useEffect } from "react";
2
- import { DeviceEventEmitter, EmitterSubscription, Platform, ViewStyle } from "react-native";
3
- import { CourierPreferencesMode, CourierPreferencesTheme } from "../models/CourierPreferencesTheme";
4
- import { Modules } from "../Modules";
1
+ import React, { useEffect } from 'react';
2
+ import {
3
+ DeviceEventEmitter,
4
+ EmitterSubscription,
5
+ Platform,
6
+ ViewStyle,
7
+ } from 'react-native';
8
+ import {
9
+ CourierPreferencesMode,
10
+ CourierPreferencesTheme,
11
+ } from '../models/CourierPreferencesTheme';
12
+ import { Modules } from '../Modules';
5
13
 
6
14
  type CourierPreferencesProps = {
7
- mode?: CourierPreferencesMode,
8
- theme?: {
9
- light?: CourierPreferencesTheme,
10
- dark?: CourierPreferencesTheme
15
+ mode?: CourierPreferencesMode;
16
+ theme?: {
17
+ light?: CourierPreferencesTheme;
18
+ dark?: CourierPreferencesTheme;
11
19
  };
12
20
  onScrollPreferences?: (offsetY: number, offsetX: number) => void;
13
21
  onPreferenceError?: (message: string) => void;
@@ -17,59 +25,50 @@ type CourierPreferencesProps = {
17
25
  const CourierPreferences = Modules.getNativeComponent('CourierPreferencesView');
18
26
 
19
27
  export const CourierPreferencesView = (props: CourierPreferencesProps) => {
20
-
21
- let onScrollPreferencesListener: EmitterSubscription | undefined = undefined;
28
+ let onScrollPreferencesListener: EmitterSubscription | undefined;
22
29
 
23
30
  useEffect(() => {
24
-
25
31
  return () => {
26
32
  onScrollPreferencesListener?.remove();
27
- }
28
-
33
+ };
29
34
  }, []);
30
35
 
31
36
  useEffect(() => {
32
-
33
37
  onScrollPreferencesListener?.remove();
34
38
 
35
39
  if (Platform.OS === 'android' && props.onScrollPreferences) {
36
- onScrollPreferencesListener = DeviceEventEmitter.addListener('courierScrollPreferences', onScrollPreferences);
40
+ onScrollPreferencesListener = DeviceEventEmitter.addListener(
41
+ 'courierScrollPreferences',
42
+ onScrollPreferences
43
+ );
37
44
  }
38
-
39
- }, [props.onScrollPreferences])
45
+ }, [props.onScrollPreferences]);
40
46
 
41
47
  const onScrollPreferences = (event: any) => {
42
-
43
48
  // Parse the native event data
44
49
  if (props.onScrollPreferences) {
45
-
46
- const contentOffset = event["contentOffset"];
47
- props.onScrollPreferences(contentOffset["y"], contentOffset["x"]);
48
-
50
+ const contentOffset = event.contentOffset;
51
+ props.onScrollPreferences(contentOffset.y, contentOffset.x);
49
52
  }
50
-
51
- }
53
+ };
52
54
 
53
55
  const onPreferenceError = (event: any) => {
54
-
55
56
  // Parse the native event data
56
57
  if (props.onPreferenceError) {
57
-
58
- const message = event["error"];
58
+ const message = event.error;
59
59
  props.onPreferenceError(message);
60
-
61
60
  }
62
-
63
- }
61
+ };
64
62
 
65
63
  return (
66
- <CourierPreferences
64
+ <CourierPreferences
67
65
  mode={props.mode}
68
66
  theme={props.theme ?? { light: undefined, dark: undefined }}
69
- onScrollPreferences={(event: any) => onScrollPreferences(event.nativeEvent)}
67
+ onScrollPreferences={(event: any) =>
68
+ onScrollPreferences(event.nativeEvent)
69
+ }
70
70
  onPreferenceError={(event: any) => onPreferenceError(event.nativeEvent)}
71
71
  style={props.style}
72
72
  />
73
- )
74
-
75
- }
73
+ );
74
+ };
@@ -1,11 +0,0 @@
1
- import { NavigationContainer } from '@react-navigation/native';
2
- import React from 'react';
3
- import Home from './Home';
4
- import Toast from 'react-native-toast-message';
5
- import { Poke } from './Poke';
6
- export default function App() {
7
- return (React.createElement(Poke, { initialEnabled: false },
8
- React.createElement(NavigationContainer, null,
9
- React.createElement(Home, null),
10
- React.createElement(Toast, null))));
11
- }
@@ -1,11 +0,0 @@
1
- import EventEmitter from 'eventemitter3';
2
- const eventEmitter = new EventEmitter();
3
- export function emitEvent(eventName, eventData) {
4
- eventEmitter.emit(eventName, eventData);
5
- }
6
- export function addListener(eventName, listener) {
7
- eventEmitter.on(eventName, listener);
8
- }
9
- export function removeListener(eventName, listener) {
10
- eventEmitter.off(eventName, listener);
11
- }
@@ -1,6 +0,0 @@
1
- export default class Env {
2
- static brandId = 'MX9K96KBP84ZF8JAVKN5F45Q1EVE';
3
- static authKey = 'pk_prod_NGYE57FM5M4P3MKPTVQDQD9KPPN2';
4
- static clientKey = 'YzM1YmFiYjUtZjA2My00NGU3LWEyODYtODU3ODUyNDNmYTcw';
5
- static topicId = '35K24W99WCME21MRG7X2BPDF6CK7';
6
- }
@@ -1,67 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
3
- import { Alert, Button } from 'react-native';
4
- import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
5
- import Auth from './pages/Auth';
6
- import Push from './pages/Push';
7
- import Inbox from './pages/Inbox';
8
- import Courier from '@trycourier/courier-react-native';
9
- import PreferencesStack from './pages/PreferencesStack';
10
- import Tests from './pages/Tests';
11
- const Tab = createBottomTabNavigator();
12
- const Home = () => {
13
- const [unreadCount, setUnreadCount] = useState(0);
14
- useEffect(() => {
15
- const setupInbox = async () => {
16
- // Setup Push
17
- Courier.setIOSForegroundPresentationOptions({ options: ['sound', 'badge', 'list', 'banner'] });
18
- const pushListener = Courier.shared.addPushNotificationListener({
19
- onPushNotificationClicked(push) {
20
- console.log(push);
21
- Alert.alert('👆 Push Notification Clicked', JSON.stringify(push));
22
- },
23
- onPushNotificationDelivered(push) {
24
- console.log(push);
25
- Alert.alert('📬 Push Notification Delivered', JSON.stringify(push));
26
- }
27
- });
28
- // Setup Inbox
29
- await Courier.shared.setInboxPaginationLimit(100);
30
- const inboxListener = await Courier.shared.addInboxListener({
31
- onUnreadCountChanged(unreadCount) {
32
- setUnreadCount(unreadCount);
33
- },
34
- });
35
- return { pushListener, inboxListener };
36
- };
37
- const listeners = setupInbox();
38
- return () => {
39
- listeners.then(({ pushListener, inboxListener }) => {
40
- pushListener.remove();
41
- inboxListener.remove();
42
- });
43
- };
44
- }, []);
45
- const inboxOptions = () => {
46
- const badgeCount = () => {
47
- return unreadCount > 0 ? unreadCount : undefined;
48
- };
49
- return {
50
- headerRight: () => (React.createElement(Button, { onPress: () => Courier.shared.readAllInboxMessages(), title: "Read All" })),
51
- tabBarBadge: badgeCount(),
52
- tabBarIcon: ({ color, size }) => (React.createElement(MaterialCommunityIcons, { name: 'bell', color: color, size: size }))
53
- };
54
- };
55
- const icon = (icon) => {
56
- return {
57
- tabBarIcon: ({ color, size }) => (React.createElement(MaterialCommunityIcons, { name: icon, color: color, size: size }))
58
- };
59
- };
60
- return (React.createElement(Tab.Navigator, null,
61
- React.createElement(Tab.Screen, { name: "Auth", component: Auth, options: icon('account-circle') }),
62
- React.createElement(Tab.Screen, { name: "Push", component: Push, options: icon('message-badge') }),
63
- React.createElement(Tab.Screen, { name: "Inbox", component: Inbox, options: inboxOptions() }),
64
- React.createElement(Tab.Screen, { name: "Preferences", component: PreferencesStack, options: { ...icon('wrench'), headerShown: false } }),
65
- React.createElement(Tab.Screen, { name: "Tests", component: Tests, options: icon('test-tube') })));
66
- };
67
- export default Home;
@@ -1,75 +0,0 @@
1
- import React, { useState, useEffect, useMemo, createContext, useContext } from 'react';
2
- import { View, StyleSheet, Animated, Easing } from 'react-native';
3
- const PokeContext = createContext(undefined);
4
- export const usePoke = () => {
5
- const context = useContext(PokeContext);
6
- if (!context) {
7
- throw new Error('usePoke must be used within a PokeProvider');
8
- }
9
- return context;
10
- };
11
- export const Poke = ({ children, initialEnabled = true, initialIndicatorStyle, initialTouchTimeout = 150, }) => {
12
- const [enabled, setEnabled] = useState(initialEnabled);
13
- const [indicatorStyle, setIndicatorStyle] = useState(initialIndicatorStyle || {});
14
- const [touchTimeout, setTouchTimeout] = useState(initialTouchTimeout);
15
- const contextValue = useMemo(() => ({
16
- setEnabled,
17
- setIndicatorStyle,
18
- setTouchTimeout,
19
- }), []);
20
- return (React.createElement(PokeContext.Provider, { value: contextValue },
21
- React.createElement(TouchIndicator, { enabled: enabled, indicatorStyle: indicatorStyle, touchTimeout: touchTimeout }, children)));
22
- };
23
- const TouchIndicator = ({ children, indicatorStyle, enabled, touchTimeout }) => {
24
- const [latestTouch, setLatestTouch] = useState(null);
25
- const indicatorSize = indicatorStyle?.size || 50;
26
- const indicatorColor = indicatorStyle?.color || 'rgba(0, 122, 255, 0.4)'; // Default blue color
27
- useEffect(() => {
28
- if (latestTouch) {
29
- const timer = setTimeout(() => {
30
- setLatestTouch(null);
31
- }, touchTimeout);
32
- return () => clearTimeout(timer);
33
- }
34
- return () => { }; // Add this line
35
- }, [latestTouch, touchTimeout]);
36
- const handleTouch = (event) => {
37
- if (!enabled)
38
- return;
39
- const touch = event.nativeEvent.touches[0]; // Get only the latest touch
40
- if (touch) {
41
- const newTouch = {
42
- id: `${touch.identifier}-${Date.now()}`,
43
- x: touch.pageX,
44
- y: touch.pageY,
45
- timestamp: Date.now(),
46
- animation: new Animated.Value(1),
47
- };
48
- Animated.timing(newTouch.animation, {
49
- toValue: 0,
50
- duration: touchTimeout,
51
- useNativeDriver: true,
52
- easing: Easing.out(Easing.cubic),
53
- }).start();
54
- setLatestTouch(newTouch);
55
- }
56
- };
57
- const touchIndicatorStyle = useMemo(() => ({
58
- position: 'absolute',
59
- width: indicatorSize,
60
- height: indicatorSize,
61
- borderRadius: indicatorSize / 2,
62
- backgroundColor: indicatorColor,
63
- zIndex: 9999,
64
- }), [indicatorSize, indicatorColor]);
65
- return (React.createElement(View, { style: StyleSheet.absoluteFill, onTouchStart: handleTouch, onTouchMove: handleTouch, onTouchEnd: handleTouch },
66
- children,
67
- enabled && latestTouch && (React.createElement(Animated.View, { key: latestTouch.id, style: [
68
- touchIndicatorStyle,
69
- {
70
- left: latestTouch.x - indicatorSize / 2,
71
- top: latestTouch.y - indicatorSize / 2,
72
- opacity: latestTouch.animation,
73
- },
74
- ] }))));
75
- };
@@ -1,36 +0,0 @@
1
- import React from "react";
2
- import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
3
- export const Tab = ({ title, isSelected, onPress }) => (React.createElement(TouchableOpacity, { onPress: onPress, style: [styles.tabButton, isSelected && styles.selectedTabButton] },
4
- React.createElement(Text, { style: [styles.tabText, isSelected && styles.selectedTabText] }, title)));
5
- export const TabControl = ({ tabs, selectedTab, setSelectedTab }) => (React.createElement(View, { style: styles.segmentedControl }, tabs.map((tab) => (React.createElement(Tab, { key: tab.key, title: tab.title, isSelected: selectedTab === tab.key, onPress: () => setSelectedTab(tab.key) })))));
6
- const styles = StyleSheet.create({
7
- container: {
8
- flex: 1,
9
- },
10
- segmentedControl: {
11
- flexDirection: 'row',
12
- justifyContent: 'space-around',
13
- width: '100%',
14
- },
15
- content: {
16
- flex: 1,
17
- width: '100%',
18
- height: '100%',
19
- },
20
- tabButton: {
21
- padding: 16,
22
- flex: 1,
23
- alignItems: 'center',
24
- borderBottomWidth: 2,
25
- borderBottomColor: 'transparent',
26
- },
27
- selectedTabButton: {
28
- borderBottomColor: 'blue',
29
- },
30
- tabText: {
31
- color: 'black',
32
- },
33
- selectedTabText: {
34
- fontWeight: 'bold',
35
- },
36
- });
@@ -1,71 +0,0 @@
1
- export class ExampleServer {
2
- static async generateJwt(props) {
3
- return new Promise((resolve, reject) => {
4
- const url = 'https://api.courier.com/auth/issue-token';
5
- const request = {
6
- method: 'POST',
7
- headers: {
8
- 'Content-Type': 'application/json',
9
- 'Authorization': `Bearer ${props.authKey}`
10
- },
11
- body: JSON.stringify({
12
- scope: `user_id:${props.userId} write:user-tokens inbox:read:messages inbox:write:events read:preferences write:preferences read:brands`,
13
- expires_in: '2 days'
14
- })
15
- };
16
- fetch(url, request)
17
- .then(response => response.json())
18
- .then((data) => {
19
- resolve(data.token);
20
- })
21
- .catch(error => {
22
- reject(error);
23
- });
24
- });
25
- }
26
- static async sendTest(props) {
27
- const url = 'https://api.courier.com/send';
28
- const headers = {
29
- 'Content-Type': 'application/json',
30
- 'Authorization': `Bearer ${props.authKey}`,
31
- };
32
- const body = JSON.stringify({
33
- 'message': {
34
- 'to': {
35
- 'user_id': props.userId
36
- },
37
- 'content': {
38
- 'title': props.title ?? 'Test',
39
- 'body': props.body ?? 'Body',
40
- },
41
- 'routing': {
42
- 'method': 'all',
43
- 'channels': [props.channel],
44
- },
45
- },
46
- });
47
- const response = await fetch(url, {
48
- method: 'POST',
49
- headers: headers,
50
- body: body,
51
- });
52
- if (response.status === 202) {
53
- const json = await response.json();
54
- return json['requestId'] ?? 'Error';
55
- }
56
- else {
57
- throw new Error('Failed to send test message');
58
- }
59
- }
60
- }
61
- export class Utils {
62
- static generateUUID() {
63
- let uuid = '';
64
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
65
- const charactersLength = characters.length;
66
- for (let i = 0; i < 16; i++) {
67
- uuid += characters.charAt(Math.floor(Math.random() * charactersLength));
68
- }
69
- return uuid;
70
- }
71
- }