@juspay-tech/react-native-hyperswitch 0.2.1

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 (261) hide show
  1. package/HyperswitchSdkReactNative.podspec +31 -0
  2. package/android/build.gradle +119 -0
  3. package/android/gradle.properties +5 -0
  4. package/android/hyperswitch_autolinking.gradle +378 -0
  5. package/android/proguard-rules.pro +72 -0
  6. package/android/src/main/AndroidManifest.xml +25 -0
  7. package/android/src/main/assets/hyperswitch.bundle +1677 -0
  8. package/android/src/main/java/com/hyperswitchsdkreactnative/HyperswitchSdkReactNativePackage.kt +36 -0
  9. package/android/src/main/java/com/hyperswitchsdkreactnative/activity/RedirectActivity.kt +39 -0
  10. package/android/src/main/java/com/hyperswitchsdkreactnative/internal/DefaultReactHost.kt +314 -0
  11. package/android/src/main/java/com/hyperswitchsdkreactnative/internal/DefaultReactNativeHost.kt +131 -0
  12. package/android/src/main/java/com/hyperswitchsdkreactnative/internal/ReactDelegate.kt +423 -0
  13. package/android/src/main/java/com/hyperswitchsdkreactnative/internal/ReactFragment.kt +335 -0
  14. package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkNativeModule.kt +143 -0
  15. package/android/src/main/java/com/hyperswitchsdkreactnative/modules/HyperswitchSdkReactNativeModule.kt +92 -0
  16. package/android/src/main/java/com/hyperswitchsdkreactnative/provider/HyperProvider.kt +269 -0
  17. package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonView.kt +60 -0
  18. package/android/src/main/java/com/hyperswitchsdkreactnative/views/GooglePayButtonViewManager.kt +76 -0
  19. package/android/src/main/java/io/hyperswitch/hyperota/HyperOtaLogger.kt +122 -0
  20. package/android/src/main/java/io/hyperswitch/logs/CrashHandler.kt +29 -0
  21. package/android/src/main/java/io/hyperswitch/logs/Debouncer.kt +20 -0
  22. package/android/src/main/java/io/hyperswitch/logs/HyperLogManager.kt +113 -0
  23. package/android/src/main/java/io/hyperswitch/logs/LogData.kt +159 -0
  24. package/android/src/main/java/io/hyperswitch/logs/LogFileManager.kt +60 -0
  25. package/android/src/main/java/io/hyperswitch/networking/HyperNetworking.kt +73 -0
  26. package/android/src/main/java/io/hyperswitch/react/Utils.kt +23 -0
  27. package/android/src/main/res/values/attrs.xml +6 -0
  28. package/android/src/main/res/values/strings.xml +5 -0
  29. package/android/src/main/res/values/theme.xml +16 -0
  30. package/ios/Modules/HyperswitchModule.swift +61 -0
  31. package/ios/Modules/HyperswitchNativeModule.swift +113 -0
  32. package/ios/Modules/HyperswitchSdkNative.h +5 -0
  33. package/ios/Modules/HyperswitchSdkNative.mm +98 -0
  34. package/ios/Modules/HyperswitchSdkReactNative.h +5 -0
  35. package/ios/Modules/HyperswitchSdkReactNative.mm +53 -0
  36. package/ios/Views/ApplePayView.h +14 -0
  37. package/ios/Views/ApplePayView.mm +89 -0
  38. package/ios/hyperswitchSDK/Core/ApplePay/ApplePayHandler.swift +249 -0
  39. package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.m +18 -0
  40. package/ios/hyperswitchSDK/Core/ApplePay/ApplePayViewManager.swift +123 -0
  41. package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+SwiftUI.swift +49 -0
  42. package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView+UIKit.swift +49 -0
  43. package/ios/hyperswitchSDK/Core/HyperPaymentSheet/PaymentSheetView.swift +80 -0
  44. package/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +176 -0
  45. package/ios/hyperswitchSDK/Core/HyperSession/PaymentSessionTypes.swift +121 -0
  46. package/ios/hyperswitchSDK/Core/Models/LogPayload.swift +53 -0
  47. package/ios/hyperswitchSDK/Core/NativeLogger/Debouncer.swift +37 -0
  48. package/ios/hyperswitchSDK/Core/NativeLogger/LogBuilder.swift +91 -0
  49. package/ios/hyperswitchSDK/Core/NativeLogger/LogFileManager.swift +75 -0
  50. package/ios/hyperswitchSDK/Core/NativeLogger/LogManager.swift +113 -0
  51. package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.m +16 -0
  52. package/ios/hyperswitchSDK/Core/NativeModule/HyperHeadless.swift +74 -0
  53. package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.m +28 -0
  54. package/ios/hyperswitchSDK/Core/NativeModule/HyperModule.swift +168 -0
  55. package/ios/hyperswitchSDK/Core/NativeModule/OTAServices.swift +113 -0
  56. package/ios/hyperswitchSDK/Core/NativeModule/RNHeadlessManager.swift +45 -0
  57. package/ios/hyperswitchSDK/Core/NativeModule/RNResponseHandler.swift +12 -0
  58. package/ios/hyperswitchSDK/Core/NativeModule/RNViewManager.swift +90 -0
  59. package/ios/hyperswitchSDK/Core/NativeModule/hyper-Bridging-Header.h +9 -0
  60. package/ios/hyperswitchSDK/Core/Resources/HyperOTA.plist +20 -0
  61. package/ios/hyperswitchSDK/Core/Resources/hyperswitch.bundle +1673 -0
  62. package/ios/hyperswitchSDK/Shared/APIClient.swift +21 -0
  63. package/ios/hyperswitchSDK/Shared/DictionaryConverter.swift +104 -0
  64. package/ios/hyperswitchSDK/Shared/Environment.swift +24 -0
  65. package/ios/hyperswitchSDK/Shared/Extensions.swift +31 -0
  66. package/ios/hyperswitchSDK/Shared/Helper.swift +16 -0
  67. package/ios/hyperswitchSDK/Shared/HyperNetworking.swift +137 -0
  68. package/ios/hyperswitchSDK/Shared/HyperParams.swift +44 -0
  69. package/ios/hyperswitchSDK/Shared/HyperUIViewController.swift +25 -0
  70. package/ios/hyperswitchSDK/Shared/PaymentSession.swift +43 -0
  71. package/ios/hyperswitchSDK/Shared/PaymentSheet.swift +30 -0
  72. package/ios/hyperswitchSDK/Shared/PaymentSheetAppearance.swift +264 -0
  73. package/ios/hyperswitchSDK/Shared/PaymentSheetConfiguration.swift +494 -0
  74. package/ios/hyperswitchSDK/Shared/SwiftUIManager.swift +28 -0
  75. package/ios/hyperswitchSDK/Shared/Version.swift +12 -0
  76. package/lib/bs/JuspayTechReactNativeHyperswitch.cmi +0 -0
  77. package/lib/bs/JuspayTechReactNativeHyperswitch.cmj +0 -0
  78. package/lib/bs/JuspayTechReactNativeHyperswitch.cmt +0 -0
  79. package/lib/bs/JuspayTechReactNativeHyperswitch.mlmap +5 -0
  80. package/lib/bs/build.ninja +29 -0
  81. package/lib/bs/install.ninja +25 -0
  82. package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmi +0 -0
  83. package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmj +0 -0
  84. package/lib/bs/src/context/HyperProvider-JuspayTechReactNativeHyperswitch.cmt +0 -0
  85. package/lib/bs/src/context/HyperProvider.ast +0 -0
  86. package/lib/bs/src/context/HyperProvider.d +1 -0
  87. package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmi +0 -0
  88. package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmj +0 -0
  89. package/lib/bs/src/hooks/useHyper-JuspayTechReactNativeHyperswitch.cmt +0 -0
  90. package/lib/bs/src/hooks/useHyper.ast +0 -0
  91. package/lib/bs/src/hooks/useHyper.d +1 -0
  92. package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmi +0 -0
  93. package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmj +0 -0
  94. package/lib/bs/src/modules/NativeHyperswitchSdk-JuspayTechReactNativeHyperswitch.cmt +0 -0
  95. package/lib/bs/src/modules/NativeHyperswitchSdk.ast +0 -0
  96. package/lib/bs/src/modules/NativeHyperswitchSdk.d +1 -0
  97. package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmi +0 -0
  98. package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmj +0 -0
  99. package/lib/bs/src/types/PaymentSheetConfiguration-JuspayTechReactNativeHyperswitch.cmt +0 -0
  100. package/lib/bs/src/types/PaymentSheetConfiguration.ast +0 -0
  101. package/lib/bs/src/types/PaymentSheetConfiguration.d +1 -0
  102. package/lib/commonjs/context/HyperProvider.gen.js +16 -0
  103. package/lib/commonjs/context/HyperProvider.gen.js.map +1 -0
  104. package/lib/commonjs/context/HyperProvider.res +78 -0
  105. package/lib/commonjs/context/HyperProvider.res.js +98 -0
  106. package/lib/commonjs/context/HyperProvider.res.js.map +1 -0
  107. package/lib/commonjs/hooks/useHyper.gen.js +15 -0
  108. package/lib/commonjs/hooks/useHyper.gen.js.map +1 -0
  109. package/lib/commonjs/hooks/useHyper.res +142 -0
  110. package/lib/commonjs/hooks/useHyper.res.js +152 -0
  111. package/lib/commonjs/hooks/useHyper.res.js.map +1 -0
  112. package/lib/commonjs/index.js +26 -0
  113. package/lib/commonjs/index.js.map +1 -0
  114. package/lib/commonjs/modules/NativeHyperswitchSdk.gen.js +6 -0
  115. package/lib/commonjs/modules/NativeHyperswitchSdk.gen.js.map +1 -0
  116. package/lib/commonjs/modules/NativeHyperswitchSdk.res +55 -0
  117. package/lib/commonjs/modules/NativeHyperswitchSdk.res.js +14 -0
  118. package/lib/commonjs/modules/NativeHyperswitchSdk.res.js.map +1 -0
  119. package/lib/commonjs/package.json +1 -0
  120. package/lib/commonjs/shims/Js.shim.js +2 -0
  121. package/lib/commonjs/shims/Js.shim.js.map +1 -0
  122. package/lib/commonjs/specs/ApplePayButtonNativeComponent.ts +11 -0
  123. package/lib/commonjs/specs/GooglePayButtonNativeComponent.android.js +10 -0
  124. package/lib/commonjs/specs/GooglePayButtonNativeComponent.android.js.map +1 -0
  125. package/lib/commonjs/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
  126. package/lib/commonjs/specs/NativeHyperswitchSdkNative.js +9 -0
  127. package/lib/commonjs/specs/NativeHyperswitchSdkNative.js.map +1 -0
  128. package/lib/commonjs/specs/NativeHyperswitchSdkReactNative.js +9 -0
  129. package/lib/commonjs/specs/NativeHyperswitchSdkReactNative.js.map +1 -0
  130. package/lib/commonjs/types/PaymentSheetConfiguration.gen.js +2 -0
  131. package/lib/commonjs/types/PaymentSheetConfiguration.gen.js.map +1 -0
  132. package/lib/commonjs/types/PaymentSheetConfiguration.res +215 -0
  133. package/lib/commonjs/types/PaymentSheetConfiguration.res.js +4 -0
  134. package/lib/commonjs/types/PaymentSheetConfiguration.res.js.map +1 -0
  135. package/lib/module/context/HyperProvider.gen.js +11 -0
  136. package/lib/module/context/HyperProvider.gen.js.map +1 -0
  137. package/lib/module/context/HyperProvider.res +78 -0
  138. package/lib/module/context/HyperProvider.res.js +91 -0
  139. package/lib/module/context/HyperProvider.res.js.map +1 -0
  140. package/lib/module/hooks/useHyper.gen.js +10 -0
  141. package/lib/module/hooks/useHyper.gen.js.map +1 -0
  142. package/lib/module/hooks/useHyper.res +142 -0
  143. package/lib/module/hooks/useHyper.res.js +142 -0
  144. package/lib/module/hooks/useHyper.res.js.map +1 -0
  145. package/lib/module/index.js +5 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/modules/NativeHyperswitchSdk.gen.js +4 -0
  148. package/lib/module/modules/NativeHyperswitchSdk.gen.js.map +1 -0
  149. package/lib/module/modules/NativeHyperswitchSdk.res +55 -0
  150. package/lib/module/modules/NativeHyperswitchSdk.res.js +9 -0
  151. package/lib/module/modules/NativeHyperswitchSdk.res.js.map +1 -0
  152. package/lib/module/package.json +1 -0
  153. package/lib/module/shims/Js.shim.js +2 -0
  154. package/lib/module/shims/Js.shim.js.map +1 -0
  155. package/lib/module/specs/ApplePayButtonNativeComponent.ts +11 -0
  156. package/lib/module/specs/GooglePayButtonNativeComponent.android.js +5 -0
  157. package/lib/module/specs/GooglePayButtonNativeComponent.android.js.map +1 -0
  158. package/lib/module/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
  159. package/lib/module/specs/NativeHyperswitchSdkNative.js +5 -0
  160. package/lib/module/specs/NativeHyperswitchSdkNative.js.map +1 -0
  161. package/lib/module/specs/NativeHyperswitchSdkReactNative.js +5 -0
  162. package/lib/module/specs/NativeHyperswitchSdkReactNative.js.map +1 -0
  163. package/lib/module/types/PaymentSheetConfiguration.gen.js +2 -0
  164. package/lib/module/types/PaymentSheetConfiguration.gen.js.map +1 -0
  165. package/lib/module/types/PaymentSheetConfiguration.res +215 -0
  166. package/lib/module/types/PaymentSheetConfiguration.res.js +4 -0
  167. package/lib/module/types/PaymentSheetConfiguration.res.js.map +1 -0
  168. package/lib/typescript/commonjs/babel.config.d.ts +10 -0
  169. package/lib/typescript/commonjs/babel.config.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/eslint.config.d.mts +3 -0
  171. package/lib/typescript/commonjs/eslint.config.d.mts.map +1 -0
  172. package/lib/typescript/commonjs/package.json +1 -0
  173. package/lib/typescript/commonjs/scripts/bootstrap.d.ts +2 -0
  174. package/lib/typescript/commonjs/scripts/bootstrap.d.ts.map +1 -0
  175. package/lib/typescript/commonjs/src/context/HyperProvider.gen.d.ts +17 -0
  176. package/lib/typescript/commonjs/src/context/HyperProvider.gen.d.ts.map +1 -0
  177. package/lib/typescript/commonjs/src/context/HyperProvider.res.d.ts +20 -0
  178. package/lib/typescript/commonjs/src/context/HyperProvider.res.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/src/hooks/useHyper.gen.d.ts +10 -0
  180. package/lib/typescript/commonjs/src/hooks/useHyper.gen.d.ts.map +1 -0
  181. package/lib/typescript/commonjs/src/hooks/useHyper.res.d.ts +95 -0
  182. package/lib/typescript/commonjs/src/hooks/useHyper.res.d.ts.map +1 -0
  183. package/lib/typescript/commonjs/src/index.d.ts +4 -0
  184. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.gen.d.ts +24 -0
  186. package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.gen.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.res.d.ts +2 -0
  188. package/lib/typescript/commonjs/src/modules/NativeHyperswitchSdk.res.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/src/shims/Js.shim.d.ts +4 -0
  190. package/lib/typescript/commonjs/src/shims/Js.shim.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/src/specs/ApplePayButtonNativeComponent.d.ts +10 -0
  192. package/lib/typescript/commonjs/src/specs/ApplePayButtonNativeComponent.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/src/specs/GooglePayButtonNativeComponent.android.d.ts +11 -0
  194. package/lib/typescript/commonjs/src/specs/GooglePayButtonNativeComponent.android.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts +1 -0
  196. package/lib/typescript/commonjs/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkNative.d.ts +17 -0
  198. package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkReactNative.d.ts +9 -0
  200. package/lib/typescript/commonjs/src/specs/NativeHyperswitchSdkReactNative.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.gen.d.ts +149 -0
  202. package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.gen.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.res.d.ts +1 -0
  204. package/lib/typescript/commonjs/src/types/PaymentSheetConfiguration.res.d.ts.map +1 -0
  205. package/lib/typescript/module/babel.config.d.ts +10 -0
  206. package/lib/typescript/module/babel.config.d.ts.map +1 -0
  207. package/lib/typescript/module/eslint.config.d.mts +3 -0
  208. package/lib/typescript/module/eslint.config.d.mts.map +1 -0
  209. package/lib/typescript/module/package.json +1 -0
  210. package/lib/typescript/module/scripts/bootstrap.d.ts +2 -0
  211. package/lib/typescript/module/scripts/bootstrap.d.ts.map +1 -0
  212. package/lib/typescript/module/src/context/HyperProvider.gen.d.ts +17 -0
  213. package/lib/typescript/module/src/context/HyperProvider.gen.d.ts.map +1 -0
  214. package/lib/typescript/module/src/context/HyperProvider.res.d.ts +20 -0
  215. package/lib/typescript/module/src/context/HyperProvider.res.d.ts.map +1 -0
  216. package/lib/typescript/module/src/hooks/useHyper.gen.d.ts +10 -0
  217. package/lib/typescript/module/src/hooks/useHyper.gen.d.ts.map +1 -0
  218. package/lib/typescript/module/src/hooks/useHyper.res.d.ts +95 -0
  219. package/lib/typescript/module/src/hooks/useHyper.res.d.ts.map +1 -0
  220. package/lib/typescript/module/src/index.d.ts +4 -0
  221. package/lib/typescript/module/src/index.d.ts.map +1 -0
  222. package/lib/typescript/module/src/modules/NativeHyperswitchSdk.gen.d.ts +24 -0
  223. package/lib/typescript/module/src/modules/NativeHyperswitchSdk.gen.d.ts.map +1 -0
  224. package/lib/typescript/module/src/modules/NativeHyperswitchSdk.res.d.ts +2 -0
  225. package/lib/typescript/module/src/modules/NativeHyperswitchSdk.res.d.ts.map +1 -0
  226. package/lib/typescript/module/src/shims/Js.shim.d.ts +4 -0
  227. package/lib/typescript/module/src/shims/Js.shim.d.ts.map +1 -0
  228. package/lib/typescript/module/src/specs/ApplePayButtonNativeComponent.d.ts +10 -0
  229. package/lib/typescript/module/src/specs/ApplePayButtonNativeComponent.d.ts.map +1 -0
  230. package/lib/typescript/module/src/specs/GooglePayButtonNativeComponent.android.d.ts +11 -0
  231. package/lib/typescript/module/src/specs/GooglePayButtonNativeComponent.android.d.ts.map +1 -0
  232. package/lib/typescript/module/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts +1 -0
  233. package/lib/typescript/module/src/specs/HyperswitchSdkReactNativeViewNativeComponent.d.ts.map +1 -0
  234. package/lib/typescript/module/src/specs/NativeHyperswitchSdkNative.d.ts +17 -0
  235. package/lib/typescript/module/src/specs/NativeHyperswitchSdkNative.d.ts.map +1 -0
  236. package/lib/typescript/module/src/specs/NativeHyperswitchSdkReactNative.d.ts +9 -0
  237. package/lib/typescript/module/src/specs/NativeHyperswitchSdkReactNative.d.ts.map +1 -0
  238. package/lib/typescript/module/src/types/PaymentSheetConfiguration.gen.d.ts +149 -0
  239. package/lib/typescript/module/src/types/PaymentSheetConfiguration.gen.d.ts.map +1 -0
  240. package/lib/typescript/module/src/types/PaymentSheetConfiguration.res.d.ts +1 -0
  241. package/lib/typescript/module/src/types/PaymentSheetConfiguration.res.d.ts.map +1 -0
  242. package/package.json +196 -0
  243. package/src/context/HyperProvider.gen.tsx +26 -0
  244. package/src/context/HyperProvider.res +78 -0
  245. package/src/context/HyperProvider.res.js +112 -0
  246. package/src/hooks/useHyper.gen.tsx +18 -0
  247. package/src/hooks/useHyper.res +142 -0
  248. package/src/hooks/useHyper.res.js +157 -0
  249. package/src/index.tsx +13 -0
  250. package/src/modules/NativeHyperswitchSdk.gen.tsx +25 -0
  251. package/src/modules/NativeHyperswitchSdk.res +55 -0
  252. package/src/modules/NativeHyperswitchSdk.res.js +10 -0
  253. package/src/shims/Js.shim.ts +5 -0
  254. package/src/specs/ApplePayButtonNativeComponent.ts +11 -0
  255. package/src/specs/GooglePayButtonNativeComponent.android.ts +12 -0
  256. package/src/specs/HyperswitchSdkReactNativeViewNativeComponent.ts +10 -0
  257. package/src/specs/NativeHyperswitchSdkNative.ts +33 -0
  258. package/src/specs/NativeHyperswitchSdkReactNative.ts +17 -0
  259. package/src/types/PaymentSheetConfiguration.gen.tsx +202 -0
  260. package/src/types/PaymentSheetConfiguration.res +215 -0
  261. package/src/types/PaymentSheetConfiguration.res.js +2 -0
