@rownd/react-native 0.2.5 → 2.2.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 (252) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +34 -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/RowndPlugin-Bridging-Header.h +3 -0
  10. package/ios/RowndPlugin.m +26 -0
  11. package/ios/RowndPlugin.swift +83 -0
  12. package/ios/RowndPluginEventEmitter.m +12 -0
  13. package/ios/RowndPluginEventEmitter.swift +19 -0
  14. package/lib/commonjs/components/GlobalContext.js +32 -298
  15. package/lib/commonjs/components/GlobalContext.js.map +1 -1
  16. package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
  17. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  18. package/lib/commonjs/constants/action.js +13 -0
  19. package/lib/commonjs/constants/action.js.map +1 -0
  20. package/lib/commonjs/hooks/rownd.js +15 -146
  21. package/lib/commonjs/hooks/rownd.js.map +1 -1
  22. package/lib/commonjs/index.js +2 -12
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/reducer/rowndReducer.js +89 -0
  25. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  26. package/lib/commonjs/utils/config.js +0 -26
  27. package/lib/commonjs/utils/config.js.map +1 -1
  28. package/lib/commonjs/utils/nativeModule.js +72 -0
  29. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  30. package/lib/module/components/GlobalContext.js +30 -293
  31. package/lib/module/components/GlobalContext.js.map +1 -1
  32. package/lib/module/components/GlobalContext.types.js +2 -0
  33. package/lib/module/components/GlobalContext.types.js.map +1 -0
  34. package/lib/module/constants/action.js +6 -0
  35. package/lib/module/constants/action.js.map +1 -0
  36. package/lib/module/hooks/rownd.js +12 -137
  37. package/lib/module/hooks/rownd.js.map +1 -1
  38. package/lib/module/index.js +2 -4
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/reducer/rowndReducer.js +78 -0
  41. package/lib/module/reducer/rowndReducer.js.map +1 -0
  42. package/lib/module/utils/config.js +1 -16
  43. package/lib/module/utils/config.js.map +1 -1
  44. package/lib/module/utils/nativeModule.js +48 -0
  45. package/lib/module/utils/nativeModule.js.map +1 -0
  46. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  47. package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
  48. package/lib/typescript/constants/action.d.ts +7 -0
  49. package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
  50. package/lib/typescript/index.d.ts +3 -0
  51. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  52. package/lib/typescript/utils/config.d.ts +10 -0
  53. package/lib/typescript/utils/nativeModule.d.ts +10 -0
  54. package/package.json +36 -56
  55. package/rownd-react-native.podspec +36 -0
  56. package/src/components/GlobalContext.tsx +47 -457
  57. package/src/components/GlobalContext.types.ts +105 -0
  58. package/src/constants/action.ts +8 -0
  59. package/src/hooks/rownd.ts +29 -147
  60. package/src/index.tsx +2 -4
  61. package/src/reducer/rowndReducer.ts +78 -0
  62. package/src/utils/config.ts +0 -27
  63. package/src/utils/nativeModule.ts +69 -0
  64. package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
  65. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
  66. package/ios/ReactNativeViewManager.m +0 -34
  67. package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
  68. package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
  69. package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
  70. package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
  71. package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
  72. package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
  73. package/lib/commonjs/components/AutoSigninDialog.js +0 -132
  74. package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
  75. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
  76. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  77. package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
  78. package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
  79. package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
  80. package/lib/commonjs/components/DarkText.js +0 -35
  81. package/lib/commonjs/components/DarkText.js.map +0 -1
  82. package/lib/commonjs/components/DefaultContext.js +0 -266
  83. package/lib/commonjs/components/DefaultContext.js.map +0 -1
  84. package/lib/commonjs/components/RowndComponents.js +0 -25
  85. package/lib/commonjs/components/RowndComponents.js.map +0 -1
  86. package/lib/commonjs/components/RowndProvider.js +0 -55
  87. package/lib/commonjs/components/RowndProvider.js.map +0 -1
  88. package/lib/commonjs/components/SignIn.js +0 -644
  89. package/lib/commonjs/components/SignIn.js.map +0 -1
  90. package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
  91. package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
  92. package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
  93. package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
  94. package/lib/commonjs/components/images/ErrorIcon.js +0 -31
  95. package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
  96. package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
  97. package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
  98. package/lib/commonjs/data/actions.js +0 -26
  99. package/lib/commonjs/data/actions.js.map +0 -1
  100. package/lib/commonjs/hooks/api.js +0 -155
  101. package/lib/commonjs/hooks/api.js.map +0 -1
  102. package/lib/commonjs/hooks/debounce.js +0 -38
  103. package/lib/commonjs/hooks/debounce.js.map +0 -1
  104. package/lib/commonjs/hooks/fingerprint.js +0 -176
  105. package/lib/commonjs/hooks/fingerprint.js.map +0 -1
  106. package/lib/commonjs/hooks/index.js +0 -48
  107. package/lib/commonjs/hooks/index.js.map +0 -1
  108. package/lib/commonjs/hooks/interval.js +0 -31
  109. package/lib/commonjs/hooks/interval.js.map +0 -1
  110. package/lib/commonjs/hooks/nav.js +0 -39
  111. package/lib/commonjs/hooks/nav.js.map +0 -1
  112. package/lib/commonjs/index.tsx.bak +0 -26
  113. package/lib/commonjs/types.js +0 -2
  114. package/lib/commonjs/types.js.map +0 -1
  115. package/lib/commonjs/utils/events.js +0 -57
  116. package/lib/commonjs/utils/events.js.map +0 -1
  117. package/lib/commonjs/utils/form.js +0 -46
  118. package/lib/commonjs/utils/form.js.map +0 -1
  119. package/lib/commonjs/utils/queue.js +0 -117
  120. package/lib/commonjs/utils/queue.js.map +0 -1
  121. package/lib/commonjs/utils/storage.js +0 -15
  122. package/lib/commonjs/utils/storage.js.map +0 -1
  123. package/lib/commonjs/utils/tokens.js +0 -35
  124. package/lib/commonjs/utils/tokens.js.map +0 -1
  125. package/lib/commonjs/utils/user-data.js +0 -21
  126. package/lib/commonjs/utils/user-data.js.map +0 -1
  127. package/lib/module/assets/images/checkmark--filled.svg +0 -12
  128. package/lib/module/assets/images/email-verify-waiting.svg +0 -36
  129. package/lib/module/assets/images/error-icon-material.svg +0 -1
  130. package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
  131. package/lib/module/components/AuthenticatedComponent.js +0 -24
  132. package/lib/module/components/AuthenticatedComponent.js.map +0 -1
  133. package/lib/module/components/AutoSigninDialog.js +0 -110
  134. package/lib/module/components/AutoSigninDialog.js.map +0 -1
  135. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
  136. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  137. package/lib/module/components/BottomSheetTextInput/index.js +0 -5
  138. package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
  139. package/lib/module/components/BottomSheetTextInput/types.js +0 -2
  140. package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
  141. package/lib/module/components/DarkText.js +0 -24
  142. package/lib/module/components/DarkText.js.map +0 -1
  143. package/lib/module/components/DefaultContext.js +0 -244
  144. package/lib/module/components/DefaultContext.js.map +0 -1
  145. package/lib/module/components/RowndComponents.js +0 -12
  146. package/lib/module/components/RowndComponents.js.map +0 -1
  147. package/lib/module/components/RowndProvider.js +0 -39
  148. package/lib/module/components/RowndProvider.js.map +0 -1
  149. package/lib/module/components/SignIn.js +0 -616
  150. package/lib/module/components/SignIn.js.map +0 -1
  151. package/lib/module/components/images/CheckmarkFilled.js +0 -27
  152. package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
  153. package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
  154. package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
  155. package/lib/module/components/images/ErrorIcon.js +0 -18
  156. package/lib/module/components/images/ErrorIcon.js.map +0 -1
  157. package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
  158. package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
  159. package/lib/module/data/actions.js +0 -19
  160. package/lib/module/data/actions.js.map +0 -1
  161. package/lib/module/hooks/api.js +0 -135
  162. package/lib/module/hooks/api.js.map +0 -1
  163. package/lib/module/hooks/debounce.js +0 -29
  164. package/lib/module/hooks/debounce.js.map +0 -1
  165. package/lib/module/hooks/fingerprint.js +0 -157
  166. package/lib/module/hooks/fingerprint.js.map +0 -1
  167. package/lib/module/hooks/index.js +0 -7
  168. package/lib/module/hooks/index.js.map +0 -1
  169. package/lib/module/hooks/interval.js +0 -23
  170. package/lib/module/hooks/interval.js.map +0 -1
  171. package/lib/module/hooks/nav.js +0 -30
  172. package/lib/module/hooks/nav.js.map +0 -1
  173. package/lib/module/index.tsx.bak +0 -26
  174. package/lib/module/types.js +0 -2
  175. package/lib/module/types.js.map +0 -1
  176. package/lib/module/utils/events.js +0 -45
  177. package/lib/module/utils/events.js.map +0 -1
  178. package/lib/module/utils/form.js +0 -34
  179. package/lib/module/utils/form.js.map +0 -1
  180. package/lib/module/utils/queue.js +0 -109
  181. package/lib/module/utils/queue.js.map +0 -1
  182. package/lib/module/utils/storage.js +0 -6
  183. package/lib/module/utils/storage.js.map +0 -1
  184. package/lib/module/utils/tokens.js +0 -24
  185. package/lib/module/utils/tokens.js.map +0 -1
  186. package/lib/module/utils/user-data.js +0 -14
  187. package/lib/module/utils/user-data.js.map +0 -1
  188. package/lib/package.json +0 -173
  189. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
  190. package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
  191. package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
  192. package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
  193. package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
  194. package/lib/typescript/src/components/DarkText.d.ts +0 -3
  195. package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
  196. package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
  197. package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
  198. package/lib/typescript/src/components/SignIn.d.ts +0 -2
  199. package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
  200. package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
  201. package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
  202. package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
  203. package/lib/typescript/src/data/actions.d.ts +0 -20
  204. package/lib/typescript/src/hooks/api.d.ts +0 -12
  205. package/lib/typescript/src/hooks/debounce.d.ts +0 -5
  206. package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
  207. package/lib/typescript/src/hooks/index.d.ts +0 -6
  208. package/lib/typescript/src/hooks/interval.d.ts +0 -2
  209. package/lib/typescript/src/hooks/nav.d.ts +0 -6
  210. package/lib/typescript/src/index.d.ts +0 -4
  211. package/lib/typescript/src/types.d.ts +0 -26
  212. package/lib/typescript/src/utils/config.d.ts +0 -18
  213. package/lib/typescript/src/utils/events.d.ts +0 -22
  214. package/lib/typescript/src/utils/form.d.ts +0 -18
  215. package/lib/typescript/src/utils/queue.d.ts +0 -21
  216. package/lib/typescript/src/utils/storage.d.ts +0 -3
  217. package/lib/typescript/src/utils/tokens.d.ts +0 -4
  218. package/lib/typescript/src/utils/user-data.d.ts +0 -3
  219. package/react-native.podspec +0 -19
  220. package/src/assets/images/checkmark--filled.svg +0 -12
  221. package/src/assets/images/email-verify-waiting.svg +0 -36
  222. package/src/assets/images/error-icon-material.svg +0 -1
  223. package/src/assets/images/phone-verify-waiting.svg +0 -26
  224. package/src/components/AuthenticatedComponent.tsx +0 -30
  225. package/src/components/AutoSigninDialog.tsx +0 -131
  226. package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
  227. package/src/components/BottomSheetTextInput/index.ts +0 -5
  228. package/src/components/BottomSheetTextInput/types.ts +0 -3
  229. package/src/components/DarkText.tsx +0 -16
  230. package/src/components/DefaultContext.tsx +0 -278
  231. package/src/components/RowndComponents.tsx +0 -18
  232. package/src/components/RowndProvider.tsx +0 -56
  233. package/src/components/SignIn.tsx +0 -797
  234. package/src/components/images/CheckmarkFilled.tsx +0 -30
  235. package/src/components/images/EmailVerifyWaiting.tsx +0 -95
  236. package/src/components/images/ErrorIcon.tsx +0 -11
  237. package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
  238. package/src/data/actions.ts +0 -21
  239. package/src/hooks/api.ts +0 -162
  240. package/src/hooks/debounce.ts +0 -36
  241. package/src/hooks/fingerprint.ts +0 -217
  242. package/src/hooks/index.ts +0 -7
  243. package/src/hooks/interval.ts +0 -25
  244. package/src/hooks/nav.tsx +0 -29
  245. package/src/index.tsx.bak +0 -26
  246. package/src/types.ts +0 -27
  247. package/src/utils/events.ts +0 -54
  248. package/src/utils/form.tsx +0 -64
  249. package/src/utils/queue.ts +0 -75
  250. package/src/utils/storage.ts +0 -7
  251. package/src/utils/tokens.ts +0 -26
  252. 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,49 @@ 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.
