@rownd/react-native 0.2.4 → 2.1.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 (253) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -52
  3. package/android/build.gradle +127 -37
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -1
  6. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginModule.kt +98 -0
  7. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginPackage.kt +16 -0
  8. package/ios/{ReactNative.xcodeproj → Rownd.xcodeproj}/project.pbxproj +13 -12
  9. package/ios/Rownd.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  10. package/ios/RowndPlugin-Bridging-Header.h +3 -0
  11. package/ios/RowndPlugin.m +26 -0
  12. package/ios/RowndPlugin.swift +83 -0
  13. package/ios/RowndPluginEventEmitter.m +12 -0
  14. package/ios/RowndPluginEventEmitter.swift +19 -0
  15. package/lib/commonjs/components/GlobalContext.js +30 -298
  16. package/lib/commonjs/components/GlobalContext.js.map +1 -1
  17. package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
  18. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  19. package/lib/commonjs/constants/action.js +13 -0
  20. package/lib/commonjs/constants/action.js.map +1 -0
  21. package/lib/commonjs/hooks/rownd.js +15 -146
  22. package/lib/commonjs/hooks/rownd.js.map +1 -1
  23. package/lib/commonjs/index.js +2 -12
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/reducer/rowndReducer.js +89 -0
  26. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  27. package/lib/commonjs/utils/config.js +0 -26
  28. package/lib/commonjs/utils/config.js.map +1 -1
  29. package/lib/commonjs/utils/nativeModule.js +72 -0
  30. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  31. package/lib/module/components/GlobalContext.js +29 -293
  32. package/lib/module/components/GlobalContext.js.map +1 -1
  33. package/lib/module/components/GlobalContext.types.js +2 -0
  34. package/lib/module/components/GlobalContext.types.js.map +1 -0
  35. package/lib/module/constants/action.js +6 -0
  36. package/lib/module/constants/action.js.map +1 -0
  37. package/lib/module/hooks/rownd.js +12 -137
  38. package/lib/module/hooks/rownd.js.map +1 -1
  39. package/lib/module/index.js +2 -4
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/reducer/rowndReducer.js +78 -0
  42. package/lib/module/reducer/rowndReducer.js.map +1 -0
  43. package/lib/module/utils/config.js +1 -16
  44. package/lib/module/utils/config.js.map +1 -1
  45. package/lib/module/utils/nativeModule.js +48 -0
  46. package/lib/module/utils/nativeModule.js.map +1 -0
  47. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  48. package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
  49. package/lib/typescript/constants/action.d.ts +7 -0
  50. package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
  51. package/lib/typescript/index.d.ts +3 -0
  52. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  53. package/lib/typescript/utils/config.d.ts +10 -0
  54. package/lib/typescript/utils/nativeModule.d.ts +10 -0
  55. package/package.json +36 -56
  56. package/rownd-react-native.podspec +36 -0
  57. package/src/components/GlobalContext.tsx +44 -457
  58. package/src/components/GlobalContext.types.ts +105 -0
  59. package/src/constants/action.ts +8 -0
  60. package/src/hooks/rownd.ts +29 -147
  61. package/src/index.tsx +2 -4
  62. package/src/reducer/rowndReducer.ts +78 -0
  63. package/src/utils/config.ts +0 -27
  64. package/src/utils/nativeModule.ts +69 -0
  65. package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
  66. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
  67. package/ios/ReactNativeViewManager.m +0 -34
  68. package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
  69. package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
  70. package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
  71. package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
  72. package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
  73. package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
  74. package/lib/commonjs/components/AutoSigninDialog.js +0 -132
  75. package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
  76. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
  77. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  78. package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
  79. package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
  80. package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
  81. package/lib/commonjs/components/DarkText.js +0 -35
  82. package/lib/commonjs/components/DarkText.js.map +0 -1
  83. package/lib/commonjs/components/DefaultContext.js +0 -266
  84. package/lib/commonjs/components/DefaultContext.js.map +0 -1
  85. package/lib/commonjs/components/RowndComponents.js +0 -25
  86. package/lib/commonjs/components/RowndComponents.js.map +0 -1
  87. package/lib/commonjs/components/RowndProvider.js +0 -55
  88. package/lib/commonjs/components/RowndProvider.js.map +0 -1
  89. package/lib/commonjs/components/SignIn.js +0 -638
  90. package/lib/commonjs/components/SignIn.js.map +0 -1
  91. package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
  92. package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
  93. package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
  94. package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
  95. package/lib/commonjs/components/images/ErrorIcon.js +0 -31
  96. package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
  97. package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
  98. package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
  99. package/lib/commonjs/data/actions.js +0 -26
  100. package/lib/commonjs/data/actions.js.map +0 -1
  101. package/lib/commonjs/hooks/api.js +0 -155
  102. package/lib/commonjs/hooks/api.js.map +0 -1
  103. package/lib/commonjs/hooks/debounce.js +0 -38
  104. package/lib/commonjs/hooks/debounce.js.map +0 -1
  105. package/lib/commonjs/hooks/fingerprint.js +0 -176
  106. package/lib/commonjs/hooks/fingerprint.js.map +0 -1
  107. package/lib/commonjs/hooks/index.js +0 -48
  108. package/lib/commonjs/hooks/index.js.map +0 -1
  109. package/lib/commonjs/hooks/interval.js +0 -31
  110. package/lib/commonjs/hooks/interval.js.map +0 -1
  111. package/lib/commonjs/hooks/nav.js +0 -39
  112. package/lib/commonjs/hooks/nav.js.map +0 -1
  113. package/lib/commonjs/index.tsx.bak +0 -26
  114. package/lib/commonjs/types.js +0 -2
  115. package/lib/commonjs/types.js.map +0 -1
  116. package/lib/commonjs/utils/events.js +0 -57
  117. package/lib/commonjs/utils/events.js.map +0 -1
  118. package/lib/commonjs/utils/form.js +0 -46
  119. package/lib/commonjs/utils/form.js.map +0 -1
  120. package/lib/commonjs/utils/queue.js +0 -117
  121. package/lib/commonjs/utils/queue.js.map +0 -1
  122. package/lib/commonjs/utils/storage.js +0 -15
  123. package/lib/commonjs/utils/storage.js.map +0 -1
  124. package/lib/commonjs/utils/tokens.js +0 -35
  125. package/lib/commonjs/utils/tokens.js.map +0 -1
  126. package/lib/commonjs/utils/user-data.js +0 -21
  127. package/lib/commonjs/utils/user-data.js.map +0 -1
  128. package/lib/module/assets/images/checkmark--filled.svg +0 -12
  129. package/lib/module/assets/images/email-verify-waiting.svg +0 -36
  130. package/lib/module/assets/images/error-icon-material.svg +0 -1
  131. package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
  132. package/lib/module/components/AuthenticatedComponent.js +0 -24
  133. package/lib/module/components/AuthenticatedComponent.js.map +0 -1
  134. package/lib/module/components/AutoSigninDialog.js +0 -110
  135. package/lib/module/components/AutoSigninDialog.js.map +0 -1
  136. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
  137. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  138. package/lib/module/components/BottomSheetTextInput/index.js +0 -5
  139. package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
  140. package/lib/module/components/BottomSheetTextInput/types.js +0 -2
  141. package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
  142. package/lib/module/components/DarkText.js +0 -24
  143. package/lib/module/components/DarkText.js.map +0 -1
  144. package/lib/module/components/DefaultContext.js +0 -244
  145. package/lib/module/components/DefaultContext.js.map +0 -1
  146. package/lib/module/components/RowndComponents.js +0 -12
  147. package/lib/module/components/RowndComponents.js.map +0 -1
  148. package/lib/module/components/RowndProvider.js +0 -39
  149. package/lib/module/components/RowndProvider.js.map +0 -1
  150. package/lib/module/components/SignIn.js +0 -610
  151. package/lib/module/components/SignIn.js.map +0 -1
  152. package/lib/module/components/images/CheckmarkFilled.js +0 -27
  153. package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
  154. package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
  155. package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
  156. package/lib/module/components/images/ErrorIcon.js +0 -18
  157. package/lib/module/components/images/ErrorIcon.js.map +0 -1
  158. package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
  159. package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
  160. package/lib/module/data/actions.js +0 -19
  161. package/lib/module/data/actions.js.map +0 -1
  162. package/lib/module/hooks/api.js +0 -135
  163. package/lib/module/hooks/api.js.map +0 -1
  164. package/lib/module/hooks/debounce.js +0 -29
  165. package/lib/module/hooks/debounce.js.map +0 -1
  166. package/lib/module/hooks/fingerprint.js +0 -157
  167. package/lib/module/hooks/fingerprint.js.map +0 -1
  168. package/lib/module/hooks/index.js +0 -7
  169. package/lib/module/hooks/index.js.map +0 -1
  170. package/lib/module/hooks/interval.js +0 -23
  171. package/lib/module/hooks/interval.js.map +0 -1
  172. package/lib/module/hooks/nav.js +0 -30
  173. package/lib/module/hooks/nav.js.map +0 -1
  174. package/lib/module/index.tsx.bak +0 -26
  175. package/lib/module/types.js +0 -2
  176. package/lib/module/types.js.map +0 -1
  177. package/lib/module/utils/events.js +0 -45
  178. package/lib/module/utils/events.js.map +0 -1
  179. package/lib/module/utils/form.js +0 -34
  180. package/lib/module/utils/form.js.map +0 -1
  181. package/lib/module/utils/queue.js +0 -109
  182. package/lib/module/utils/queue.js.map +0 -1
  183. package/lib/module/utils/storage.js +0 -6
  184. package/lib/module/utils/storage.js.map +0 -1
  185. package/lib/module/utils/tokens.js +0 -24
  186. package/lib/module/utils/tokens.js.map +0 -1
  187. package/lib/module/utils/user-data.js +0 -14
  188. package/lib/module/utils/user-data.js.map +0 -1
  189. package/lib/package.json +0 -173
  190. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
  191. package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
  192. package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
  193. package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
  194. package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
  195. package/lib/typescript/src/components/DarkText.d.ts +0 -3
  196. package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
  197. package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
  198. package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
  199. package/lib/typescript/src/components/SignIn.d.ts +0 -2
  200. package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
  201. package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
  202. package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
  203. package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
  204. package/lib/typescript/src/data/actions.d.ts +0 -20
  205. package/lib/typescript/src/hooks/api.d.ts +0 -12
  206. package/lib/typescript/src/hooks/debounce.d.ts +0 -5
  207. package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
  208. package/lib/typescript/src/hooks/index.d.ts +0 -6
  209. package/lib/typescript/src/hooks/interval.d.ts +0 -2
  210. package/lib/typescript/src/hooks/nav.d.ts +0 -6
  211. package/lib/typescript/src/index.d.ts +0 -4
  212. package/lib/typescript/src/types.d.ts +0 -26
  213. package/lib/typescript/src/utils/config.d.ts +0 -18
  214. package/lib/typescript/src/utils/events.d.ts +0 -22
  215. package/lib/typescript/src/utils/form.d.ts +0 -18
  216. package/lib/typescript/src/utils/queue.d.ts +0 -21
  217. package/lib/typescript/src/utils/storage.d.ts +0 -3
  218. package/lib/typescript/src/utils/tokens.d.ts +0 -4
  219. package/lib/typescript/src/utils/user-data.d.ts +0 -3
  220. package/react-native.podspec +0 -19
  221. package/src/assets/images/checkmark--filled.svg +0 -12
  222. package/src/assets/images/email-verify-waiting.svg +0 -36
  223. package/src/assets/images/error-icon-material.svg +0 -1
  224. package/src/assets/images/phone-verify-waiting.svg +0 -26
  225. package/src/components/AuthenticatedComponent.tsx +0 -30
  226. package/src/components/AutoSigninDialog.tsx +0 -131
  227. package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
  228. package/src/components/BottomSheetTextInput/index.ts +0 -5
  229. package/src/components/BottomSheetTextInput/types.ts +0 -3
  230. package/src/components/DarkText.tsx +0 -16
  231. package/src/components/DefaultContext.tsx +0 -278
  232. package/src/components/RowndComponents.tsx +0 -18
  233. package/src/components/RowndProvider.tsx +0 -56
  234. package/src/components/SignIn.tsx +0 -793
  235. package/src/components/images/CheckmarkFilled.tsx +0 -30
  236. package/src/components/images/EmailVerifyWaiting.tsx +0 -95
  237. package/src/components/images/ErrorIcon.tsx +0 -11
  238. package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
  239. package/src/data/actions.ts +0 -21
  240. package/src/hooks/api.ts +0 -162
  241. package/src/hooks/debounce.ts +0 -36
  242. package/src/hooks/fingerprint.ts +0 -217
  243. package/src/hooks/index.ts +0 -7
  244. package/src/hooks/interval.ts +0 -25
  245. package/src/hooks/nav.tsx +0 -29
  246. package/src/index.tsx.bak +0 -26
  247. package/src/types.ts +0 -27
  248. package/src/utils/events.ts +0 -54
  249. package/src/utils/form.tsx +0 -64
  250. package/src/utils/queue.ts +0 -75
  251. package/src/utils/storage.ts +0 -7
  252. package/src/utils/tokens.ts +0 -26
  253. package/src/utils/user-data.ts +0 -15