@@ -0,0 +1,423 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.hyperswitchsdkreactnative.internal
9
+
10
+ import android.app.Activity
11
+ import android.content.Intent
12
+ import android.content.res.Configuration
13
+ import android.os.Bundle
14
+ import android.view.KeyEvent
15
+ import com.facebook.react.ReactHost
16
+ import com.facebook.react.ReactInstanceManager
17
+ import com.facebook.react.ReactNativeHost
18
+ import com.facebook.react.ReactRootView
19
+ import com.facebook.react.bridge.ReactContext
20
+ import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
21
+ import com.facebook.react.devsupport.DoubleTapReloadRecognizer
22
+ import com.facebook.react.devsupport.ReleaseDevSupportManager
23
+ import com.facebook.react.devsupport.interfaces.DevSupportManager
24
+ import com.facebook.react.interfaces.fabric.ReactSurface
25
+ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
26
+ import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
27
+
28
+ /**
29
+ * A delegate for handling React Application support. This delegate is unaware whether it is used in
30
+ * an [Activity] or a [android.app.Fragment].
31
+ */
32
+ @Suppress("DEPRECATION")
33
+ internal open class ReactDelegate {
34
+ private val activity: Activity
35
+ private var internalReactRootView: ReactRootView? = null
36
+ private val mainComponentName: String?
37
+ private var launchOptions: Bundle?
38
+ private var doubleTapReloadRecognizer: DoubleTapReloadRecognizer?
39
+
40
+ @Deprecated(
41
+ "You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.",
42
+ ReplaceWith("reactHost"),
43
+ )
44
+ private var reactNativeHost: ReactNativeHost? = null
45
+ var reactHost: ReactHost? = null
46
+ private set
47
+
48
+ private var reactSurface: ReactSurface? = null
49
+
50
+ /**
51
+ * Override this method if you wish to selectively toggle Fabric for a specific surface. This will
52
+ * also control if Concurrent Root (React 18) should be enabled or not.
53
+ *
54
+ * @return true if Fabric is enabled for this Activity, false otherwise.
55
+ */
56
+ protected var isFabricEnabled: Boolean =
57
+ ReactNativeFeatureFlags.enableFabricRenderer()
58
+ private set
59
+
60
+ /**
61
+ * Do not use this constructor as it's not accounting for New Architecture at all. You should use
62
+ * [ReactDelegate(Activity, ReactNativeHost, String, Bundle, boolean)] as it's the constructor
63
+ * used for New Architecture.
64
+ */
65
+ @Deprecated(
66
+ "Use one of the other constructors instead to account for New Architecture. Deprecated since 0.75.0")
67
+ constructor(
68
+ activity: Activity,
69
+ reactNativeHost: ReactNativeHost?,
70
+ appKey: String?,
71
+ launchOptions: Bundle?,
72
+ ) {
73
+ this.activity = activity
74
+ mainComponentName = appKey
75
+ this.launchOptions = launchOptions
76
+ doubleTapReloadRecognizer = DoubleTapReloadRecognizer()
77
+ this.reactNativeHost = reactNativeHost
78
+ }
79
+
80
+ constructor(
81
+ activity: Activity,
82
+ reactHost: ReactHost?,
83
+ appKey: String?,
84
+ launchOptions: Bundle?,
85
+ ) {
86
+ this.activity = activity
87
+ mainComponentName = appKey
88
+ this.launchOptions = launchOptions
89
+ doubleTapReloadRecognizer = DoubleTapReloadRecognizer()
90
+ this.reactHost = reactHost
91
+ }
92
+
93
+ @Deprecated("Deprecated since 0.81.0, use one of the other constructors instead.")
94
+ constructor(
95
+ activity: Activity,
96
+ reactNativeHost: ReactNativeHost?,
97
+ appKey: String?,
98
+ launchOptions: Bundle?,
99
+ fabricEnabled: Boolean,
100
+ ) {
101
+ isFabricEnabled = fabricEnabled
102
+ this.activity = activity
103
+ mainComponentName = appKey
104
+ this.launchOptions = launchOptions
105
+ doubleTapReloadRecognizer = DoubleTapReloadRecognizer()
106
+ this.reactNativeHost = reactNativeHost
107
+ }
108
+
109
+ private val devSupportManager: DevSupportManager?
110
+ get() =
111
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
112
+ reactHost?.devSupportManager != null) {
113
+ reactHost?.devSupportManager
114
+ } else if (reactNativeHost?.hasInstance() == true &&
115
+ reactNativeHost?.reactInstanceManager != null) {
116
+ reactNativeHost?.reactInstanceManager?.devSupportManager
117
+ } else {
118
+ null
119
+ }
120
+
121
+ fun onHostResume() {
122
+ if (activity !is DefaultHardwareBackBtnHandler) {
123
+ throw ClassCastException(
124
+ "Host Activity `${activity.javaClass.simpleName}` does not implement DefaultHardwareBackBtnHandler")
125
+ }
126
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
127
+ reactHost != null) {
128
+ reactHost?.onHostResume(activity, activity as DefaultHardwareBackBtnHandler)
129
+ } else {
130
+ if (reactNativeHost?.hasInstance() == true) {
131
+ reactNativeHost
132
+ ?.reactInstanceManager
133
+ ?.onHostResume(activity, activity as DefaultHardwareBackBtnHandler)
134
+ }
135
+ }
136
+ }
137
+
138
+ fun onUserLeaveHint() {
139
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
140
+ reactHost != null) {
141
+ reactHost?.onHostLeaveHint(activity)
142
+ } else {
143
+ if (reactNativeHost?.hasInstance() == true) {
144
+ reactNativeHost?.reactInstanceManager?.onUserLeaveHint(activity)
145
+ }
146
+ }
147
+ }
148
+
149
+ fun onHostPause() {
150
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
151
+ reactHost != null) {
152
+ reactHost?.onHostPause(activity)
153
+ } else {
154
+ if (reactNativeHost?.hasInstance() == true) {
155
+ reactNativeHost?.reactInstanceManager?.onHostPause(activity)
156
+ }
157
+ }
158
+ }
159
+
160
+ fun onHostDestroy() {
161
+ unloadApp()
162
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
163
+ reactHost != null) {
164
+ reactHost?.onHostDestroy(activity)
165
+ } else {
166
+ if (reactNativeHost?.hasInstance() == true) {
167
+ reactNativeHost?.reactInstanceManager?.onHostDestroy(activity)
168
+ }
169
+ }
170
+ }
171
+
172
+ fun onBackPressed(): Boolean {
173
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
174
+ reactHost != null) {
175
+ reactHost?.onBackPressed()
176
+ return true
177
+ } else {
178
+ if (reactNativeHost?.hasInstance() == true) {
179
+ reactNativeHost?.reactInstanceManager?.onBackPressed()
180
+ return true
181
+ }
182
+ }
183
+ return false
184
+ }
185
+
186
+ fun onNewIntent(intent: Intent): Boolean {
187
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
188
+ reactHost != null) {
189
+ reactHost?.onNewIntent(intent)
190
+ return true
191
+ } else {
192
+ if (reactNativeHost?.hasInstance() == true) {
193
+ reactNativeHost?.reactInstanceManager?.onNewIntent(intent)
194
+ return true
195
+ }
196
+ }
197
+ return false
198
+ }
199
+
200
+ fun onActivityResult(
201
+ requestCode: Int,
202
+ resultCode: Int,
203
+ data: Intent?,
204
+ shouldForwardToReactInstance: Boolean,
205
+ ) {
206
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
207
+ reactHost != null &&
208
+ shouldForwardToReactInstance) {
209
+ reactHost?.onActivityResult(activity, requestCode, resultCode, data)
210
+ } else {
211
+ if (reactNativeHost?.hasInstance() == true && shouldForwardToReactInstance) {
212
+ reactNativeHost
213
+ ?.reactInstanceManager
214
+ ?.onActivityResult(activity, requestCode, resultCode, data)
215
+ }
216
+ }
217
+ }
218
+
219
+ fun onWindowFocusChanged(hasFocus: Boolean) {
220
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
221
+ reactHost != null) {
222
+ reactHost?.onWindowFocusChange(hasFocus)
223
+ } else {
224
+ if (reactNativeHost?.hasInstance() == true) {
225
+ reactNativeHost?.reactInstanceManager?.onWindowFocusChange(hasFocus)
226
+ }
227
+ }
228
+ }
229
+
230
+ fun onConfigurationChanged(newConfig: Configuration?) {
231
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
232
+ reactHost != null) {
233
+ reactHost?.onConfigurationChanged(checkNotNull(activity))
234
+ } else {
235
+ if (reactNativeHost?.hasInstance() == true) {
236
+ getReactInstanceManager().onConfigurationChanged(checkNotNull(activity), newConfig)
237
+ }
238
+ }
239
+ }
240
+
241
+ fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
242
+ if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD &&
243
+ ((ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
244
+ reactHost?.devSupportManager != null) ||
245
+ (reactNativeHost?.hasInstance() == true &&
246
+ reactNativeHost?.useDeveloperSupport == true))) {
247
+ event.startTracking()
248
+ return true
249
+ }
250
+ return false
251
+ }
252
+
253
+ fun onKeyLongPress(keyCode: Int): Boolean {
254
+ if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
255
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture() &&
256
+ reactHost != null) {
257
+ val devSupportManager = reactHost?.devSupportManager
258
+ // onKeyLongPress is a Dev API and not supported in RELEASE mode.
259
+ if (devSupportManager != null && devSupportManager !is ReleaseDevSupportManager) {
260
+ devSupportManager.showDevOptionsDialog()
261
+ return true
262
+ }
263
+ } else {
264
+ if (reactNativeHost?.hasInstance() == true &&
265
+ reactNativeHost?.useDeveloperSupport == true) {
266
+ reactNativeHost?.reactInstanceManager?.showDevOptionsDialog()
267
+ return true
268
+ }
269
+ }
270
+ }
271
+ return false
272
+ }
273
+
274
+ fun reload() {
275
+ val devSupportManager = devSupportManager ?: return
276
+
277
+ // Reload in RELEASE mode
278
+ if (devSupportManager is ReleaseDevSupportManager) {
279
+ // Do not reload the bundle from JS as there is no bundler running in release mode.
280
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
281
+ reactHost?.reload("ReactDelegate.reload()")
282
+ } else {
283
+ runOnUiThread {
284
+ if (reactNativeHost?.hasInstance() == true &&
285
+ reactNativeHost?.reactInstanceManager != null) {
286
+ reactNativeHost?.reactInstanceManager?.recreateReactContextInBackground()
287
+ }
288
+ }
289
+ }
290
+ return
291
+ }
292
+
293
+ // Reload in DEBUG mode
294
+ devSupportManager.handleReloadJS()
295
+ }
296
+
297
+ /** Start the React surface with the app key supplied in the [ReactDelegate] constructor. */
298
+ fun loadApp() {
299
+ val name = requireNotNull(mainComponentName) { "Cannot loadApp without a main component name." }
300
+ loadApp(name)
301
+ }
302
+
303
+ /**
304
+ * Start the React surface for the given app key.
305
+ *
306
+ * @param appKey The ID of the app to load into the surface.
307
+ */
308
+ fun loadApp(appKey: String) {
309
+ // With Bridgeless enabled, create and start the surface
310
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
311
+ val reactHost = reactHost
312
+ if (reactSurface == null && reactHost != null) {
313
+ reactSurface = reactHost.createSurface(activity, appKey, launchOptions)
314
+ }
315
+ reactSurface?.start()
316
+ } else {
317
+ check(internalReactRootView == null) { "Cannot loadApp while app is already running." }
318
+ internalReactRootView = createRootView()
319
+ if (reactNativeHost != null) {
320
+ internalReactRootView?.startReactApplication(
321
+ reactNativeHost?.reactInstanceManager,
322
+ appKey,
323
+ launchOptions,
324
+ )
325
+ }
326
+ }
327
+ }
328
+
329
+ /** Stop the React surface started with [ReactDelegate.loadApp]. */
330
+ fun unloadApp() {
331
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
332
+ reactSurface?.stop()
333
+ reactSurface = null
334
+ } else {
335
+ if (internalReactRootView != null) {
336
+ internalReactRootView?.unmountReactApplication()
337
+ internalReactRootView = null
338
+ }
339
+ }
340
+ }
341
+
342
+ fun setReactSurface(reactSurface: ReactSurface?) {
343
+ this.reactSurface = reactSurface
344
+ }
345
+
346
+ var reactRootView: ReactRootView?
347
+ get() {
348
+ return if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
349
+ if (reactSurface != null) {
350
+ reactSurface?.view as ReactRootView?
351
+ } else {
352
+ null
353
+ }
354
+ } else {
355
+ internalReactRootView
356
+ }
357
+ }
358
+ set(reactRootView) {
359
+ internalReactRootView = reactRootView
360
+ }
361
+
362
+ // Not used in bridgeless
363
+ protected open fun createRootView(): ReactRootView? {
364
+ val reactRootView = ReactRootView(activity)
365
+ reactRootView.setIsFabric(isFabricEnabled)
366
+ return reactRootView
367
+ }
368
+
369
+ /**
370
+ * Handles delegating the [Activity.onKeyUp] method to determine whether the application should
371
+ * show the developer menu or should reload the React Application.
372
+ *
373
+ * @return true if we consume the event and either show the develop menu or reloaded the
374
+ * application.
375
+ */
376
+ fun shouldShowDevMenuOrReload(keyCode: Int, event: KeyEvent?): Boolean {
377
+ val devSupportManager = devSupportManager
378
+ // shouldShowDevMenuOrReload is a Dev API and not supported in RELEASE mode.
379
+ if (devSupportManager == null || devSupportManager is ReleaseDevSupportManager) {
380
+ return false
381
+ }
382
+
383
+ if (keyCode == KeyEvent.KEYCODE_MENU) {
384
+ devSupportManager.showDevOptionsDialog()
385
+ return true
386
+ }
387
+ val didDoubleTapR = doubleTapReloadRecognizer?.didDoubleTapR(keyCode, activity.currentFocus)
388
+ if (didDoubleTapR == true) {
389
+ devSupportManager.handleReloadJS()
390
+ return true
391
+ }
392
+ return false
393
+ }
394
+
395
+ @Deprecated(
396
+ "Do not access [ReactInstanceManager] directly. This class is going away in the New Architecture. You should use [ReactHost] instead.")
397
+ fun getReactInstanceManager(): ReactInstanceManager {
398
+ val nonNullReactNativeHost =
399
+ checkNotNull(reactNativeHost) {
400
+ "Cannot get ReactInstanceManager without a ReactNativeHost."
401
+ }
402
+ return nonNullReactNativeHost.reactInstanceManager
403
+ }
404
+
405
+ /**
406
+ * Get the current [ReactContext] from [ReactHost] or [ReactInstanceManager]
407
+ *
408
+ * Do not store a reference to this, if the React instance is reloaded or destroyed, this context
409
+ * will no longer be valid.
410
+ */
411
+ val currentReactContext: ReactContext?
412
+ get() {
413
+ return if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
414
+ if (reactHost != null) {
415
+ reactHost?.currentReactContext
416
+ } else {
417
+ null
418
+ }
419
+ } else {
420
+ getReactInstanceManager().currentReactContext
421
+ }
422
+ }
423
+ }