@stripe/stripe-react-native 0.57.0 → 0.57.2

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 (324) hide show
  1. package/README.md +0 -8
  2. package/android/.idea/AndroidProjectSystem.xml +6 -0
  3. package/android/.idea/caches/deviceStreaming.xml +1029 -0
  4. package/android/.idea/compiler.xml +6 -0
  5. package/android/.idea/gradle.xml +19 -0
  6. package/android/.idea/migrations.xml +10 -0
  7. package/android/.idea/misc.xml +10 -0
  8. package/android/.idea/runConfigurations.xml +17 -0
  9. package/android/.idea/vcs.xml +6 -0
  10. package/android/build.gradle +76 -118
  11. package/android/gradle.properties +1 -1
  12. package/android/local.properties +8 -0
  13. package/android/settings.gradle +2 -0
  14. package/android/spotless.gradle +1 -1
  15. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +20 -17
  16. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +13 -11
  17. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +17 -21
  18. package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherManager.kt +2 -0
  19. package/android/src/main/java/com/reactnativestripesdk/CustomPaymentMethodActivity.kt +2 -0
  20. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +53 -11
  21. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +105 -117
  22. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +4 -8
  23. package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +154 -0
  24. package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetManager.kt +13 -15
  25. package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +1 -1
  26. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +1 -1
  27. package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +7 -5
  28. package/android/src/main/java/com/reactnativestripesdk/NavigationBarManager.kt +31 -0
  29. package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +120 -0
  30. package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +228 -0
  31. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherManager.kt +1 -0
  32. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +3 -0
  33. package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +4 -6
  34. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +73 -30
  35. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +19 -245
  36. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +53 -17
  37. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +52 -14
  38. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +21 -2
  39. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +4 -4
  40. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +2 -2
  41. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +15 -35
  42. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -1
  43. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +5 -10
  44. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +90 -77
  45. package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +6 -4
  46. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +13 -3
  47. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +41 -0
  48. package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +1 -1
  49. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +92 -44
  50. package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerDelegate.java +3 -0
  51. package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java +2 -0
  52. package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +118 -0
  53. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
  54. package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +922 -0
  55. package/android/src/test/java/com/facebook/testutils/shadows/ShadowArguments.kt +29 -0
  56. package/android/src/test/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManagerTest.kt +163 -0
  57. package/android/src/test/java/com/reactnativestripesdk/PaymentElementConfigTest.kt +976 -0
  58. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetAppearanceTest.kt +801 -0
  59. package/android/src/test/java/com/reactnativestripesdk/PaymentSheetManagerTest.kt +523 -0
  60. package/android/src/test/java/com/reactnativestripesdk/addresssheet/AddressSheetViewTest.kt +551 -0
  61. package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +567 -0
  62. package/android/src/test/java/com/reactnativestripesdk/mappers/PaymentOptionDisplayDataMapperTest.kt +456 -0
  63. package/android/src/test/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxyTest.kt +43 -0
  64. package/android/src/test/resources/robolectric.properties +2 -0
  65. package/ios/AddressSheet/AddressSheetUtils.swift +3 -3
  66. package/ios/AddressSheet/AddressSheetView.swift +25 -25
  67. package/ios/AddressSheet/AddressSheetViewManager.swift +2 -2
  68. package/ios/ApplePayButtonManager.swift +1 -1
  69. package/ios/ApplePayButtonView.swift +9 -10
  70. package/ios/ApplePayUtils.swift +51 -51
  71. package/ios/ApplePayViewController.swift +25 -29
  72. package/ios/AuBECSDebitFormManager.swift +1 -1
  73. package/ios/AuBECSDebitFormView.swift +13 -15
  74. package/ios/CardFieldManager.swift +4 -4
  75. package/ios/CardFieldView.swift +9 -9
  76. package/ios/CardFormManager.swift +3 -3
  77. package/ios/CardFormView.swift +28 -28
  78. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingView.swift +97 -0
  79. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewController.swift +133 -0
  80. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.m +16 -0
  81. package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.swift +17 -0
  82. package/ios/CustomerSheet/CustomerSheetUtils.swift +15 -16
  83. package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +19 -19
  84. package/ios/EmbeddedPaymentElementView.swift +2 -2
  85. package/ios/Errors.swift +22 -23
  86. package/ios/FinancialConnections.swift +37 -37
  87. package/ios/Mappers.swift +210 -71
  88. package/ios/NavigationBarManager.m +13 -0
  89. package/ios/NavigationBarManager.swift +17 -0
  90. package/ios/NavigationBarView.swift +65 -0
  91. package/ios/NewArch/NavigationBarComponentView.h +10 -0
  92. package/ios/NewArch/NavigationBarComponentView.mm +86 -0
  93. package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
  94. package/ios/OldArch/StripeSdkEventEmitterCompat.m +7 -1
  95. package/ios/PaymentMethodFactory.swift +24 -24
  96. package/ios/PaymentOptionDisplayData+ReactNative.swift +4 -4
  97. package/ios/PaymentPassFinder.swift +9 -10
  98. package/ios/PaymentSheetAppearance.swift +137 -138
  99. package/ios/PushProvisioning/AddToWalletButtonManager.swift +2 -2
  100. package/ios/PushProvisioning/AddToWalletButtonView.swift +15 -17
  101. package/ios/PushProvisioning/PushProvisioningUtils.swift +11 -11
  102. package/ios/StripeContainerManager.swift +1 -1
  103. package/ios/StripeContainerView.swift +3 -3
  104. package/ios/StripeOnrampSdk.h +17 -0
  105. package/ios/StripeOnrampSdk.mm +158 -0
  106. package/ios/StripeSdk.mm +8 -0
  107. package/ios/StripeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  108. package/ios/StripeSdk.xcodeproj/project.xcworkspace/xcuserdata/tianzhao.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  109. package/ios/StripeSdk.xcodeproj/xcuserdata/tianzhao.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
  110. package/ios/StripeSdkEmitter.swift +4 -0
  111. package/ios/StripeSdkImpl+CustomerSheet.swift +30 -25
  112. package/ios/StripeSdkImpl+Embedded.swift +11 -9
  113. package/ios/StripeSdkImpl+PaymentSheet.swift +36 -34
  114. package/ios/StripeSdkImpl.swift +913 -185
  115. package/ios/UIColorExtension.swift +72 -0
  116. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  117. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  118. package/lib/commonjs/components/AddressSheet.js +1 -1
  119. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  120. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  121. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  122. package/lib/commonjs/components/CardField.js +1 -1
  123. package/lib/commonjs/components/CardField.js.map +1 -1
  124. package/lib/commonjs/components/CardForm.js +1 -1
  125. package/lib/commonjs/components/CardForm.js.map +1 -1
  126. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  127. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  128. package/lib/commonjs/components/StripeContainer.js +1 -1
  129. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  130. package/lib/commonjs/components/StripeProvider.js +1 -1
  131. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  132. package/lib/commonjs/connect/Components.js +2 -0
  133. package/lib/commonjs/connect/Components.js.map +1 -0
  134. package/lib/commonjs/connect/ConnectComponentsProvider.js +2 -0
  135. package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -0
  136. package/lib/commonjs/connect/EmbeddedComponent.js +19 -0
  137. package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -0
  138. package/lib/commonjs/connect/ModalCloseButton.js +2 -0
  139. package/lib/commonjs/connect/ModalCloseButton.js.map +1 -0
  140. package/lib/commonjs/connect/NavigationBar.js +2 -0
  141. package/lib/commonjs/connect/NavigationBar.js.map +1 -0
  142. package/lib/commonjs/connect/connectTypes.js +2 -0
  143. package/lib/commonjs/connect/connectTypes.js.map +1 -0
  144. package/lib/commonjs/events.js +1 -1
  145. package/lib/commonjs/events.js.map +1 -1
  146. package/lib/commonjs/helpers.js +1 -1
  147. package/lib/commonjs/helpers.js.map +1 -1
  148. package/lib/commonjs/hooks/useOnramp.js +2 -0
  149. package/lib/commonjs/hooks/useOnramp.js.map +1 -0
  150. package/lib/commonjs/index.js +1 -1
  151. package/lib/commonjs/index.js.map +1 -1
  152. package/lib/commonjs/plugin/withStripe.js +1 -1
  153. package/lib/commonjs/plugin/withStripe.js.map +1 -1
  154. package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
  155. package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -1
  156. package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
  157. package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -1
  158. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  159. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
  160. package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
  161. package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -1
  162. package/lib/commonjs/specs/NativeCardField.js +1 -1
  163. package/lib/commonjs/specs/NativeCardField.js.map +1 -1
  164. package/lib/commonjs/specs/NativeCardForm.js +1 -1
  165. package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
  166. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +2 -0
  167. package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js.map +1 -0
  168. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
  169. package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  170. package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
  171. package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -1
  172. package/lib/commonjs/specs/NativeNavigationBar.js +2 -0
  173. package/lib/commonjs/specs/NativeNavigationBar.js.map +1 -0
  174. package/lib/commonjs/specs/NativeOnrampSdkModule.js +2 -0
  175. package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -0
  176. package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
  177. package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -1
  178. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  179. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  180. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  181. package/lib/commonjs/types/Errors.js +1 -1
  182. package/lib/commonjs/types/Errors.js.map +1 -1
  183. package/lib/commonjs/types/Onramp.js +2 -0
  184. package/lib/commonjs/types/Onramp.js.map +1 -0
  185. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  186. package/lib/commonjs/types/index.js +1 -1
  187. package/lib/commonjs/types/index.js.map +1 -1
  188. package/lib/module/components/AddToWalletButton.js +1 -1
  189. package/lib/module/components/AddToWalletButton.js.map +1 -1
  190. package/lib/module/components/AddressSheet.js +1 -1
  191. package/lib/module/components/AddressSheet.js.map +1 -1
  192. package/lib/module/components/AuBECSDebitForm.js +1 -1
  193. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  194. package/lib/module/components/CardField.js +1 -1
  195. package/lib/module/components/CardField.js.map +1 -1
  196. package/lib/module/components/CardForm.js +1 -1
  197. package/lib/module/components/CardForm.js.map +1 -1
  198. package/lib/module/components/PlatformPayButton.js +1 -1
  199. package/lib/module/components/PlatformPayButton.js.map +1 -1
  200. package/lib/module/components/StripeContainer.js +1 -1
  201. package/lib/module/components/StripeContainer.js.map +1 -1
  202. package/lib/module/components/StripeProvider.js +1 -1
  203. package/lib/module/components/StripeProvider.js.map +1 -1
  204. package/lib/module/connect/Components.js +2 -0
  205. package/lib/module/connect/Components.js.map +1 -0
  206. package/lib/module/connect/ConnectComponentsProvider.js +2 -0
  207. package/lib/module/connect/ConnectComponentsProvider.js.map +1 -0
  208. package/lib/module/connect/EmbeddedComponent.js +19 -0
  209. package/lib/module/connect/EmbeddedComponent.js.map +1 -0
  210. package/lib/module/connect/ModalCloseButton.js +2 -0
  211. package/lib/module/connect/ModalCloseButton.js.map +1 -0
  212. package/lib/module/connect/NavigationBar.js +2 -0
  213. package/lib/module/connect/NavigationBar.js.map +1 -0
  214. package/lib/module/connect/connectTypes.js +2 -0
  215. package/lib/module/connect/connectTypes.js.map +1 -0
  216. package/lib/module/events.js +1 -1
  217. package/lib/module/events.js.map +1 -1
  218. package/lib/module/helpers.js +1 -1
  219. package/lib/module/helpers.js.map +1 -1
  220. package/lib/module/hooks/useOnramp.js +2 -0
  221. package/lib/module/hooks/useOnramp.js.map +1 -0
  222. package/lib/module/index.js +1 -1
  223. package/lib/module/index.js.map +1 -1
  224. package/lib/module/plugin/withStripe.js +1 -1
  225. package/lib/module/plugin/withStripe.js.map +1 -1
  226. package/lib/module/specs/NativeAddToWalletButton.js +1 -1
  227. package/lib/module/specs/NativeAddToWalletButton.js.map +1 -1
  228. package/lib/module/specs/NativeAddressSheet.js +1 -1
  229. package/lib/module/specs/NativeAddressSheet.js.map +1 -1
  230. package/lib/module/specs/NativeApplePayButton.js +1 -1
  231. package/lib/module/specs/NativeApplePayButton.js.map +1 -1
  232. package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
  233. package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -1
  234. package/lib/module/specs/NativeCardField.js +1 -1
  235. package/lib/module/specs/NativeCardField.js.map +1 -1
  236. package/lib/module/specs/NativeCardForm.js +1 -1
  237. package/lib/module/specs/NativeCardForm.js.map +1 -1
  238. package/lib/module/specs/NativeConnectAccountOnboardingView.js +2 -0
  239. package/lib/module/specs/NativeConnectAccountOnboardingView.js.map +1 -0
  240. package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
  241. package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
  242. package/lib/module/specs/NativeGooglePayButton.js +1 -1
  243. package/lib/module/specs/NativeGooglePayButton.js.map +1 -1
  244. package/lib/module/specs/NativeNavigationBar.js +2 -0
  245. package/lib/module/specs/NativeNavigationBar.js.map +1 -0
  246. package/lib/module/specs/NativeOnrampSdkModule.js +2 -0
  247. package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -0
  248. package/lib/module/specs/NativeStripeContainer.js +1 -1
  249. package/lib/module/specs/NativeStripeContainer.js.map +1 -1
  250. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  251. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  252. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  253. package/lib/module/types/Errors.js +1 -1
  254. package/lib/module/types/Errors.js.map +1 -1
  255. package/lib/module/types/Onramp.js +2 -0
  256. package/lib/module/types/Onramp.js.map +1 -0
  257. package/lib/module/types/PaymentSheet.js.map +1 -1
  258. package/lib/module/types/index.js +1 -1
  259. package/lib/module/types/index.js.map +1 -1
  260. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -1
  261. package/lib/typescript/src/connect/Components.d.ts +23 -0
  262. package/lib/typescript/src/connect/Components.d.ts.map +1 -0
  263. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts +22 -0
  264. package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts.map +1 -0
  265. package/lib/typescript/src/connect/EmbeddedComponent.d.ts +18 -0
  266. package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -0
  267. package/lib/typescript/src/connect/ModalCloseButton.d.ts +7 -0
  268. package/lib/typescript/src/connect/ModalCloseButton.d.ts.map +1 -0
  269. package/lib/typescript/src/connect/NavigationBar.d.ts +8 -0
  270. package/lib/typescript/src/connect/NavigationBar.d.ts.map +1 -0
  271. package/lib/typescript/src/connect/connectTypes.d.ts +464 -0
  272. package/lib/typescript/src/connect/connectTypes.d.ts.map +1 -0
  273. package/lib/typescript/src/events.d.ts +4 -0
  274. package/lib/typescript/src/events.d.ts.map +1 -1
  275. package/lib/typescript/src/functions.d.ts.map +1 -1
  276. package/lib/typescript/src/helpers.d.ts.map +1 -1
  277. package/lib/typescript/src/hooks/useOnramp.d.ts +158 -0
  278. package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -0
  279. package/lib/typescript/src/index.d.ts +4 -0
  280. package/lib/typescript/src/index.d.ts.map +1 -1
  281. package/lib/typescript/src/plugin/withStripe.d.ts +15 -0
  282. package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -1
  283. package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts +14 -0
  284. package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts.map +1 -0
  285. package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts +1 -0
  286. package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts.map +1 -1
  287. package/lib/typescript/src/specs/NativeNavigationBar.d.ts +11 -0
  288. package/lib/typescript/src/specs/NativeNavigationBar.d.ts.map +1 -0
  289. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +28 -0
  290. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -0
  291. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -0
  292. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  293. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
  294. package/lib/typescript/src/types/Errors.d.ts +5 -0
  295. package/lib/typescript/src/types/Errors.d.ts.map +1 -1
  296. package/lib/typescript/src/types/Onramp.d.ts +275 -0
  297. package/lib/typescript/src/types/Onramp.d.ts.map +1 -0
  298. package/lib/typescript/src/types/PaymentSheet.d.ts +7 -0
  299. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  300. package/lib/typescript/src/types/index.d.ts +7 -1
  301. package/lib/typescript/src/types/index.d.ts.map +1 -1
  302. package/package.json +25 -14
  303. package/src/components/StripeProvider.tsx +5 -0
  304. package/src/connect/Components.tsx +279 -0
  305. package/src/connect/ConnectComponentsProvider.tsx +93 -0
  306. package/src/connect/EmbeddedComponent.tsx +407 -0
  307. package/src/connect/ModalCloseButton.tsx +44 -0
  308. package/src/connect/NavigationBar.tsx +29 -0
  309. package/src/connect/connectTypes.ts +626 -0
  310. package/src/events.ts +23 -0
  311. package/src/hooks/useOnramp.tsx +334 -0
  312. package/src/index.tsx +13 -0
  313. package/src/plugin/withStripe.ts +104 -7
  314. package/src/specs/NativeConnectAccountOnboardingView.ts +19 -0
  315. package/src/specs/NativeEmbeddedPaymentElement.ts +5 -1
  316. package/src/specs/NativeNavigationBar.ts +16 -0
  317. package/src/specs/NativeOnrampSdkModule.ts +47 -0
  318. package/src/specs/NativeStripeSdkModule.ts +5 -0
  319. package/src/types/EmbeddedPaymentElement.tsx +24 -3
  320. package/src/types/Errors.ts +6 -0
  321. package/src/types/Onramp.ts +317 -0
  322. package/src/types/PaymentSheet.ts +7 -0
  323. package/src/types/index.ts +8 -0
  324. package/stripe-react-native.podspec +20 -7