package/LICENSE CHANGED
@@ -1,7 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Matt Hamann
4
-
3
+ Copyright (c) 2022 rownd
5
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
5
  of this software and associated documentation files (the "Software"), to deal
7
6
  in the Software without restriction, including without limitation the rights
package/README.md CHANGED
@@ -13,59 +13,30 @@ First, install the Rownd SDK for React Native.
13
13
  npm install @rownd/react-native
14
14
  ```
15
15
 
16
- Due to some native peer-dependencies, you'll also need to run the following command to get modules with native code working properly.
17
-
18
- > If you already use `react-native-gesture-handler` and/or `react-native-reanimated` run the following command:
19
-
20
- ```sh
21
- npm install @gorhom/bottom-sheet@2 @react-native-clipboard/clipboard \
22
- react-native-device-info react-native-gesture-handler@1 react-native-mmkv \
23
- react-native-reanimated@1 react-native-sha256 react-native-svg
24
- ```
25
-
26
- > If you **do not** use the aforementioned libraries _or_ are on v2.x, run this command instead:
27
-
28
- ```sh
29
- npm install @gorhom/bottom-sheet @react-native-clipboard/clipboard \
30
- react-native-device-info react-native-gesture-handler react-native-mmkv \
31
- react-native-reanimated react-native-sha256 react-native-svg
32
- ```
16
+ ### Android
33
17
 
18
+ ```sh
19
+ cd android
20
+ ```
21
+ ```sh
22
+ ./gradlew build
23
+ ```
34
24
 
35
- Once those are installed, run this command to ensure the iOS build can find the native components.
25
+ ### iOS
36
26
 
37
27
  ```sh
