@trycourier/courier-react-native 1.0.8 → 2.0.0-beta0

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 (89) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -416
  3. package/android/build.gradle +48 -83
  4. package/android/src/main/AndroidManifest.xml +0 -1
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/com/courierreactnative/CourierReactNativeActivity.kt +10 -10
  7. package/android/src/main/java/com/courierreactnative/CourierReactNativeModule.kt +146 -139
  8. package/android/src/main/java/com/courierreactnative/CourierReactNativePackage.kt +1 -3
  9. package/android/src/main/java/com/courierreactnative/CourierReactNativeViewManager.kt +43 -0
  10. package/courier-react-native.podspec +12 -4
  11. package/ios/CourierReactNative-Bridging-Header.h +0 -1
  12. package/ios/CourierReactNative.xcodeproj/project.pbxproj +4 -4
  13. package/ios/CourierReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  14. package/ios/CourierReactNativeModule.m +48 -0
  15. package/ios/{CourierReactNative.swift → CourierReactNativeModule.swift} +167 -48
  16. package/ios/CourierReactNativeViewManager.m +15 -0
  17. package/ios/CourierReactNativeViewManager.swift +348 -0
  18. package/lib/commonjs/index.js +68 -215
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/models/CourierInboxListener.js +26 -0
  21. package/lib/commonjs/models/CourierInboxListener.js.map +1 -0
  22. package/lib/commonjs/models/CourierInboxTheme.js +2 -0
  23. package/lib/commonjs/models/CourierInboxTheme.js.map +1 -0
  24. package/lib/commonjs/models/InboxAction.js +2 -0
  25. package/lib/commonjs/models/InboxAction.js.map +1 -0
  26. package/lib/commonjs/models/InboxMessage.js +6 -0
  27. package/lib/commonjs/models/InboxMessage.js.map +1 -0
  28. package/lib/commonjs/views/CourierInboxView.js +53 -0
  29. package/lib/commonjs/views/CourierInboxView.js.map +1 -0
  30. package/lib/module/index.js +62 -214
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/models/CourierInboxListener.js +18 -0
  33. package/lib/module/models/CourierInboxListener.js.map +1 -0
  34. package/lib/module/models/CourierInboxTheme.js +2 -0
  35. package/lib/module/models/CourierInboxTheme.js.map +1 -0
  36. package/lib/module/models/InboxAction.js +2 -0
  37. package/lib/module/models/InboxAction.js.map +1 -0
  38. package/lib/module/models/InboxMessage.js +2 -0
  39. package/lib/module/models/InboxMessage.js.map +1 -0
  40. package/lib/module/views/CourierInboxView.js +45 -0
  41. package/lib/module/views/CourierInboxView.js.map +1 -0
  42. package/lib/typescript/index.d.ts +34 -94
  43. package/lib/typescript/index.d.ts.map +1 -0
  44. package/lib/typescript/models/CourierInboxListener.d.ts +9 -0
  45. package/lib/typescript/models/CourierInboxListener.d.ts.map +1 -0
  46. package/lib/typescript/models/CourierInboxTheme.d.ts +34 -0
  47. package/lib/typescript/models/CourierInboxTheme.d.ts.map +1 -0
  48. package/lib/typescript/models/InboxAction.d.ts +8 -0
  49. package/lib/typescript/models/InboxAction.d.ts.map +1 -0
  50. package/lib/typescript/models/InboxMessage.d.ts +18 -0
  51. package/lib/typescript/models/InboxMessage.d.ts.map +1 -0
  52. package/lib/typescript/views/CourierInboxView.d.ts +16 -0
  53. package/lib/typescript/views/CourierInboxView.d.ts.map +1 -0
  54. package/package.json +61 -44
  55. package/src/index.tsx +188 -0
  56. package/src/models/CourierInboxListener.tsx +25 -0
  57. package/src/models/CourierInboxTheme.tsx +30 -0
  58. package/src/models/InboxAction.tsx +5 -0
  59. package/src/models/InboxMessage.tsx +16 -0
  60. package/src/views/CourierInboxView.tsx +85 -0
  61. package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  62. package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
  63. package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
  64. package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
  65. package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
  66. package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
  67. package/android/.gradle/7.1/gc.properties +0 -0
  68. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  69. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  70. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  71. package/android/.gradle/checksums/checksums.lock +0 -0
  72. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  73. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  74. package/android/.gradle/vcs-1/gc.properties +0 -0
  75. package/android/.idea/compiler.xml +0 -6
  76. package/android/.idea/gradle.xml +0 -17
  77. package/android/.idea/jarRepositories.xml +0 -35
  78. package/android/.idea/misc.xml +0 -10
  79. package/android/.idea/vcs.xml +0 -6
  80. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  81. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  82. package/android/gradlew +0 -185
  83. package/android/gradlew.bat +0 -89
  84. package/android/local.properties +0 -8
  85. package/android/src/main/java/com/courierreactnative/NotificationPermissionStatus.kt +0 -6
  86. package/ios/CourierReactNative.m +0 -53
  87. package/ios/CourierReactNativeDelegate.h +0 -20
  88. package/ios/CourierReactNativeDelegate.m +0 -125
  89. package/src/index.ts +0 -341
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 FahadAminShovon
3
+ Copyright (c) 2023 mikemilla
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
6
6
  in the Software without restriction, including without limitation the rights
