@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
@@ -7,6 +7,7 @@ import android.content.Intent
7
7
  import android.os.Bundle
8
8
  import android.util.Log
9
9
  import android.view.ViewGroup
10
+ import androidx.browser.customtabs.CustomTabsIntent
10
11
  import androidx.fragment.app.FragmentActivity
11
12
  import com.facebook.react.ReactActivity
12
13
  import com.facebook.react.bridge.Arguments
@@ -18,7 +19,6 @@ import com.facebook.react.bridge.ReadableArray
18
19
  import com.facebook.react.bridge.ReadableMap
19
20
  import com.facebook.react.bridge.UiThreadUtil
20
21
  import com.facebook.react.bridge.WritableMap
21
- import com.facebook.react.bridge.WritableNativeMap
22
22
  import com.facebook.react.module.annotations.ReactModule
23
23
  import com.reactnativestripesdk.addresssheet.AddressLauncherManager
24
24
  import com.reactnativestripesdk.customersheet.CustomerSheetManager
@@ -35,6 +35,7 @@ import com.reactnativestripesdk.utils.createMissingInitError
35
35
  import com.reactnativestripesdk.utils.createResult
36
36
  import com.reactnativestripesdk.utils.getBooleanOr
37
37
  import com.reactnativestripesdk.utils.getIntOrNull
38
+ import com.reactnativestripesdk.utils.getLongOrNull
38
39
  import com.reactnativestripesdk.utils.getValOr
39
40
  import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
40
41
  import com.reactnativestripesdk.utils.mapFromPaymentMethod