38
- npx pod-install
28
+ cd ios
29
+ ```
30
+ ```sh
31
+ pod install
39
32
  ```
40
33
 
41
34
  ## Setup
42
35
 
43
36
  ### Enable deep linking
44
37
  Rownd supports automatically signing-in users when they initially install your
45
- app or when they click a sign-in link when the app is already installed.
46
-
47
- In order to enable the latter case, the Rownd SDK needs to know which URL
48
- triggered the app to launch, in case it was one of the special sign-in links.
49
-
50
- To enable this functionality, follow [the instructions for configuring a
51
- React Native app to receive deep links.](https://reactnative.dev/docs/linking)
52
- ### Add Gesture Handler
38
+ app or when they click a sign-in link when the app is already installed.
53
39
 
54
- Unless you already use `react-native-gesture-handler', include it within your app's root, wrapping your component tree like this:
55
-
56
- ```tsx
57
- import { GestureHandlerRootView } from 'react-native-gesture-handler';
58
-
59
- // ...
60
-
61
- export default function Root() {
62
- return (
63
- <GestureHandlerRootView>
64
- <App />
65
- </GestureHandlerRootView>
66
- );
67
- }
68
- ```
69
40
 
70
41
  ## Usage
71
42
  The Rownd SDK includes a context provider that will enable any component of your app to access authentication state and user data.