package/README.md CHANGED
@@ -1,431 +1,31 @@
1
- # Courier React Native Overview
1
+ # courier-react-native
2
2
 
3
- ```ts
4
- import Courier, { CourierProvider } from '@trycourier/courier-react-native'
3
+ Inbox & Push Notifications for iOS
5
4
 
6
- await Courier.setIsDebugging(true);
5
+ ## Installation
7
6
 
8
- const userId = await Courier.userId;
9
-
10
- await Courier.signIn({
11
- accessToken: 'asdf...',
12
- userId: 'example_user_id',
13
- });
14
-
15
- await Courier.signOut();
16
-
17
- await Courier.iOSForegroundPresentationOptions({
18
- options: ['badge', 'banner', 'list', 'sound'],
19
- });
20
-
21
- const currentPermissionStatus = await Courier.notificationPermissionStatus;
22
- const requestNotificationPermission = await Courier.requestNotificationPermission();
23
-
24
- await Courier.setFcmToken('asdf...');
25
-
26
- const fcmToken = await Courier.fcmToken;
27
- const apnsToken = await Courier.apnsToken;
28
-
29
- const unsubscribe = Courier.registerPushNotificationListeners({
30
- onPushNotificationClicked(push) {
31
- console.log(push);
32
- },
33
- onPushNotificationDelivered(push) {
34
- console.log(push);
35
- },
36
- });
37
-
38
- const messageId = await Courier.sendPush({
39
- authKey: 'asdf...',
40
- userId: 'example_user_id',
41
- title: 'Hey! 👋',
42
- body: 'Courier is awesome!!',
43
- isProduction: false,
44
- providers: [CourierProvider.APNS, CourierProvider.FCM],
45
- });
46
- ```
47
-
48
-  
49
-
50
- # Requirements & Support
51
-
52
-
53
- | Operating System | Min SDK | Compile SDK | Firebase Cloud Messaging | Apple Push Notification Service | Expo | OneSignal | Courier Inbox | Courier Toast |
54
- | :-- | --: | --: | --: | --: | --: | --: | --: | --: |
55
- | `iOS` | `13` | — | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
56
- | `Android` | `21` | `32` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
57
-
58
- > Most of this SDK depends on a Courier account: [`Create a Courier account here`](https://app.courier.com/signup)
59
-
60
- > Testing push notifications requires a physical device. Simulators will not work.
61
-
62
-  
63
-
64
- # **Installation**
65
-
66
- > Link to [`Example App`](https://github.com/trycourier/courier-react-native/tree/master/example)
67
-
68
- 1. [`Install the package`](#1-install-the-package)
69
- 2. [`iOS Setup`](#2-ios-setup)
70
- 3. [`Android Setup`](#3-android-setup)
71
- 4. [`Configure Push Provider`](#4-configure-push-provider)
72
- 5. [`Managing User State`](#5-managing-user-state)
73
- 6. [`Going to Production`](#going-to-production)
74
-
75
-  
76
-
77
- ## **1. Install the package**
78
-
79
- Run the following command at your project's root directory:
80
-
81
- using npm:
82
-
83
- ```
84
- npm install @trycourier/courier-react-native
85
- ```
86
-
87
- using yarn:
88
-
89
- ```
90
- yarn add @trycourier/courier-react-native
91
- ```
92
-
93
-  
94
-
95
- ## **2. iOS Setup**
96
-
97
- > If you don't need push notification support on iOS, you can skip this step.
98
-
99
- https://user-images.githubusercontent.com/6370613/199279392-1b376929-4a03-4acd-9d00-d170085d9791.mov
100
-
101
- ### Written Tutorial 👇
102
-
103
- 1. Open your iOS project and increase the min SDK target to iOS 13.0+
104
- 2. Open your `Podfile` and increase the platform:
105
-
106
- ```
107
- ..
108
- platform :ios, '13'
109
- ..
110
- ```
111
-
112
- 3. From your React Native project's root directory, run: `cd ios && pod update`
113
- 4. In Xcode, change your `AppDelegate.h` to use the snippet below:
114
- - This automatically syncs APNS tokens to Courier token management
115
- - Allows the React Native SDK to handle when push notifications are delivered and clicked
116
-
117
- ```objective-c
118
- #import <courier-react-native/CourierReactNativeDelegate.h>
119
-
120
- @interface AppDelegate : CourierReactNativeDelegate
121
- @end
122
- ```
123
-
124
- 4. Enable the "Push Notifications" capability
125
-
126
- ### **Add the Notification Service Extension (Recommended)**
127
-
128
- To make sure Courier can track when a notification is delivered to the device, you need to add a Notification Service Extension. Here is how to add one.
129
-
130
- https://user-images.githubusercontent.com/6370613/199331562-5d16e02f-2878-4f60-bbe2-075ae119c6bc.mov
131
-
132
- ### Written Tutorial 👇
133
-
134
- 1. Download and Unzip the Courier Notification Service Extension: [`CourierNotificationServiceTemplate.zip`](https://github.com/trycourier/courier-notification-service-extension-template/archive/refs/heads/main.zip)
135
- 2. Open the folder in terminal and run `sh make_template.sh`
136
- - This will create the Notification Service Extension on your mac to save you time
137
- 3. Open your iOS app in Xcode and go to File > New > Target
138
- 4. Select "Courier Service" and click "Next"
139
- 5. Give the Notification Service Extension a name (i.e. "CourierService"), select `Courier_iOS` as the Package, and click "Finish"
140
- 6. Click "Cancel" on the next popup
141
- - You do NOT need to click "Activate" here. Your Notification Service Extension will still work just fine.
142
- 7. Open your `Podfile` and add the following snippet to the end of your Podfile
143
- - This will link the `Courier-iOS` pod to your Notification Service Extension
144
-
145
- ```
146
- target 'CourierService' do
147
- pod 'Courier-iOS'
148
- end
149
- ```
150
-
151
- 8. From the root of your React Native app, run: `cd ios && pod install`
152
-
153
- &emsp;
154
-
155
- ## **3. Android Setup**
156
-
157
- > If you don't need push notification support on Android, you can skip this step.
158
-
159
- https://user-images.githubusercontent.com/6370613/199335432-aa52028a-f7ae-48bb-abec-427795baa6f4.mov
160
-
161
- ### Written Tutorial 👇
162
-
163
- 1. Open Android project
164
- 2. Register your app in Firebase and download your `google-services.json` file
165
- 3. Add the `google-services.json` file to your `yourApp/app/src` directory
166
- 4. Make sure your `yourApp/android/build.gradle` file supports Jitpack:
167
-
168
- ```groovy
169
- allprojects {
170
- repositories {
171
- ..
172
- maven { url 'https://www.jitpack.io' } // This line is needed
173
- }
174
- }
175
- ```
176
-
177
- 3. Update your `yourApp/android/build.gradle` to support the following SDK versions
178
- - This is needed to support newer Android Notification APIs
179
-
180
- ```groovy
181
- buildscript {
182
- ext {
183
- buildToolsVersion = "32.0.0"
184
- minSdkVersion = 21
185
- compileSdkVersion = 32
186
- targetSdkVersion = 32
187
- ..
188
- }
189
- ..
190
- }
191
- ```
192
-
193
- 4. Add the `google-services` dependency to your `yourApp/android/build.gradle` file:
194
-
195
- ```groovy
196
- buildscript {
197
- dependencies {
198
- ..
199
- classpath("com.google.gms:google-services:4.3.14") // Add this line
200
- }
201
- }
202
- ```
203
-
204
- 5. Add this following line to the top of your `/android/app/build.gradle` file:
205
-
206
- ```groovy
207
- apply plugin: "com.android.application"
208
- apply plugin: "com.google.gms.google-services" // Add this line
209
- ```
210
-
211
- 6. Run Gradle Sync
212
-
213
- ### **Update Activity and Register Service**
214
-
215
- https://user-images.githubusercontent.com/6370613/199335233-0880209b-5aec-4584-9726-eaa1077bf80d.mov
216
-
217
- ### Written Tutorial 👇
218
-
219
- 1. Change your `MainActivity` to extend the `CourierReactNativeActivity`
220
- - This allows Courier to handle when push notifications are delivered and clicked
221
- 2. Setup a new Notification Service by creating a new java file and paste the code below in it
222
- - This allows you to present a notification to your user when a new notification arrives and will automatically sync new fcm tokens to Courier token management
223
-
224
- ```java
225
- // Your project import
226
-
227
- import android.annotation.SuppressLint;
228
- import androidx.annotation.NonNull;
229
- import com.courier.android.notifications.RemoteMessageExtensionsKt;
230
- import com.courier.android.service.CourierService;
231
- import com.google.firebase.messaging.RemoteMessage;
232
-
233
- // This is safe. `CourierService` will automatically handle token refreshes.
234
- @SuppressLint("MissingFirebaseInstanceTokenRefresh")
235
- public class YourExampleService extends CourierService {
236
-
237
- @Override
238
- public void showNotification(@NonNull RemoteMessage message) {
239
- super.showNotification(message);
240
-
241
- // TODO: This is where you will customize the notification that is shown to your users
242
- // The function below is used to get started quickly.
243
- // You likely do not want to use `message.presentNotification(...)`
244
- // For React Native, you likely do not want to change RemoteMessageExtensionsKt.presentNotification.handlingClass
245
- // More information on how to customize an Android notification here:
246
- // https://developer.android.com/develop/ui/views/notifications/build-notification
247
-
248
- RemoteMessageExtensionsKt.presentNotification(
249
- message,
250
- this,
251
- MainActivity.class,
252
- android.R.drawable.ic_dialog_info,
253
- "Notification Service"
254
- );
255
-
256
- }
257
-
258
- }
259
- ```
260
-
261
- 3. Add the Notification Service entry in your `AndroidManifest.xml` file
262
-
263
- ```xml
264
- <manifest>
265
- <application>
266
-
267
- <activity>
268
- ..
269
- </activity>
270
-
271
- // Add this 👇
272
- <service
273
- android:name=".YourExampleService"
274
- android:exported="false">
275
- <intent-filter>
276
- <action android:name="com.google.firebase.MESSAGING_EVENT" />
277
- </intent-filter>
278
- </service>
279
- // Add this 👆
280
-
281
- ..
282
-
283
- </application>
284
- </manifest>
285
- ```
286
-
287
- &emsp;
288
-
289
- ## **4. Configure Push Provider**
290
-
291
- > If you don't need push notification support, you can skip this step.
292
-
293
- To get push notification to appear in your app, add support for the provider you would like to use:
294
-
295
- - [`APNS (Apple Push Notification Service)`](https://app.courier.com/channels/apn)
296
- - [`FCM (Firebase Cloud Messaging)`](https://app.courier.com/channels/firebase-fcm)
297
-
298
- &emsp;
299
-
300
- ## **5. Managing User State**
301
-
302
- Best user experience practice is to synchronize the current user's push notification tokens and the user's state. Courier does most of this for you automatically!
303
-
304
- > You can use a Courier Auth Key [`found here`](https://app.courier.com/settings/api-keys) when developing.
305
-
306
- > When you are ready for production release, you should be using a JWT as the `accessToken`.
307
- > Here is more info about [`Going to Production`](#going-to-production)
308
-
309
- Place these functions where you normally manage your user's state:
310
-
311
- ```dart
312
- // Saves accessToken and userId to native level local storage
313
- // This will persist between app sessions
314
- await Courier.signIn({
315
- accessToken: accessToken,
316
- userId: userId,
317
- });
318
-
319
- await Courier.signOut();
7
+ ```sh
8
+ npm install courier-react-native
320
9
  ```
321
10
 
322
- If you followed the steps above:
323
-
324
- - APNS tokens on iOS will automatically be synced to Courier
325
- - FCM tokens on Android will automatically be synced to Courier
326
-
327
- <!-- If you want FCM tokens to sync to Courier on iOS:
328
-
329
- 1. Add the following react native packages to your project
330
- - [`React Native Firebase`](https://rnfirebase.io/)
331
-
332
- 2. Add code to manually sync FCM tokens
333
-
334
- ```typescript
335
- const fcmToken = await FirebaseMessaging.instance.getToken();
336
- if (fcmToken != null) {
337
- await Courier.shared.setFcmToken(token: fcmToken);
338
- }
339
-
340
- // Handle FCM token refreshes
341
- FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) {
342
- Courier.shared.setFcmToken(token: fcmToken);
343
- });
344
- ``` -->
345
-
346
- &emsp;
347
-
348
- ## **6. Testing Push Notifications**
349
-
350
- > If you don't need push notification support, you can skip this step.
351
-
352
- Courier allows you to send a push notification directly from the SDK to a user id. No tokens juggling or backend needed!
353
-
354
- ```typescript
355
- const notificationPermission = await Courier.notificationPermissionStatus;
356
- console.log(notificationPermission);
357
-
358
- // Notification permissions must be `authorized` on iOS to receive pushes
359
-
360
- const requestedNotificationPermission = await Courier.requestNotificationPermission();
361
- console.log(requestedNotificationPermission);
362
-
363
- // This is how iOS will show the notification when the app is in the foreground
364
- // Passing [] will not present anything
365
- // `onPushNotificationDelivered` will still get called
366
- await Courier.iOSForegroundPresentationOptions({
367
- options: ['badge', 'banner', 'list', 'sound'],
368
- });
369
-
370
-
371
- // This function returns an unsubscribe function
372
- // Call `unsibscribe();` to stop listening to notifications
373
- // Recommended to call the function while component mounts and unsubscribe when the component unmounts
374
- const unsubscribe = Courier.registerPushNotificationListeners({
375
-
376
- // Will be called if the app is in the foreground and a push notification arrives
377
- onPushNotificationClicked(push) {
378
- console.log(push.title)
379
- },
380
-
381
- // Will be called when a user clicks a push notification
382
- onPushNotificationDelivered(push) {
383
- console.log(push.title)
384
- }
385
-
386
- });
387
-
388
- // Sends a test push
389
- const messageId = await Courier.sendPush({
390
- authKey: 'your_courier_auth_key_that_should_only_be_used_for_testing',
391
- userId: 'example_user',
392
- title: 'Chirp Chrip!',
393
- body: 'Hello from Courier 🐣',
394
- isProduction: false, // This only affects APNS pushes. false == sandbox / true == production
395
- providers: [CourierProvider.APNS, CourierProvider.FCM],
396
- });
397
- ```
398
-
399
- &emsp;
400
-
401
- ## **Going to Production**
11
+ ## Usage
402
12
 
403
- For security reasons, you should not keep your `authKey` (which looks like: `pk_prod_ABCD...`) in your production app. The `authKey` is safe to test with, but you will want to use an `accessToken` in production.
13
+ ```js
14
+ import { CourierReactNativeView } from "courier-react-native";
404
15
 
405
- To create an `accessToken`, call this:
16
+ // ...
406
17
 
407
- ```curl
408
- curl --request POST \
409
- --url https://api.courier.com/auth/issue-token \
410
- --header 'Accept: application/json' \
411
- --header 'Authorization: Bearer $YOUR_AUTH_KEY' \
412
- --header 'Content-Type: application/json' \
413
- --data
414
- '{
415
- "scope": "user_id:$YOUR_USER_ID write:user-tokens",
416
- "expires_in": "$YOUR_NUMBER days"
417
- }'
18
+ <CourierReactNativeView color="tomato" />
418
19
  ```
419
20
 
420
- Or generate one here: [`Issue Courier Access Token`](https://www.courier.com/docs/reference/auth/issue-token/)
21
+ ## Contributing
421
22
 
422
- > This request to issue a token should likely exist in a separate endpoint served on your backend.
23
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
423
24
 
424
- &emsp;
25
+ ## License
425
26
 
426
- ## **Share feedback with Courier**
27
+ MIT
427
28
 
428
- We want to make this the best SDK for managing notifications! Have an idea or feedback about our SDKs? Here are some links to contact us:
29
+ ---
429
30
 
430
- - [Courier Feedback](https://feedback.courier.com/)
431
- - [Courier React Native Issues](https://github.com/trycourier/courier-react-native/issues)
31
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -1,44 +1,70 @@
1
1
  buildscript {
2
2
  // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
- def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['CourierReactNative_kotlinVersion']
3
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["CourierReactNative_kotlinVersion"]
4
4
 
5
5
  repositories {
6
- google()
7
- mavenCentral()
6
+ google()
7
+ mavenCentral()
8
8
  }
9
9
 
10
10
  dependencies {
11
- classpath 'com.android.tools.build:gradle:3.5.3'
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
12
  // noinspection DifferentKotlinGradleVersion
13
13
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
14
  }
15
15
  }
16
16
 
17
17
  def isNewArchitectureEnabled() {
18
- return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
19
  }
20
20
 
21
- apply plugin: 'com.android.library'
22
- apply plugin: 'kotlin-android'
21
+ apply plugin: "com.android.library"
22
+ apply plugin: "kotlin-android"
23
+
24
+
25
+ def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
23
26
 
24
27
  if (isNewArchitectureEnabled()) {
25
- apply plugin: 'com.facebook.react'
28
+ apply plugin: "com.facebook.react"
26
29
  }
27
30
 
28
31
  def getExtOrDefault(name) {
29
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['CourierReactNative_' + name]
32
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["CourierReactNative_" + name]
30
33
  }
31
34
 
32
35
  def getExtOrIntegerDefault(name) {
33
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['CourierReactNative_' + name]).toInteger()
36
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CourierReactNative_" + name]).toInteger()
37
+ }
38
+
39
+ def supportsNamespace() {
40
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
41
+ def major = parsed[0].toInteger()
42
+ def minor = parsed[1].toInteger()
43
+
44
+ // Namespace support was added in 7.3.0
45
+ if (major == 7 && minor >= 3) {
46
+ return true
47
+ }
48
+
49
+ return major >= 8
34
50
  }
35
51
 
36
52
  android {
37
- compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
53
+ if (supportsNamespace()) {
54
+ namespace "com.courierreactnative"
55
+
56
+ sourceSets {
57
+ main {
58
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
59
+ }
60
+ }
61
+ }
62
+
63
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
38
64
 
39
65
  defaultConfig {
40
- minSdkVersion getExtOrIntegerDefault('minSdkVersion')
41
- targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
66
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
67
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
42
68
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
43
69
  }
44
70
  buildTypes {
@@ -48,102 +74,41 @@ android {
48
74
  }
49
75
 
50
76
  lintOptions {
51
- disable 'GradleCompatible'
77
+ disable "GradleCompatible"
52
78
  }
53
79
 
54
80
  compileOptions {
55
81
  sourceCompatibility JavaVersion.VERSION_1_8
56
82
  targetCompatibility JavaVersion.VERSION_1_8
57
83
  }
84
+
58
85
  }
59
86
 
60
87
  repositories {
61
88
  mavenCentral()
62
89
  google()
63
90
  maven { url 'https://jitpack.io' }
64
-
65
- def found = false
66
- def defaultDir = null
67
- def androidSourcesName = 'React Native sources'
68
-
69
- if (rootProject.ext.has('reactNativeAndroidRoot')) {
70
- defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
71
- } else {
72
- defaultDir = new File(
73
- projectDir,
74
- '/../../../node_modules/react-native/android'
75
- )
76
- }
77
-
78
- if (defaultDir.exists()) {
79
- maven {
80
- url defaultDir.toString()
81
- name androidSourcesName
82
- }
83
-
84
- logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
85
- found = true
86
- } else {
87
- def parentDir = rootProject.projectDir
88
-
89
- 1.upto(5, {
90
- if (found) return true
91
- parentDir = parentDir.parentFile
92
-
93
- def androidSourcesDir = new File(
94
- parentDir,
95
- 'node_modules/react-native'
96
- )
97
-
98
- def androidPrebuiltBinaryDir = new File(
99
- parentDir,
100
- 'node_modules/react-native/android'
101
- )
102
-
103
- if (androidPrebuiltBinaryDir.exists()) {
104
- maven {
105
- url androidPrebuiltBinaryDir.toString()
106
- name androidSourcesName
107
- }
108
-
109
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
110
- found = true
111
- } else if (androidSourcesDir.exists()) {
112
- maven {
113
- url androidSourcesDir.toString()
114
- name androidSourcesName
115
- }
116
-
117
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
118
- found = true
119
- }
120
- })
121
- }
122
-
123
- if (!found) {
124
- throw new GradleException(
125
- "${project.name}: unable to locate React Native android sources. " +
126
- "Ensure you have you installed React Native as a dependency in your project and try again."
127
- )
128
- }
129
91
  }
130
92
 
131
- def kotlin_version = getExtOrDefault('kotlinVersion')
93
+ def kotlin_version = getExtOrDefault("kotlinVersion")
132
94
 
133
95
  dependencies {
134
- //noinspection GradleDynamicVersion
96
+
97
+ // For < 0.71, this will be from the local maven repo
98
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
99
+ //noinspection GradleDynamicVersion
135
100
  implementation "com.facebook.react:react-native:+"
136
101
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
137
102
 
138
103
  // Courier Core SDK
139
- api 'com.github.trycourier:courier-android:1.1.1'
104
+ api 'com.github.trycourier:courier-android:2.0.2'
140
105
 
141
106
  }
142
107
 
143
108
  if (isNewArchitectureEnabled()) {
144
109
  react {
145
110
  jsRootDir = file("../src/")
146
- libraryName = "CourierReactNative"
111
+ libraryName = "CourierReactNativeView"
147
112
  codegenJavaPackageName = "com.courierreactnative"
148
113
  }
149
114
  }
@@ -1,4 +1,3 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
  package="com.courierreactnative">
3
-
4
3
  </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>