@@ -163,7 +164,7 @@ class StripeSdkModule(
163
164
 
164
165
  private fun configure3dSecure(params: ReadableMap) {
165
166
  val stripe3dsConfigBuilder = PaymentAuthConfig.Stripe3ds2Config.Builder()
166
- if (params.hasKey("timeout")) stripe3dsConfigBuilder.setTimeout(params.getInt("timeout"))
167
+ params.getIntOrNull("timeout")?.let { stripe3dsConfigBuilder.setTimeout(it) }
167
168
  val uiCustomization = mapToUICustomization(params)
168
169
 
169
170
  PaymentAuthConfig.init(
@@ -244,10 +245,10 @@ class StripeSdkModule(
244
245
  return
245
246
  }
246
247
 
247
- val timeoutKey = "timeout"
248
- if (options.hasKey(timeoutKey)) {
248
+ val timeout = options.getLongOrNull("timeout")
249
+ if (timeout != null) {
249
250
  paymentSheetManager?.presentWithTimeout(
250
- options.getInt(timeoutKey).toLong(),
251
+ timeout,
251
252
  promise,
252
253
  )
253
254
  } else {
@@ -502,7 +503,7 @@ class StripeSdkModule(
502
503
  object : ApiResultCallback<Token> {
503
504
  override fun onSuccess(result: Token) {
504
505
  val tokenId = result.id
505
- val res = WritableNativeMap()
506
+ val res = Arguments.createMap()
506
507
  res.putString("tokenId", tokenId)
507
508
  promise.resolve(res)
508
509
  }
@@ -760,6 +761,7 @@ class StripeSdkModule(
760
761
  return
761
762
  }
762
763
 
764
+ unregisterStripeUIManager(googlePayLauncherManager)
763
765
  googlePayLauncherManager =
764
766
  GooglePayLauncherManager(
765
767
  reactApplicationContext,
@@ -779,7 +781,7 @@ class StripeSdkModule(
779
781
  expand = listOf("payment_method"),
780
782
  object : ApiResultCallback<PaymentIntent> {
781
783
  override fun onError(e: Exception) {
782
- promise.resolve(createResult("paymentIntent", WritableNativeMap()))
784
+ promise.resolve(createResult("paymentIntent", Arguments.createMap()))
783
785
  }
784
786
 
785
787
  override fun onSuccess(result: PaymentIntent) {
@@ -799,7 +801,7 @@ class StripeSdkModule(
799
801
  expand = listOf("payment_method"),
800
802
  object : ApiResultCallback<SetupIntent> {
801
803
  override fun onError(e: Exception) {
802
- promise.resolve(createResult("setupIntent", WritableNativeMap()))
804
+ promise.resolve(createResult("setupIntent", Arguments.createMap()))
803
805
  }
804
806
 
805
807
  override fun onSuccess(result: SetupIntent) {
@@ -829,6 +831,9 @@ class StripeSdkModule(
829
831
  }
830
832
  }
831
833
  }
834
+ }.also {
835
+ registerStripeUIManager(it)
836
+ it.present()
832
837
  }
833
838
  }
834
839
 
@@ -909,7 +914,7 @@ class StripeSdkModule(
909
914
  PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
910
915
  val result: WritableMap =
911
916
  error ?: run {
912
- val map = WritableNativeMap()
917
+ val map = Arguments.createMap()
913
918
  map.putBoolean("isInWallet", isCardInWallet)
914
919
  map.putMap("token", token)
915
920
  map
@@ -1129,7 +1134,7 @@ class StripeSdkModule(
1129
1134
  params: ReadableMap,
1130
1135
  promise: Promise,
1131
1136
  ) {
1132
- val timeout = params.getIntOrNull("timeout")?.toLong()
1137
+ val timeout = params.getLongOrNull("timeout")
1133
1138
  customerSheetManager?.present(promise, timeout) ?: run {
1134
1139
  promise.resolve(CustomerSheetManager.createMissingInitError())
1135
1140
  }
@@ -1329,6 +1334,39 @@ class StripeSdkModule(
1329
1334
  // noop, iOS only
1330
1335
  }
1331
1336
 
1337
+ @ReactMethod
1338
+ override fun openAuthenticatedWebView(
1339
+ id: String,
1340
+ url: String,
1341
+ promise: Promise,
1342
+ ) {
1343
+ val activity = getCurrentActivityOrResolveWithError(promise) ?: return
1344
+
1345
+ UiThreadUtil.runOnUiThread {
1346
+ try {
1347
+ val uri = android.net.Uri.parse(url)
1348
+ val builder =
1349
+ androidx.browser.customtabs.CustomTabsIntent
1350
+ .Builder()
1351
+
1352
+ // Set toolbar color for better UX
1353
+ builder.setShowTitle(true)
1354
+ builder.setUrlBarHidingEnabled(true)
1355
+
1356
+ val customTabsIntent = builder.build()
1357
+
1358
+ // Note: Custom Tabs doesn't have built-in redirect handling like iOS ASWebAuthenticationSession.
1359
+ // The redirect will be handled via deep linking when the auth server redirects to stripe-connect://
1360
+ // The React Native Linking module will capture the deep link and pass it back to the JS layer.
1361
+ customTabsIntent.launchUrl(activity, uri)
1362
+
1363
+ promise.resolve(null)
1364
+ } catch (e: Exception) {
1365
+ promise.resolve(createError("Failed", e))
1366
+ }
1367
+ }
1368
+ }
1369
+
1332
1370
  override fun addListener(eventType: String?) {
1333
1371
  // noop, iOS only
1334
1372
  }
@@ -1376,7 +1414,7 @@ class StripeSdkModule(
1376
1414
  * provided will be resolved with an error message instructing the user to retry the method.
1377
1415
  */
1378
1416
  private fun getCurrentActivityOrResolveWithError(promise: Promise?): FragmentActivity? {
1379
- (currentActivity as? FragmentActivity)?.let {
1417
+ (reactApplicationContext.currentActivity as? FragmentActivity)?.let {
1380
1418
  return it
1381
1419
  }
1382
1420
  promise?.resolve(createMissingActivityError())
@@ -1430,14 +1468,14 @@ class StripeSdkModule(
1430
1468
  */
1431
1469
  private fun preventActivityRecreation() {
1432
1470
  isRecreatingReactActivity = false
1433
- currentActivity?.application?.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks)
1434
- currentActivity?.application?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
1471
+ reactApplicationContext.currentActivity?.application?.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks)
1472
+ reactApplicationContext.currentActivity?.application?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
1435
1473
  }
1436
1474
 
1437
1475
  private fun setupComposeCompatView() {
1438
1476
  UiThreadUtil.runOnUiThread {
1439
1477
  composeCompatView = composeCompatView ?: StripeAbstractComposeView.CompatView(context = reactApplicationContext).also {
1440
- currentActivity?.findViewById<ViewGroup>(android.R.id.content)?.addView(
1478
+ reactApplicationContext.currentActivity?.findViewById<ViewGroup>(android.R.id.content)?.addView(
1441
1479
  it,
1442
1480
  )
1443
1481
  }
@@ -19,11 +19,20 @@ class StripeSdkPackage : BaseReactPackage() {
19
19
  ): NativeModule? =
20
20
  when (name) {
21
21
  StripeSdkModule.NAME -> StripeSdkModule(reactContext)
22
+ NativeOnrampSdkModuleSpec.NAME -> {
23
+ val onrampModuleClass = getOnrampModuleClass()
24
+ val constructor = onrampModuleClass.getConstructor(ReactApplicationContext::class.java)
25
+ constructor.newInstance(reactContext) as NativeModule
26
+ }
22
27
  else -> null
23
28
  }
24
29
 
25
30
  override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
26
- val moduleList: Array<Class<out NativeModule?>> = arrayOf(StripeSdkModule::class.java)
31
+ val moduleList: Array<Class<out NativeModule?>> =
32
+ arrayOf(
33
+ StripeSdkModule::class.java,
34
+ getOnrampModuleClass(),
35
+ )
27
36
  val reactModuleInfoMap: MutableMap<String, ReactModuleInfo> = HashMap()
28
37
  for (moduleClass in moduleList) {
29
38
  val reactModule = moduleClass.getAnnotation(ReactModule::class.java) ?: continue
@@ -47,8 +56,18 @@ class StripeSdkPackage : BaseReactPackage() {
47
56
  StripeContainerManager(),
48
57
  CardFormViewManager(),
49
58
  GooglePayButtonManager(),
50
- AddToWalletButtonManager(reactContext),
59
+ AddToWalletButtonManager(),
51
60
  AddressSheetViewManager(),
52
61
  EmbeddedPaymentElementViewManager(),
62
+ NavigationBarManager(),
53
63
  )
64
+
65
+ private fun getOnrampModuleClass(): Class<out NativeModule?> {
66
+ if (BuildConfig.IS_ONRAMP_INCLUDED) {
67
+ @Suppress("UNCHECKED_CAST")
68
+ return Class.forName("com.reactnativestripesdk.OnrampSdkModule") as Class<out NativeModule?>
69
+ } else {
70
+ return FakeOnrampSdkModule::class.java
71
+ }
72
+ }
54
73
  }
@@ -3,9 +3,9 @@ package com.reactnativestripesdk.addresssheet
3
3
  import android.annotation.SuppressLint
4
4
  import android.util.Log
5
5
  import android.widget.FrameLayout
6
+ import com.facebook.react.bridge.Arguments
6
7
  import com.facebook.react.bridge.ReadableMap
7
8
  import com.facebook.react.bridge.WritableMap
8
- import com.facebook.react.bridge.WritableNativeMap
9
9
  import com.facebook.react.uimanager.ThemedReactContext
10
10
  import com.facebook.react.uimanager.UIManagerHelper
11
11
  import com.reactnativestripesdk.buildPaymentSheetAppearance
@@ -172,14 +172,14 @@ class AddressSheetView(
172
172
  }
173
173
 
174
174
  internal fun buildResult(addressDetails: AddressDetails): WritableMap =
175
- WritableNativeMap().apply {
175
+ Arguments.createMap().apply {
176
176
  putMap(
177
177
  "result",
178
- WritableNativeMap().apply {
178
+ Arguments.createMap().apply {
179
179
  putString("name", addressDetails.name)
180
180
  putMap(
181
181
  "address",
182
- WritableNativeMap().apply {
182
+ Arguments.createMap().apply {
183
183
  putString("city", addressDetails.address?.city)
184
184
  putString("country", addressDetails.address?.country)
185
185
  putString("line1", addressDetails.address?.line1)
@@ -41,7 +41,7 @@ class AddressSheetViewManager :
41
41
  view: AddressSheetView,
42
42
  appearance: Dynamic,
43
43
  ) {
44
- view.setAppearance(appearance.asMap())
44
+ view.setAppearance(appearance.asMapOrNull())
45
45
  }
46
46
 
47
47
  @ReactProp(name = "defaultValues")
@@ -49,7 +49,7 @@ class AddressSheetViewManager :
49
49
  view: AddressSheetView,
50
50
  defaults: Dynamic,
51
51
  ) {
52
- view.setDefaultValues(defaults.asMap())
52
+ view.setDefaultValues(defaults.asMapOrNull())
53
53
  }
54
54
 
55
55
  @ReactProp(name = "additionalFields")
@@ -12,17 +12,14 @@ import com.facebook.react.bridge.Promise
12
12
  import com.facebook.react.bridge.ReactApplicationContext
13
13
  import com.facebook.react.bridge.ReadableMap
14
14
  import com.facebook.react.bridge.WritableMap
15
- import com.facebook.react.bridge.WritableNativeMap
16
15
  import com.reactnativestripesdk.ReactNativeCustomerAdapter
17
16
  import com.reactnativestripesdk.ReactNativeCustomerSessionProvider
17
+ import com.reactnativestripesdk.buildBillingDetails
18
+ import com.reactnativestripesdk.buildBillingDetailsCollectionConfiguration
18
19
  import com.reactnativestripesdk.buildPaymentSheetAppearance
19
20
  import com.reactnativestripesdk.getBase64FromBitmap
20
21
  import com.reactnativestripesdk.getBitmapFromDrawable
21
- import com.reactnativestripesdk.getIntegerArrayList
22
- import com.reactnativestripesdk.getStringArrayList
23
- import com.reactnativestripesdk.mapToAddressCollectionMode
24
22
  import com.reactnativestripesdk.mapToCardBrandAcceptance
25
- import com.reactnativestripesdk.mapToCollectionMode
26
23
  import com.reactnativestripesdk.utils.CreateTokenErrorType
27
24
  import com.reactnativestripesdk.utils.ErrorType
28
25
  import com.reactnativestripesdk.utils.KeepJsAwakeTask
@@ -30,6 +27,8 @@ import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
30
27
  import com.reactnativestripesdk.utils.StripeUIManager
31
28
  import com.reactnativestripesdk.utils.createError
32
29
  import com.reactnativestripesdk.utils.getBooleanOr
30
+ import com.reactnativestripesdk.utils.getIntegerList
31
+ import com.reactnativestripesdk.utils.getStringList
33
32
  import com.reactnativestripesdk.utils.mapFromPaymentMethod
34
33
  import com.reactnativestripesdk.utils.mapToPreferredNetworks
35
34
  import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
@@ -66,7 +65,7 @@ class CustomerSheetManager(
66
65
  val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
67
66
  val allowsRemovalOfLastSavedPaymentMethod =
68
67
  arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
69
- val paymentMethodOrder = arguments.getStringArrayList("paymentMethodOrder")
68
+ val paymentMethodOrder = arguments.getStringList("paymentMethodOrder")
70
69
 
71
70
  val appearance =
72
71
  try {
@@ -83,7 +82,7 @@ class CustomerSheetManager(
83
82
  .googlePayEnabled(googlePayEnabled)
84
83
  .headerTextForSelectionScreen(headerTextForSelectionScreen)
85
84
  .preferredNetworks(
86
- mapToPreferredNetworks(arguments.getIntegerArrayList("preferredNetworks")),
85
+ mapToPreferredNetworks(arguments.getIntegerList("preferredNetworks")),
87
86
  ).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
88
87
  .cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
89
88
 
@@ -126,7 +125,10 @@ class CustomerSheetManager(
126
125
  val customerId = arguments.getString("customerId")
127
126
  if (customerId == null) {
128
127
  initPromise.resolve(
129
- createError(ErrorType.Failed.toString(), "When using `customerEphemeralKeySecret` you must provide a value for `customerId`"),
128
+ createError(
129
+ ErrorType.Failed.toString(),
130
+ "When using `customerEphemeralKeySecret` you must provide a value for `customerId`",
131
+ ),
130
132
  )
131
133
  return
132
134
  }
@@ -157,7 +159,7 @@ class CustomerSheetManager(
157
159
 
158
160
  customerSheet?.configure(configuration.build())
159
161
 
160
- initPromise.resolve(WritableNativeMap())
162
+ initPromise.resolve(Arguments.createMap())
161
163
  }
162
164
 
163
165
  private fun handleResult(result: CustomerSheetResult) {
@@ -295,33 +297,11 @@ class CustomerSheetManager(
295
297
  internal fun createMissingInitError(): WritableMap =
296
298
  createError(ErrorType.Failed.toString(), "No customer sheet has been initialized yet.")
297
299
 
298
- internal fun createDefaultBillingDetails(map: ReadableMap): PaymentSheet.BillingDetails {
299
- val addressMap = map.getMap("address")
300
- val address =
301
- PaymentSheet.Address(
302
- addressMap?.getString("city"),
303
- addressMap?.getString("country"),
304
- addressMap?.getString("line1"),
305
- addressMap?.getString("line2"),
306
- addressMap?.getString("postalCode"),
307
- addressMap?.getString("state"),
308
- )
309
- return PaymentSheet.BillingDetails(
310
- address,
311
- map.getString("email"),
312
- map.getString("name"),
313
- map.getString("phone"),
314
- )
315
- }
300
+ internal fun createDefaultBillingDetails(map: ReadableMap): PaymentSheet.BillingDetails =
301
+ buildBillingDetails(map) ?: PaymentSheet.BillingDetails()
316
302
 
317
303
  internal fun createBillingDetailsCollectionConfiguration(map: ReadableMap): PaymentSheet.BillingDetailsCollectionConfiguration =
318
- PaymentSheet.BillingDetailsCollectionConfiguration(
319
- name = mapToCollectionMode(map.getString("name")),
320
- phone = mapToCollectionMode(map.getString("phone")),
321
- email = mapToCollectionMode(map.getString("email")),
322
- address = mapToAddressCollectionMode(map.getString("address")),
323
- attachDefaultsToPaymentMethod = map.getBooleanOr("attachDefaultsToPaymentMethod", false),
324
- )
304
+ buildBillingDetailsCollectionConfiguration(map)
325
305
 
326
306
  internal fun createCustomerAdapter(
327
307
  context: ReactApplicationContext,
@@ -404,7 +384,7 @@ class CustomerSheetManager(
404
384
  val onBehalfOf = bundle.getString("onBehalfOf")
405
385
  CustomerSheet.IntentConfiguration
406
386
  .Builder()
407
- .paymentMethodTypes(bundle.getStringArrayList("paymentMethodTypes") ?: emptyList())
387
+ .paymentMethodTypes(bundle.getStringList("paymentMethodTypes") ?: emptyList())
408
388
  .apply {
409
389
  if (onBehalfOf != null) {
410
390
  this.onBehalfOf(onBehalfOf)
@@ -11,7 +11,8 @@ class ReactNativeCustomerSessionProvider(
11
11
  private val stripeSdkModule = context.getNativeModule(StripeSdkModule::class.java)
12
12
 
13
13
  internal var provideSetupIntentClientSecretCallback: CompletableDeferred<String>? = null
14
- internal var providesCustomerSessionClientSecretCallback: CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>? = null
14
+ internal var providesCustomerSessionClientSecretCallback:
15
+ CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>? = null
15
16
 
16
17
  override suspend fun intentConfiguration(): Result<CustomerSheet.IntentConfiguration> = Result.success(intentConfiguration)
17
18
 
@@ -1,7 +1,5 @@
1
1
  package com.reactnativestripesdk.pushprovisioning
2
2
 
3
- import android.content.Context
4
- import com.bumptech.glide.Glide
5
3
  import com.facebook.react.bridge.Dynamic
6
4
  import com.facebook.react.bridge.ReadableMap
7
5
  import com.facebook.react.module.annotations.ReactModule
@@ -13,12 +11,10 @@ import com.facebook.react.viewmanagers.AddToWalletButtonManagerInterface
13
11
  import com.reactnativestripesdk.utils.asMapOrNull
14
12
 
15
13
  @ReactModule(name = AddToWalletButtonManager.REACT_CLASS)
16
- class AddToWalletButtonManager(
17
- applicationContext: Context,
18
- ) : SimpleViewManager<AddToWalletButtonView>(),
14
+ class AddToWalletButtonManager :
15
+ SimpleViewManager<AddToWalletButtonView>(),
19
16
  AddToWalletButtonManagerInterface<AddToWalletButtonView> {
20
17
  private val delegate = AddToWalletButtonManagerDelegate(this)
21
- private val requestManager = Glide.with(applicationContext)
22
18
 
23
19
  override fun getName() = REACT_CLASS
24
20
 
@@ -34,8 +30,7 @@ class AddToWalletButtonManager(
34
30
  view.onAfterUpdateTransaction()
35
31
  }
36
32
 
37
- override fun createViewInstance(reactContext: ThemedReactContext): AddToWalletButtonView =
38
- AddToWalletButtonView(reactContext, requestManager)
33
+ override fun createViewInstance(reactContext: ThemedReactContext): AddToWalletButtonView = AddToWalletButtonView(reactContext)
39
34
 
40
35
  override fun getExportedCustomDirectEventTypeConstants() =
41
36
  mutableMapOf(
@@ -64,7 +59,7 @@ class AddToWalletButtonManager(
64
59
  view: AddToWalletButtonView,
65
60
  ephemeralKey: Dynamic,
66
61
  ) {
67
- val map = ephemeralKey.asMap()
62
+ val map = ephemeralKey.asMapOrNull()
68
63
  if (map == null) return
69
64
  view.setEphemeralKey(map)
70
65
  }
@@ -74,7 +69,7 @@ class AddToWalletButtonManager(
74
69
  view: AddToWalletButtonView,
75
70
  token: Dynamic,
76
71
  ) {
77
- val map = token.asMap()
72
+ val map = token.asMapOrNull()
78
73
  if (map == null) return
79
74
  view.setToken(map)
80
75
  }
@@ -2,37 +2,45 @@ package com.reactnativestripesdk.pushprovisioning
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import android.content.res.ColorStateList
5
- import android.graphics.Color
6
5
  import android.graphics.drawable.Drawable
7
6
  import android.graphics.drawable.RippleDrawable
8
7
  import android.view.MotionEvent
9
8
  import android.webkit.URLUtil
10
9
  import androidx.appcompat.widget.AppCompatImageView
11
- import com.bumptech.glide.RequestManager
12
- import com.bumptech.glide.load.DataSource
13
- import com.bumptech.glide.load.engine.GlideException
14
- import com.bumptech.glide.load.model.GlideUrl
15
- import com.bumptech.glide.request.RequestListener
16
- import com.bumptech.glide.request.target.Target
10
+ import androidx.core.graphics.drawable.toDrawable
11
+ import androidx.core.graphics.toColorInt
12
+ import androidx.core.net.toUri
13
+ import com.facebook.common.executors.UiThreadImmediateExecutorService
14
+ import com.facebook.common.references.CloseableReference
15
+ import com.facebook.datasource.BaseDataSubscriber
16
+ import com.facebook.datasource.DataSource
17
+ import com.facebook.drawee.backends.pipeline.Fresco
18
+ import com.facebook.imagepipeline.image.CloseableBitmap
19
+ import com.facebook.imagepipeline.image.CloseableImage
20
+ import com.facebook.imagepipeline.request.ImageRequestBuilder
17
21
  import com.facebook.react.bridge.ReadableMap
18
22
  import com.facebook.react.bridge.WritableMap
19
23
  import com.facebook.react.uimanager.ThemedReactContext
20
24
  import com.facebook.react.uimanager.UIManagerHelper
25
+ import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
21
26
  import com.reactnativestripesdk.utils.createError
22
27
 
23
28
  @SuppressLint("ViewConstructor")
24
29
  class AddToWalletButtonView(
25
30
  private val context: ThemedReactContext,
26
- private val requestManager: RequestManager,
27
31
  ) : AppCompatImageView(context) {
28
32
  private var cardDetails: ReadableMap? = null
29
33
  private var ephemeralKey: String? = null
30
34
  private var sourceMap: ReadableMap? = null
31
35
  private var token: ReadableMap? = null
32
36
 
33
- private var loadedSource: Any? = null
34
- private var heightOverride: Int = 0
35
- private var widthOverride: Int = 0
37
+ private var loadedSource: String? = null
38
+ private var currentDataSource: DataSource<CloseableReference<CloseableImage>>? = null
39
+
40
+ init {
41
+ scaleType = ScaleType.CENTER_CROP
42
+ clipToOutline = true
43
+ }
36
44
 
37
45
  override fun performClick(): Boolean {
38
46
  super.performClick()
@@ -78,85 +86,90 @@ class AddToWalletButtonView(
78
86
  }
79
87
 
80
88
  fun onAfterUpdateTransaction() {
81
- val sourceToLoad = getUrlOrResourceId(sourceMap)
82
- if (sourceToLoad == null) {
83
- requestManager.clear(this)
89
+ val uri = sourceMap?.getString("uri")
90
+ if (uri == null) {
91
+ cancelCurrentRequest()
84
92
  setImageDrawable(null)
85
93
  loadedSource = null
86
- } else if (sourceToLoad != loadedSource || (heightOverride > 0 || widthOverride > 0)) {
87
- loadedSource = sourceToLoad
88
- val scale = sourceMap?.getDouble("scale") ?: 1.0
89
-
90
- requestManager
91
- .load(sourceToLoad)
92
- .addListener(
93
- object : RequestListener<Drawable> {
94
- override fun onLoadFailed(
95
- e: GlideException?,
96
- model: Any?,
97
- target: Target<Drawable>?,
98
- isFirstResource: Boolean,
99
- ): Boolean {
100
- dispatchEvent(
101
- createError("Failed", "Failed to load the source from $sourceToLoad"),
102
- )
103
- return true
104
- }
105
-
106
- override fun onResourceReady(
107
- resource: Drawable?,
108
- model: Any?,
109
- target: Target<Drawable>?,
110
- dataSource: DataSource?,
111
- isFirstResource: Boolean,
112
- ): Boolean {
113
- setImageDrawable(
114
- RippleDrawable(
115
- ColorStateList.valueOf(Color.parseColor("#e0e0e0")),
116
- resource,
117
- null,
118
- ),
119
- )
120
- return true
121
- }
122
- },
123
- ).centerCrop()
124
- .override((widthOverride * scale).toInt(), (heightOverride * scale).toInt())
125
- .into(this)
94
+ return
126
95
  }
127
- }
128
96
 
129
- private fun getUrlOrResourceId(sourceMap: ReadableMap?): Any? {
130
- sourceMap?.getString("uri")?.let {
131
- return if (URLUtil.isValidUrl(it)) {
132
- // Debug mode, Image.resolveAssetSource resolves to local http:// URL
133
- GlideUrl(it)
97
+ if (uri != loadedSource) {
98
+ loadedSource = uri
99
+ if (URLUtil.isValidUrl(uri)) {
100
+ // Debug mode: Image.resolveAssetSource resolves to local http:// URL
101
+ loadImageFromUrl(uri)
134
102
  } else {
135
- // Release mode, Image.resolveAssetSource resolves to a drawable resource
136
- context.resources.getIdentifier(it, "drawable", context.packageName)
103
+ // Release mode: Image.resolveAssetSource resolves to a drawable resource name
104
+ loadImageFromDrawable(uri)
137
105
  }
138
106
  }
139
- return null
140
107
  }
141
108
 
142
- override fun onSizeChanged(
143
- w: Int,
144
- h: Int,
145
- oldw: Int,
146
- oldh: Int,
147
- ) {
148
- super.onSizeChanged(w, h, oldw, oldh)
149
- if (w > 0 && h > 0) {
150
- heightOverride = h
151
- widthOverride = w
152
- onAfterUpdateTransaction()
153
- heightOverride = 0
154
- widthOverride = 0
109
+ private fun loadImageFromUrl(url: String) {
110
+ cancelCurrentRequest()
111
+
112
+ val imageRequest =
113
+ ImageRequestBuilder
114
+ .newBuilderWithSource(url.toUri())
115
+ .build()
116
+
117
+ val dataSource = Fresco.getImagePipeline().fetchDecodedImage(imageRequest, context)
118
+ currentDataSource = dataSource
119
+
120
+ dataSource.subscribe(
121
+ object : BaseDataSubscriber<CloseableReference<CloseableImage>>() {
122
+ override fun onNewResultImpl(dataSource: DataSource<CloseableReference<CloseableImage>>) {
123
+ if (!dataSource.isFinished) return
124
+ val imageRef = dataSource.result ?: return
125
+
126
+ try {
127
+ val image = imageRef.get()
128
+ if (image is CloseableBitmap) {
129
+ val drawable = image.underlyingBitmap.toDrawable(resources)
130
+ setImageWithRipple(drawable)
131
+ }
132
+ } finally {
133
+ CloseableReference.closeSafely(imageRef)
134
+ }
135
+ }
136
+
137
+ override fun onFailureImpl(dataSource: DataSource<CloseableReference<CloseableImage>>) {
138
+ dispatchEvent(createError("Failed", "Failed to load the source from $url"))
139
+ }
140
+ },
141
+ UiThreadImmediateExecutorService.getInstance(),
142
+ )
143
+ }
144
+
145
+ private fun loadImageFromDrawable(resourceName: String) {
146
+ // Instance is deprecated, but have to use until we drop support for RN 0.79
147
+ @Suppress("DEPRECATION")
148
+ val drawable = ResourceDrawableIdHelper.instance.getResourceDrawable(context, resourceName)
149
+ if (drawable != null) {
150
+ setImageWithRipple(drawable)
151
+ } else {
152
+ dispatchEvent(createError("Failed", "Failed to load drawable resource: $resourceName"))
155
153
  }
156
154
  }
157
155
 
156
+ private fun setImageWithRipple(drawable: Drawable) {
157
+ setImageDrawable(
158
+ RippleDrawable(
159
+ ColorStateList.valueOf("#e0e0e0".toColorInt()),
160
+ drawable,
161
+ null,
162
+ ),
163
+ )
164
+ }
165
+
166
+ private fun cancelCurrentRequest() {
167
+ currentDataSource?.close()
168
+ currentDataSource = null
169
+ }
170
+
158
171
  fun onDropViewInstance() {
159
- requestManager.clear(this)
172
+ cancelCurrentRequest()
160
173
  }
161
174
 
162
175
  fun setSourceMap(map: ReadableMap?) {