@@ -79,11 +50,9 @@ import { RowndProvider } from "@rownd/react-native";
79
50
 
80
51
  export default function Root() {
81
52
  return (
82
- <GestureHandlerRootView>
83
53
  <RowndProvider appKey="<your app key>">
84
54
  <App />
85
55
  </RowndProvider>
86
- </GestureHandlerRootView>
87
56
  );
88
57
  }
89
58
  ```
@@ -92,7 +61,7 @@ Later on within your app's components, you can use the Rownd hook to access the
92
61
 
93
62
  ```tsx
94
63
  import { View, Text } from 'react-native';
95
- import { useRownd } from '@rownd/react';
64
+ import { useRownd } from '@rownd/react-native';
96
65
 
97
66
  export default function MyProtectedComponent(props) {
98
67
  const { is_authenticated, user, requestSignIn, getAccessToken } = useRownd();
@@ -136,15 +105,9 @@ Trigger the Rownd sign in dialog
136
105
  ```javascript
137
106
  const { requestSignIn } = useRownd();
138
107
 
139
- requestSignIn({
140
- auto_sign_in: false, // optional
141
- identifier: 'me@company.com' || '+19105551212' // optional
142
- });
108
+ requestSignIn();
143
109
  ```
144
110
 
145
- * `auto_sign_in: boolean` - when `true`, automatically trigger a sign-in attempt _if_ `identifier` is included or an email address or phone number has already been set in the user data.
146
- * `identifier: string` - an email address or phone number (in E164 format) to which a verification message may be sent. If the Rownd app is configured to allow unverified users, then sign-in will complete without verification if the user has not signed in previously.
147
-
148
111
  #### signOut()
149
112
 
150
113
  Sign out the user and clear their profile, returning them to a completely unauthenticated state.
@@ -1,59 +1,149 @@
1
1
  buildscript {
2
- if (project == rootProject) {
3
- repositories {
4
- google()
5
- mavenCentral()
6
- jcenter()
7
- }
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['RowndPlugin_kotlinVersion']
8
4
 
9
- dependencies {
10
- classpath 'com.android.tools.build:gradle:3.5.3'
11
- }
12
- }
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath 'com.android.tools.build:gradle:3.5.3'
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
15
+ }
16
+ }
17
+
18
+ def isNewArchitectureEnabled() {
19
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
13
20
  }