@@ -3,7 +3,6 @@ package com.reactnativestripesdk
3
3
  import android.annotation.SuppressLint
4
4
  import android.app.Activity
5
5
  import android.app.Application
6
- import android.content.Context
7
6
  import android.content.Intent
8
7
  import android.graphics.Bitmap
9
8
  import android.graphics.Canvas
@@ -14,14 +13,13 @@ import android.os.Handler
14
13
  import android.os.Looper
15
14
  import android.util.Base64
16
15
  import android.util.Log
17
- import androidx.appcompat.content.res.AppCompatResources
16
+ import androidx.core.graphics.createBitmap
18
17
  import androidx.core.graphics.drawable.DrawableCompat
19
18
  import com.facebook.react.bridge.Arguments
20
19
  import com.facebook.react.bridge.Promise
21
20
  import com.facebook.react.bridge.ReactApplicationContext
22
21
  import com.facebook.react.bridge.ReadableMap
23
22
  import com.facebook.react.bridge.WritableMap
24
- import com.facebook.react.bridge.WritableNativeMap
25
23
  import com.reactnativestripesdk.addresssheet.AddressSheetView
26
24
  import com.reactnativestripesdk.utils.ErrorType
27
25
  import com.reactnativestripesdk.utils.KeepJsAwakeTask