16
+ ### Android
17
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
- ```
18
+ ```sh
19
+ cd android
20
+ ```
21
+ ```sh
22
+ ./gradlew build
23
+ ```
33
24
 
25
+ ### iOS
34
26
 
35
- Once those are installed, run this command to ensure the iOS build can find the native components.
27
+ Add the code below to ios/Podfile. Place inside target
28
+ ```
29
+ dynamic_frameworks = ['Sodium']
30
+ pre_install do |installer|
31
+ installer.pod_targets.each do |pod|
32
+ if dynamic_frameworks.include?(pod.name)
33
+ puts "Overriding the dynamic_framework? method for #{pod.name}"
34
+ def pod.dynamic_framework?;
35
+ true
36
+ end
37
+ def pod.build_type;
38
+ Pod::BuildType.dynamic_framework
39
+ end
40
+ end
41
+ end
42
+ end
43
+ ```
44
+ On command line run:
36
45
 
37
46
  ```sh
38
- npx pod-install
47
+ cd ios
48
+ ```
49
+ ```sh
50
+ pod install
39
51
  ```
40
52
 
41
53
  ## Setup
42
54
 
43
55
  ### Enable deep linking
44
56
  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
57
+ app or when they click a sign-in link when the app is already installed.
53
58
 
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
59
 
70
60
  ## Usage
71
61
  The Rownd SDK includes a context provider that will enable any component of your app to access authentication state and user data.
@@ -79,11 +69,9 @@ import { RowndProvider } from "@rownd/react-native";
79
69
 
80
70
  export default function Root() {
81
71
  return (
82
- <GestureHandlerRootView>
83
- <RowndProvider appKey="<your app key>">
72
+ <RowndProvider config={{appKey:"<your app key>"}}>
84
73
  <App />
85
74
  </RowndProvider>
86
- </GestureHandlerRootView>
87
75
  );
88
76
  }
89
77
  ```
@@ -92,7 +80,7 @@ Later on within your app's components, you can use the Rownd hook to access the
92
80
 
93
81
  ```tsx
94
82
  import { View, Text } from 'react-native';
95
- import { useRownd } from '@rownd/react';
83
+ import { useRownd } from '@rownd/react-native';
96
84
 
97
85
  export default function MyProtectedComponent(props) {
98
86
  const { is_authenticated, user, requestSignIn, getAccessToken } = useRownd();
@@ -136,15 +124,9 @@ Trigger the Rownd sign in dialog
136
124
  ```javascript
137
125
  const { requestSignIn } = useRownd();
138
126
 
139
- requestSignIn({
140
- auto_sign_in: false, // optional
141
- identifier: 'me@company.com' || '+19105551212' // optional
142
- });
127
+ requestSignIn();
143
128
  ```
144
129
 
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
130
  #### signOut()
149
131
 
150
132
  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,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.manageUser()
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
+