14
21
 
15
22
  apply plugin: 'com.android.library'
23
+ apply plugin: 'kotlin-android'
24
+ apply plugin: 'kotlinx-serialization'
25
+
26
+ if (isNewArchitectureEnabled()) {
27
+ apply plugin: 'com.facebook.react'
28
+ }
16
29
 
17
- def safeExtGet(prop, fallback) {
18
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
30
+ def getExtOrDefault(name) {
31
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RowndPlugin_' + name]
32
+ }
33
+
34
+ def getExtOrIntegerDefault(name) {
35
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RowndPlugin_' + name]).toInteger()
19
36
  }
20
37
 
21
38
  android {
22
- compileSdkVersion safeExtGet('ReactNative_compileSdkVersion', 29)
23
- defaultConfig {
24
- minSdkVersion safeExtGet('ReactNative_minSdkVersion', 16)
25
- targetSdkVersion safeExtGet('ReactNative_targetSdkVersion', 29)
26
- versionCode 1
27
- versionName "1.0"
39
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
28
40
 
41
+ defaultConfig {
42
+ minSdkVersion getExtOrIntegerDefault('minSdkVersion')
43
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
44
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
45
+ }
46
+ buildTypes {
47
+ release {
48
+ minifyEnabled false
29
49
  }
50
+ }
30
51
 
31
- buildTypes {
32
- release {
33
- minifyEnabled false
34
- }
35
- }
36
- lintOptions {
37
- disable 'GradleCompatible'
38
- }
39
- compileOptions {
40
- sourceCompatibility JavaVersion.VERSION_1_8
41
- targetCompatibility JavaVersion.VERSION_1_8
42
- }
52
+ lintOptions {
53
+ disable 'GradleCompatible'
54
+ }
55
+
56
+ compileOptions {
57
+ sourceCompatibility JavaVersion.VERSION_1_8
58
+ targetCompatibility JavaVersion.VERSION_1_8
59
+ }
43
60
  }
44
61
 
45
62
  repositories {
46
- mavenLocal()
63
+ mavenCentral()
64
+ google()
65
+
66
+ def found = false
67
+ def defaultDir = null
68
+ def androidSourcesName = 'React Native sources'
69
+
70
+ if (rootProject.ext.has('reactNativeAndroidRoot')) {
71
+ defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
72
+ } else {
73
+ defaultDir = new File(
74
+ projectDir,
75
+ '/../../../node_modules/react-native/android'
76
+ )
77
+ }
78
+
79
+ if (defaultDir.exists()) {
47
80
  maven {
48
- // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
49
- url("$rootDir/../node_modules/react-native/android")
81
+ url defaultDir.toString()
82
+ name androidSourcesName
50
83
  }
51
- google()
52
- mavenCentral()
53
- jcenter()
84
+
85
+ logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
86
+ found = true
87
+ } else {
88
+ def parentDir = rootProject.projectDir
89
+
90
+ 1.upto(5, {
91
+ if (found) return true
92
+ parentDir = parentDir.parentFile
93
+
94
+ def androidSourcesDir = new File(
95
+ parentDir,
96
+ 'node_modules/react-native'
97
+ )
98
+
99
+ def androidPrebuiltBinaryDir = new File(
100
+ parentDir,
101
+ 'node_modules/react-native/android'
102
+ )
103
+
104
+ if (androidPrebuiltBinaryDir.exists()) {
105
+ maven {
106
+ url androidPrebuiltBinaryDir.toString()
107
+ name androidSourcesName
108
+ }
109
+
110
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
111
+ found = true
112
+ } else if (androidSourcesDir.exists()) {
113
+ maven {
114
+ url androidSourcesDir.toString()
115
+ name androidSourcesName
116
+ }
117
+
118
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
119
+ found = true
120
+ }
121
+ })
122
+ }
123
+
124
+ if (!found) {
125
+ throw new GradleException(
126
+ "${project.name}: unable to locate React Native android sources. " +
127
+ "Ensure you have you installed React Native as a dependency in your project and try again."
128
+ )
129
+ }
54
130
  }
55
131
 
132
+ def kotlin_version = getExtOrDefault('kotlinVersion')
133
+
56
134
  dependencies {
57
135
  //noinspection GradleDynamicVersion
58
- implementation "com.facebook.react:react-native:+" // From node_modules
136
+ implementation "com.facebook.react:react-native:+"
137
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
138
+ implementation 'io.rownd:android:1.3.2'
139
+ implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"
140
+ // From node_modules
141
+ }
142
+
143
+ if (isNewArchitectureEnabled()) {
144
+ react {
145
+ jsRootDir = file("../src/")
146
+ libraryName = "RowndPlugin"
147
+ codegenJavaPackageName = "com.reactnativerowndplugin"
148
+ }
59
149
  }
@@ -0,0 +1,5 @@
1
+ RowndPlugin_kotlinVersion=1.7.0
2
+ RowndPlugin_minSdkVersion=21
3
+ RowndPlugin_targetSdkVersion=31
4
+ RowndPlugin_compileSdkVersion=31
5
+ RowndPlugin_ndkversion=21.4.7075529
@@ -1,4 +1,4 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.reactnative">
2
+ package="com.reactnativerowndplugin">
3
3
 
4
4
  </manifest>
@@ -0,0 +1,98 @@
1
+ package com.reactnativerowndplugin
2
+
3
+ import android.os.Handler
4
+ import android.os.Looper
5
+ import androidx.fragment.app.FragmentActivity
6
+ import com.facebook.react.bridge.*
7
+ import com.facebook.react.modules.core.DeviceEventManagerModule
8
+ import io.rownd.android.Rownd
9
+ import io.rownd.android.models.repos.GlobalState
10
+ import io.rownd.android.models.repos.UserRepo
11
+ import kotlinx.coroutines.*
12
+ import kotlinx.serialization.json.Json
13
+
14
+
15
+ class RowndPluginModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
16
+ private var uiThreadHandler = Handler(Looper.getMainLooper())
17
+ private var coroutineScope: Job? = null
18
+ private var isRowndJSInitialized = false
19
+
20
+ override fun getName(): String {
21
+ return "RowndPlugin"
22
+ }
23
+
24
+ private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
25
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
26
+ .emit(eventName, params)
27
+ }
28
+
29
+ init {
30
+ coroutineScope = CoroutineScope(Dispatchers.IO).launch {
31
+ Rownd.state.collect {
32
+ uiThreadHandler.post{
33
+ val params = Arguments.createMap().apply {
34
+ putString("state", Json.encodeToString(GlobalState.serializer(), it))
35
+ }
36
+ if (isRowndJSInitialized) {
37
+ sendEvent(reactApplicationContext, "update_state", params)
38
+ } else {
39
+ println("ROWND JS: NOT INITIALIZED YET")
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+ // Example method
47
+ // See https://reactnative.dev/docs/native-modules-android
48
+ @ReactMethod
49
+ fun multiply(a: Int, b: Int, promise: Promise) {
50
+ promise.resolve(a * b * 10)
51
+ }
52
+
53
+ @ReactMethod
54
+ fun configure(appKey: String) {
55
+ Rownd.configure(reactApplicationContext.currentActivity as FragmentActivity, appKey)
56
+ isRowndJSInitialized = true
57
+ }
58
+
59
+ @ReactMethod
60
+ fun requestSignIn() {
61
+ Rownd.requestSignIn()
62
+ }
63
+
64
+ @ReactMethod
65
+ fun signOut() {
66
+ Rownd.signOut()
67
+ }
68
+
69
+ @ReactMethod
70
+ fun manageAccount() {
71
+ Rownd.manageAccount()
72
+ }
73
+
74
+ @ReactMethod
75
+ fun setUserData(data: ReadableMap) {
76
+ UserRepo.set(data.toHashMap())
77
+ }
78
+
79
+ @ReactMethod
80
+ fun setUserDataValue(key: String, array: ReadableMap) {
81
+ val value = array.toHashMap().entries.find { it.key == "value" }?.value
82
+ if (value != null) {
83
+ UserRepo.set(key, value)
84
+ } else {
85
+ println("ROWND ANDROID PLUGIN: Missing content for value")
86
+ }
87
+ }
88
+
89
+ // @ReactMethod
90
+ // suspend fun getAccessToken(promise: Promise) {
91
+ // try {
92
+ // val accessToken = Rownd.getAccessToken()
93
+ // promise.resolve(accessToken ?: "")
94
+ // } catch (e: Throwable) {
95
+ // promise.reject("GET_ACCESS_TOKEN_ERROR: ", e)
96
+ // }
97
+ // }
98
+ }
@@ -0,0 +1,16 @@
1
+ package com.reactnativerowndplugin
2
+ import com.facebook.react.ReactPackage
3
+ import com.facebook.react.bridge.NativeModule
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.uimanager.ViewManager
6
+
7
+
8
+ class RowndPluginPackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
+ return listOf(RowndPluginModule(reactContext))
11
+ }
12
+
13
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
+ return emptyList()
15
+ }
16
+ }
@@ -7,9 +7,8 @@
7
7
  objects = {
8
8
 
9
9
  /* Begin PBXBuildFile section */
10
-
11
10
  5E555C0D2413F4C50049A1A2 /* ReactNative.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* ReactNative.m */; };
12
-
11
+ F4FF95D7245B92E800C19C63 /* ReactNative.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* ReactNative.swift */; };
13
12
  /* End PBXBuildFile section */
14
13
 
15
14
  /* Begin PBXCopyFilesBuildPhase section */
@@ -26,10 +25,9 @@
26
25
 
27
26
  /* Begin PBXFileReference section */
28
27
  134814201AA4EA6300B7C361 /* libReactNative.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNative.a; sourceTree = BUILT_PRODUCTS_DIR; };
29
-
30
- B3E7B5881CC2AC0600A0062D /* ReactNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNative.h; sourceTree = "<group>"; };
31
28
  B3E7B5891CC2AC0600A0062D /* ReactNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNative.m; sourceTree = "<group>"; };
32
-
29
+ F4FF95D5245B92E700C19C63 /* ReactNative-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ReactNative-Bridging-Header.h"; sourceTree = "<group>"; };
30
+ F4FF95D6245B92E800C19C63 /* ReactNative.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactNative.swift; sourceTree = "<group>"; };
33
31
  /* End PBXFileReference section */
34
32
 
35
33
  /* Begin PBXFrameworksBuildPhase section */
@@ -54,10 +52,9 @@
54
52
  58B511D21A9E6C8500147676 = {
55
53
  isa = PBXGroup;
56
54
  children = (
57
-
58
- B3E7B5881CC2AC0600A0062D /* ReactNative.h */,
55
+ F4FF95D6245B92E800C19C63 /* ReactNative.swift */,
59
56
  B3E7B5891CC2AC0600A0062D /* ReactNative.m */,
60
-
57
+ F4FF95D5245B92E700C19C63 /* ReactNative-Bridging-Header.h */,
61
58
  134814211AA4EA7D00B7C361 /* Products */,
62
59
  );
63
60
  sourceTree = "<group>";
@@ -119,9 +116,8 @@
119
116
  isa = PBXSourcesBuildPhase;
120
117
  buildActionMask = 2147483647;
121
118
  files = (
122
-
119
+ F4FF95D7245B92E800C19C63 /* ReactNative.swift in Sources */,
123
120
  B3E7B58A1CC2AC0600A0062D /* ReactNative.m in Sources */,
124
-
125
121
  );
126
122
  runOnlyForDeploymentPostprocessing = 0;
127
123
  };
@@ -156,6 +152,7 @@
156
152
  COPY_PHASE_STRIP = NO;
157
153
  ENABLE_STRICT_OBJC_MSGSEND = YES;
158
154
  ENABLE_TESTABILITY = YES;
155
+ "EXCLUDED_ARCHS[sdk=*]" = arm64;
159
156
  GCC_C_LANGUAGE_STANDARD = gnu99;
160
157
  GCC_DYNAMIC_NO_PIC = NO;
161
158
  GCC_NO_COMMON_BLOCKS = YES;
@@ -206,6 +203,7 @@
206
203
  COPY_PHASE_STRIP = YES;
207
204
  ENABLE_NS_ASSERTIONS = NO;
208
205
  ENABLE_STRICT_OBJC_MSGSEND = YES;
206
+ "EXCLUDED_ARCHS[sdk=*]" = arm64;
209
207
  GCC_C_LANGUAGE_STANDARD = gnu99;
210
208
  GCC_NO_COMMON_BLOCKS = YES;
211
209
  GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@@ -234,7 +232,9 @@
234
232
  OTHER_LDFLAGS = "-ObjC";
235
233
  PRODUCT_NAME = ReactNative;
236
234
  SKIP_INSTALL = YES;
237
-
235
+ SWIFT_OBJC_BRIDGING_HEADER = "ReactNative-Bridging-Header.h";
236
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
237
+ SWIFT_VERSION = 5.0;
238
238
  };