@@ -33,8 +31,8 @@ import com.reactnativestripesdk.utils.createError
33
31
  import com.reactnativestripesdk.utils.createResult
34
32
  import com.reactnativestripesdk.utils.forEachKey
35
33
  import com.reactnativestripesdk.utils.getBooleanOr
36
- import com.reactnativestripesdk.utils.getIntOr
37
- import com.reactnativestripesdk.utils.isEmpty
34
+ import com.reactnativestripesdk.utils.getIntegerList
35
+ import com.reactnativestripesdk.utils.getStringList
38
36
  import com.reactnativestripesdk.utils.mapFromConfirmationToken
39
37
  import com.reactnativestripesdk.utils.mapFromCustomPaymentMethod
40
38
  import com.reactnativestripesdk.utils.mapFromPaymentMethod
@@ -103,7 +101,7 @@ class PaymentSheetManager(
103
101
  val allowsDelayedPaymentMethods = arguments.getBooleanOr("allowsDelayedPaymentMethods", false)
104
102
  val billingDetailsMap = arguments.getMap("defaultBillingDetails")
105
103
  val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
106
- val paymentMethodOrder = arguments.getStringArrayList("paymentMethodOrder")
104
+ val paymentMethodOrder = arguments.getStringList("paymentMethodOrder")
107
105
  val allowsRemovalOfLastSavedPaymentMethod =
108
106
  arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
109
107
  paymentIntentClientSecret = arguments.getString("paymentIntentClientSecret").orEmpty()
@@ -144,9 +142,9 @@ class PaymentSheetManager(
144
142
  PaymentOptionResultCallback { paymentOptionResult ->
145
143
  val result =
146
144
  paymentOptionResult.paymentOption?.let {
147
- val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
145
+ val bitmap = getBitmapFromDrawable(it.icon())
148
146
  val imageString = getBase64FromBitmap(bitmap)
149
- val option: WritableMap = WritableNativeMap()
147
+ val option: WritableMap = Arguments.createMap()
150
148
  option.putString("label", it.label)
151
149
  option.putString("image", imageString)
152
150
  val additionalFields: Map<String, Any> = mapOf("didCancel" to paymentOptionResult.didCancel)
@@ -191,7 +189,7 @@ class PaymentSheetManager(
191
189
  }
192
190
 
193
191
  is PaymentSheetResult.Completed -> {
194
- resolvePaymentResult(WritableNativeMap())
192
+ resolvePaymentResult(Arguments.createMap())
195
193
  paymentSheet = null
196
194
  flowController = null
197
195
  }
@@ -252,36 +250,9 @@ class PaymentSheetManager(
252
250
  }
253
251
  }
254
252
 
255
- val billingDetailsConfig =
256
- PaymentSheet.BillingDetailsCollectionConfiguration(
257
- name = mapToCollectionMode(billingConfigParams?.getString("name")),
258
- phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
259
- email = mapToCollectionMode(billingConfigParams?.getString("email")),
260
- address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
261
- attachDefaultsToPaymentMethod =
262
- billingConfigParams?.getBooleanOr("attachDefaultsToPaymentMethod", false) ?: false,
263
- )
253
+ val billingDetailsConfig = buildBillingDetailsCollectionConfiguration(billingConfigParams)
264
254
 
265
- var defaultBillingDetails: PaymentSheet.BillingDetails? = null
266
- if (billingDetailsMap != null) {
267
- val addressMap = billingDetailsMap.getMap("address")
268
- val address =
269
- PaymentSheet.Address(
270
- addressMap?.getString("city"),
271
- addressMap?.getString("country"),
272
- addressMap?.getString("line1"),
273
- addressMap?.getString("line2"),
274
- addressMap?.getString("postalCode"),
275
- addressMap?.getString("state"),
276
- )
277
- defaultBillingDetails =
278
- PaymentSheet.BillingDetails(
279
- address,
280
- billingDetailsMap.getString("email"),
281
- billingDetailsMap.getString("name"),
282
- billingDetailsMap.getString("phone"),
283
- )
284
- }
255
+ val defaultBillingDetails = buildBillingDetails(billingDetailsMap)
285
256
  val configurationBuilder =
286
257
  PaymentSheet.Configuration
287
258
  .Builder(merchantDisplayName)
@@ -294,7 +265,7 @@ class PaymentSheetManager(
294
265
  .link(linkConfig)
295
266
  .billingDetailsCollectionConfiguration(billingDetailsConfig)
296
267
  .preferredNetworks(
297
- mapToPreferredNetworks(arguments.getIntegerArrayList("preferredNetworks")),
268
+ mapToPreferredNetworks(arguments.getIntegerList("preferredNetworks")),
298
269
  ).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
299
270
  .cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
300
271
  .customPaymentMethods(parseCustomPaymentMethods(arguments.getMap("customPaymentMethodConfiguration")))
@@ -308,7 +279,7 @@ class PaymentSheetManager(
308
279
 
309
280
  paymentSheetConfiguration = configurationBuilder.build()
310
281
 
311
- if (arguments.getBoolean("customFlow") == true) {
282
+ if (arguments.getBooleanOr("customFlow", false)) {
312
283
  flowController =
313
284
  if (intentConfiguration != null) {
314
285
  val builder =
@@ -354,7 +325,7 @@ class PaymentSheetManager(
354
325
  .confirmCustomPaymentMethodCallback(this)
355
326
  .build(activity, signal)
356
327
  }
357
- initPromise.resolve(WritableNativeMap())
328
+ initPromise.resolve(Arguments.createMap())
358
329
  }
359
330
  }
360
331
 
@@ -444,13 +415,13 @@ class PaymentSheetManager(
444
415
  PaymentSheet.FlowController.ConfigCallback { _, _ ->
445
416
  val result =
446
417
  flowController?.getPaymentOption()?.let {
447
- val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
418
+ val bitmap = getBitmapFromDrawable(it.icon())
448
419
  val imageString = getBase64FromBitmap(bitmap)
449
- val option: WritableMap = WritableNativeMap()
420
+ val option: WritableMap = Arguments.createMap()
450
421
  option.putString("label", it.label)
451
422
  option.putString("image", imageString)
452
423
  createResult("paymentOption", option)
453
- } ?: run { WritableNativeMap() }
424
+ } ?: run { Arguments.createMap() }
454
425
  initPromise.resolve(result)
455
426
  }
456
427
 
@@ -571,165 +542,21 @@ class PaymentSheetManager(
571
542
  }
572
543
 
573
544
  companion object {
574
- private val mapIntToButtonType =
575
- mapOf(
576
- 1 to PaymentSheet.GooglePayConfiguration.ButtonType.Buy,
577
- 6 to PaymentSheet.GooglePayConfiguration.ButtonType.Book,
578
- 5 to PaymentSheet.GooglePayConfiguration.ButtonType.Checkout,
579
- 4 to PaymentSheet.GooglePayConfiguration.ButtonType.Donate,
580
- 11 to PaymentSheet.GooglePayConfiguration.ButtonType.Order,
581
- 1000 to PaymentSheet.GooglePayConfiguration.ButtonType.Pay,
582
- 7 to PaymentSheet.GooglePayConfiguration.ButtonType.Subscribe,
583
- 1001 to PaymentSheet.GooglePayConfiguration.ButtonType.Plain,
584
- )
585
-
586
545
  internal fun createMissingInitError(): WritableMap =
587
546
  createError(
588
547
  PaymentSheetErrorType.Failed.toString(),
589
548
  "No payment sheet has been initialized yet. You must call `initPaymentSheet` before `presentPaymentSheet`.",
590
549
  )
591
-
592
- internal fun buildGooglePayConfig(params: ReadableMap?): PaymentSheet.GooglePayConfiguration? {
593
- if (params == null || params.isEmpty()) {
594
- return null
595
- }
596
-
597
- val countryCode = params.getString("merchantCountryCode").orEmpty()
598
- val currencyCode = params.getString("currencyCode").orEmpty()
599
- val testEnv = params.getBoolean("testEnv")
600
- val amount = params.getString("amount")?.toLongOrNull()
601
- val label = params.getString("label")
602
- val buttonType =
603
- mapIntToButtonType.get(params.getIntOr("buttonType", 0))
604
- ?: PaymentSheet.GooglePayConfiguration.ButtonType.Pay
605
-
606
- return PaymentSheet.GooglePayConfiguration(
607
- environment =
608
- if (testEnv) {
609
- PaymentSheet.GooglePayConfiguration.Environment.Test
610
- } else {
611
- PaymentSheet.GooglePayConfiguration.Environment.Production
612
- },
613
- countryCode = countryCode,
614
- currencyCode = currencyCode,
615
- amount = amount,
616
- label = label,
617
- buttonType = buttonType,
618
- )
619
- }
620
-
621
- internal fun buildLinkConfig(params: ReadableMap?): PaymentSheet.LinkConfiguration {
622
- if (params == null) {
623
- return PaymentSheet.LinkConfiguration()
624
- }
625
-
626
- val display = mapStringToLinkDisplay(params.getString("display"))
627
-
628
- return PaymentSheet.LinkConfiguration(
629
- display = display,
630
- )
631
- }
632
-
633
- private fun mapStringToLinkDisplay(value: String?): PaymentSheet.LinkConfiguration.Display =
634
- when (value) {
635
- "automatic" -> PaymentSheet.LinkConfiguration.Display.Automatic
636
- "never" -> PaymentSheet.LinkConfiguration.Display.Never
637
- else -> PaymentSheet.LinkConfiguration.Display.Automatic
638
- }
639
-
640
- @Throws(PaymentSheetException::class)
641
- internal fun buildIntentConfiguration(intentConfigurationParams: ReadableMap?): PaymentSheet.IntentConfiguration? {
642
- if (intentConfigurationParams == null) {
643
- return null
644
- }
645
- val modeParams =
646
- intentConfigurationParams.getMap("mode")
647
- ?: throw PaymentSheetException(
648
- "If `intentConfiguration` is provided, `intentConfiguration.mode` is required",
649
- )
650
-
651
- return PaymentSheet.IntentConfiguration(
652
- mode = buildIntentConfigurationMode(modeParams),
653
- paymentMethodTypes =
654
- intentConfigurationParams.getStringArrayList("paymentMethodTypes")?.toList()
655
- ?: emptyList(),
656
- )
657
- }
658
-
659
- @OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
660
- private fun buildIntentConfigurationMode(modeParams: ReadableMap): PaymentSheet.IntentConfiguration.Mode =
661
- if (modeParams.hasKey("amount")) {
662
- val currencyCode =
663
- modeParams.getString("currencyCode")
664
- ?: throw PaymentSheetException(
665
- "You must provide a value to intentConfiguration.mode.currencyCode",
666
- )
667
- PaymentSheet.IntentConfiguration.Mode.Payment(
668
- amount = modeParams.getInt("amount").toLong(),
669
- currency = currencyCode,
670
- setupFutureUse = mapToSetupFutureUse(modeParams.getString("setupFutureUsage")),
671
- captureMethod = mapToCaptureMethod(modeParams.getString("captureMethod")),
672
- paymentMethodOptions = mapToPaymentMethodOptions(modeParams.getMap("paymentMethodOptions")),
673
- )
674
- } else {
675
- val setupFutureUsage =
676
- mapToSetupFutureUse(modeParams.getString("setupFutureUsage"))
677
- ?: throw PaymentSheetException(
678
- "You must provide a value to intentConfiguration.mode.setupFutureUsage",
679
- )
680
- PaymentSheet.IntentConfiguration.Mode.Setup(
681
- currency = modeParams.getString("currencyCode"),
682
- setupFutureUse = setupFutureUsage,
683
- )
684
- }
685
-
686
- @Throws(PaymentSheetException::class)
687
- internal fun buildCustomerConfiguration(map: ReadableMap?): PaymentSheet.CustomerConfiguration? {
688
- val customerId = map?.getString("customerId").orEmpty()
689
- val customerEphemeralKeySecret = map?.getString("customerEphemeralKeySecret").orEmpty()
690
- val customerSessionClientSecret = map?.getString("customerSessionClientSecret").orEmpty()
691
- return if (customerSessionClientSecret.isNotEmpty() &&
692
- customerEphemeralKeySecret.isNotEmpty()
693
- ) {
694
- throw PaymentSheetException(
695
- "`customerEphemeralKeySecret` and `customerSessionClientSecret` cannot both be set",
696
- )
697
- } else if (customerId.isNotEmpty() && customerSessionClientSecret.isNotEmpty()) {
698
- PaymentSheet.CustomerConfiguration.createWithCustomerSession(
699
- id = customerId,
700
- clientSecret = customerSessionClientSecret,
701
- )
702
- } else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
703
- PaymentSheet.CustomerConfiguration(
704
- id = customerId,
705
- ephemeralKeySecret = customerEphemeralKeySecret,
706
- )
707
- } else {
708
- null
709
- }
710
- }
711
550
  }
712
551
  }
713
552
 
714
- fun getBitmapFromVectorDrawable(
715
- context: Context?,
716
- drawableId: Int,
717
- ): Bitmap? {
718
- val drawable = AppCompatResources.getDrawable(context!!, drawableId) ?: return null
719
- return getBitmapFromDrawable(drawable)
720
- }
721
-
722
553
  fun getBitmapFromDrawable(drawable: Drawable): Bitmap? {
723
554
  val drawableCompat = DrawableCompat.wrap(drawable).mutate()
724
555
  if (drawableCompat.intrinsicWidth <= 0 || drawableCompat.intrinsicHeight <= 0) {
725
556
  return null
726
557
  }
727
558
  val bitmap =
728
- Bitmap.createBitmap(
729
- drawableCompat.intrinsicWidth,
730
- drawableCompat.intrinsicHeight,
731
- Bitmap.Config.ARGB_8888,
732
- )
559
+ createBitmap(drawableCompat.intrinsicWidth, drawableCompat.intrinsicHeight)
733
560
  bitmap.eraseColor(Color.TRANSPARENT)
734
561
  val canvas = Canvas(bitmap)
735
562
  drawable.setBounds(0, 0, canvas.width, canvas.height)
@@ -747,14 +574,6 @@ fun getBase64FromBitmap(bitmap: Bitmap?): String? {
747
574
  return Base64.encodeToString(imageBytes, Base64.DEFAULT)
748
575
  }
749
576
 
750
- fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode =
751
- when (str) {
752
- "automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
753
- "never" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Never
754
- "always" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
755
- else -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
756
- }
757
-
758
577
  fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
759
578
  when (str) {
760
579
  "Horizontal" -> PaymentSheet.PaymentMethodLayout.Horizontal
@@ -762,17 +581,7 @@ fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
762
581
  else -> PaymentSheet.PaymentMethodLayout.Automatic
763
582
  }
764
583
 
765
- fun mapToAddressCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode =
766
- when (str) {
767
- "automatic" ->
768
- PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
769
-
770
- "never" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Never
771
- "full" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
772
- else -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
773
- }
774
-
775
- fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
584
+ internal fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
776
585
  when (type) {
777
586
  "OffSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OffSession
778
587
  "OnSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OnSession
@@ -780,7 +589,7 @@ fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFu
780
589
  else -> null
781
590
  }
782
591
 
783
- fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
592
+ internal fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
784
593
  when (type) {
785
594
  "Automatic" -> PaymentSheet.IntentConfiguration.CaptureMethod.Automatic
786
595
  "Manual" -> PaymentSheet.IntentConfiguration.CaptureMethod.Manual
@@ -789,7 +598,7 @@ fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureM
789
598
  }
790
599
 
791
600
  @OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
792
- fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
601
+ internal fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
793
602
  val sfuMap = options?.getMap("setupFutureUsageValues")
794
603
  val paymentMethodToSfuMap = mutableMapOf<PaymentMethod.Type, PaymentSheet.IntentConfiguration.SetupFutureUse>()
795
604
  sfuMap?.forEachKey { code ->
@@ -807,38 +616,3 @@ fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfigu
807
616
  null
808
617
  }
809
618
  }
810
-
811
- fun mapToCardBrandAcceptance(params: ReadableMap?): PaymentSheet.CardBrandAcceptance {
812
- val cardBrandAcceptanceParams = params?.getMap("cardBrandAcceptance") ?: return PaymentSheet.CardBrandAcceptance.all()
813
- val filter = cardBrandAcceptanceParams.getString("filter") ?: return PaymentSheet.CardBrandAcceptance.all()
814
-
815
- return when (filter) {
816
- "all" -> PaymentSheet.CardBrandAcceptance.all()
817
- "allowed" -> {
818
- val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
819
- val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
820
- if (brandCategories.isEmpty()) {
821
- return PaymentSheet.CardBrandAcceptance.all()
822
- }
823
- PaymentSheet.CardBrandAcceptance.allowed(brandCategories)
824
- }
825
- "disallowed" -> {
826
- val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
827
- val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
828
- if (brandCategories.isEmpty()) {
829
- return PaymentSheet.CardBrandAcceptance.all()
830
- }
831
- PaymentSheet.CardBrandAcceptance.disallowed(brandCategories)
832
- }
833
- else -> PaymentSheet.CardBrandAcceptance.all()
834
- }
835
- }
836
-
837
- fun mapToCardBrandCategory(brand: String): PaymentSheet.CardBrandAcceptance.BrandCategory? =
838
- when (brand) {
839
- "visa" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Visa
840
- "mastercard" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Mastercard
841
- "amex" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Amex
842
- "discover" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Discover
843
- else -> null
844
- }
@@ -1,6 +1,7 @@
1
1
  package com.reactnativestripesdk
2
2
 
3
3
  import android.content.Context
4
+ import android.widget.FrameLayout
4
5
  import androidx.compose.runtime.Composable
5
6
  import androidx.compose.ui.platform.AbstractComposeView
6
7
  import androidx.compose.ui.platform.ViewCompositionStrategy
@@ -17,13 +18,24 @@ import androidx.savedstate.setViewTreeSavedStateRegistryOwner
17
18
  import com.facebook.react.bridge.ReactContext
18
19
 
19
20
  /**
21
+ * A wrapper around Compose views that safely handles React Native's layout system.
22
+ *
23
+ * This uses a FrameLayout wrapper pattern to solve the "Cannot locate windowRecomposer;
24
+ * View is not attached to a window" crash that occurs when React Native measures views
25
+ * before they are attached to the window hierarchy. By extending FrameLayout instead of
26
+ * AbstractComposeView directly, the view can be safely measured before the Compose
27
+ * infrastructure is ready.
28
+ *
29
+ * The inner ComposeView is only created when the wrapper is attached to the window,
30
+ * ensuring the WindowRecomposer is always available.
31
+ *
20
32
  * Compose disposes views by default when using Fragments, which is not compatible with how
21
33
  * react-native-screens work. To avoid this we change the composition strategy to use the
22
34
  * activity lifecycle instead of the fragment. Note that `setViewTreeLifecycleOwner` also
23
35
  * needs to be set otherwise a different code path will dispose of the view.
24
36
  *
25
37
  * **IMPORTANT** Views using this will need to call `handleOnDropViewInstance` manually to avoid leaking.
26
- * This can be done using the using the following code in the view manager:
38
+ * This can be done using the following code in the view manager:
27
39
  *
28
40
  * ```
29
41
  * override fun onDropViewInstance(view: SomeStripeAbstractComposeView) {
@@ -35,7 +47,7 @@ import com.facebook.react.bridge.ReactContext
35
47
  */
36
48
  abstract class StripeAbstractComposeView(
37
49
  context: Context,
38
- ) : AbstractComposeView(context) {
50
+ ) : FrameLayout(context) {
39
51
  /**
40
52
  * Dummy compose view that will be added at the root of the app, this is needed so that the context
41
53
  * that compose needs is already initialized and we can set it directly on our compose views.
@@ -55,6 +67,7 @@ abstract class StripeAbstractComposeView(
55
67
  }
56
68
  }
57
69
 
70
+ private var innerComposeView: InnerComposeView? = null
58
71
  private var isLifecycleSetup = false
59
72
 
60
73
  // Create a lifecycle this is tied to the activity, but that we can manually
@@ -67,24 +80,35 @@ abstract class StripeAbstractComposeView(
67
80
  }
68
81
  private var lifecycleRegistry = LifecycleRegistry(lifecycleOwner)
69
82
 
70
- init {
71
- // Setup lifecycles
72
- setViewCompositionStrategy(
73
- ViewCompositionStrategy.DisposeOnLifecycleDestroyed(lifecycleOwner = lifecycleOwner),
74
- )
75
- setViewTreeLifecycleOwner(lifecycleOwner = lifecycleOwner)
76
-
77
- // Setup context from dummy compose view.
78
- (context as ReactContext).getNativeModule(StripeSdkModule::class.java)?.composeCompatView?.let {
79
- setParentCompositionContext(it.findViewTreeCompositionContext())
80
- setViewTreeSavedStateRegistryOwner(it.findViewTreeSavedStateRegistryOwner())
81
- setViewTreeViewModelStoreOwner(it.findViewTreeViewModelStoreOwner())
82
- }
83
- }
84
-
85
83
  override fun onAttachedToWindow() {
86
84
  super.onAttachedToWindow()
85
+ ensureComposeViewCreated()
86
+ setupActivityLifecycleObserver()
87
+ }
88
+
89
+ private fun ensureComposeViewCreated() {
90
+ if (innerComposeView != null) return
91
+
92
+ innerComposeView =
93
+ InnerComposeView(context).also { cv ->
94
+ // Setup lifecycles
95
+ cv.setViewCompositionStrategy(
96
+ ViewCompositionStrategy.DisposeOnLifecycleDestroyed(lifecycleOwner = lifecycleOwner),
97
+ )
98
+ cv.setViewTreeLifecycleOwner(lifecycleOwner = lifecycleOwner)
87
99
 
100
+ // Setup context from dummy compose view (now safe since we're attached to window)
101
+ (context as? ReactContext)?.getNativeModule(StripeSdkModule::class.java)?.composeCompatView?.let {
102
+ cv.setParentCompositionContext(it.findViewTreeCompositionContext())
103
+ cv.setViewTreeSavedStateRegistryOwner(it.findViewTreeSavedStateRegistryOwner())
104
+ cv.setViewTreeViewModelStoreOwner(it.findViewTreeViewModelStoreOwner())
105
+ }
106
+
107
+ addView(cv, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
108
+ }
109
+ }
110
+
111
+ private fun setupActivityLifecycleObserver() {
88
112
  if (isLifecycleSetup) {
89
113
  return
90
114
  }
@@ -111,4 +135,16 @@ abstract class StripeAbstractComposeView(
111
135
  lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
112
136
  }
113
137
  }
138
+
139
+ @Composable
140
+ abstract fun Content()
141
+
142
+ private inner class InnerComposeView(
143
+ context: Context,
144
+ ) : AbstractComposeView(context) {
145
+ @Composable
146
+ override fun Content() {
147
+ this@StripeAbstractComposeView.Content()
148
+ }
149
+ }
114
150
  }