239
239
  name = Debug;
240
240
  };
@@ -251,7 +251,8 @@
251
251
  OTHER_LDFLAGS = "-ObjC";
252
252
  PRODUCT_NAME = ReactNative;
253
253
  SKIP_INSTALL = YES;
254
-
254
+ SWIFT_OBJC_BRIDGING_HEADER = "ReactNative-Bridging-Header.h";
255
+ SWIFT_VERSION = 5.0;
255
256
  };
256
257
  name = Release;
257
258
  };
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ </Workspace>
@@ -0,0 +1,3 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
3
+
@@ -0,0 +1,26 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(RowndPlugin, NSObject)
4
+
5
+
6
+ RCT_EXTERN_METHOD(setUserDataValue:(NSString *)key withValue:(id)value)
7
+ RCT_EXTERN_METHOD(setUserData:(NSDictionary<NSString *, id>)data)
8
+
9
+ RCT_EXTERN_METHOD(configure:(NSString *)appKey
10
+ withResolver:(RCTPromiseResolveBlock)resolve
11
+ withRejecter:(RCTPromiseRejectBlock)reject)
12
+
13
+ RCT_EXTERN_METHOD(requestSignIn)
14
+ RCT_EXTERN_METHOD(signOut)
15
+
16
+ RCT_EXTERN_METHOD(manageAccount)
17
+
18
+ RCT_EXTERN_METHOD(getAccessToken:
19
+ withResolver:(RCTPromiseResolveBlock)resolve)
20
+
21
+ + (BOOL)requiresMainQueueSetup
22
+ {
23
+ return NO;
24
+ }
25
+
26
+ @end
@@ -0,0 +1,83 @@
1
+ import Rownd
2
+ import SwiftUI
3
+ import Combine
4
+ import AnyCodable
5
+
6
+ @objc(RowndPlugin)
7
+ class RowndPlugin: NSObject {
8
+
9
+ @ObservedObject private var state = Rownd.getInstance().state().subscribe { $0 }
10
+
11
+ private var stateCancellable: AnyCancellable?
12
+
13
+ override init() {
14
+ super.init()
15
+
16
+ stateCancellable = state.$current.sink { newState in
17
+ do {
18
+ RowndPluginEventEmitter.emitter.sendEvent(withName: "update_state", body: try newState.toDictionary())
19
+ } catch {
20
+ print("Failed to encode Rownd state: \(String(describing: error))")
21
+ }
22
+ }
23
+ }
24
+
25
+ @objc(configure:withResolver:withRejecter:)
26
+ func configure(appKey: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
27
+ Task.init {
28
+ await Rownd.configure(launchOptions: nil, appKey: appKey)
29
+ }
30
+ resolve(appKey)
31
+ }
32
+
33
+ @objc
34
+ func requestSignIn() -> Void {
35
+ DispatchQueue.main.async {
36
+ Rownd.requestSignIn()
37
+ }
38
+ }
39
+
40
+ @objc
41
+ func signOut() -> Void {
42
+ DispatchQueue.main.async {
43
+ Rownd.signOut()
44
+ }
45
+ }
46
+
47
+ @objc
48
+ func manageAccount() -> Void {
49
+ DispatchQueue.main.async {
50
+ Rownd.manageAccount()
51
+ }
52
+ }
53
+
54
+ @objc(getAccessToken:withResolver:)
55
+ func getAccessToken(resolve: @escaping RCTPromiseResolveBlock) async -> Void {
56
+ let accessToken = await Rownd.getAccessToken()
57
+ resolve(accessToken)
58
+ }
59
+
60
+ @objc(setUserData:)
61
+ func setUserData(data: Dictionary<String, Any>) -> Void {
62
+ do {
63
+ let jsonData = try JSONSerialization.data(withJSONObject: data, options: .prettyPrinted)
64
+ let decoder = JSONDecoder()
65
+ let dictionary = try! decoder.decode([String: AnyCodable].self, from: jsonData)
66
+
67
+ Rownd.user.set(data: dictionary)
68
+ } catch {
69
+ print("FAILED TO SET USER DATA: ",error)
70
+ }
71
+ }
72
+
73
+ @objc(setUserDataValue:withValue:)
74
+ func setUserDataValue(key: String, value: Any) -> Void {
75
+ let json = """
76
+ "\(value)"
77
+ """.data(using: .utf8)!
78
+
79
+ let decoder = JSONDecoder()
80
+ let dictionary = try! decoder.decode(AnyCodable.self, from: json)
81
+ Rownd.user.set(field: key, value: dictionary)
82
+ }
83
+ }
@@ -0,0 +1,12 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
3
+
4
+ @interface RCT_EXTERN_MODULE(RowndPluginEventEmitter, RCTEventEmitter)
5
+ RCT_EXTERN_METHOD(supportedEvents)
6
+
7
+ + (BOOL)requiresMainQueueSetup
8
+ {
9
+ return YES;
10
+ }
11
+
12
+ @end
@@ -0,0 +1,19 @@
1
+ import Rownd
2
+ import SwiftUI
3
+ import React
4
+
5
+ @objc(RowndPluginEventEmitter)
6
+ class RowndPluginEventEmitter: RCTEventEmitter {
7
+
8
+ public static var emitter: RCTEventEmitter!
9
+
10
+ override init() {
11
+ super.init()
12
+ RowndPluginEventEmitter.emitter = self
13
+ }
14
+
15
+ open override func supportedEvents() -> [String] {
16
+ ["update_state","onReady", "onPending", "onFailure"] // etc.
17
+ }
18
+ }
19
+