-
Notifications
You must be signed in to change notification settings - Fork 42
[WIP] Card view #787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
[WIP] Card view #787
Changes from all commits
22b501d
d6d634c
b13d731
03f0bea
e11a811
5eb838b
a2b5521
66ccec6
5859150
d1ee809
70fc175
d3a0be3
24a057f
7608979
808f853
c5ef27d
9cd1532
9889dd6
a1d84eb
f907743
07b87a0
75747d1
e8000d3
1604b0c
e8d6ec6
c105abd
af97fad
3abda40
a3bdff9
6815295
224e17e
94f7cdc
822aebf
743913b
d163b04
412f9c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| yarn test | ||
| yarn lint | ||
| yarn typecheck | ||
| swiftformat --lint . | ||
| yarn test > /dev/null 2>&1 || yarn test | ||
| yarn lint > /dev/null 2>&1 || yarn lint | ||
| yarn typecheck > /dev/null 2>&1 || yarn typecheck | ||
| swiftformat --lint ios > /dev/null 2>&1 || swiftformat --lint ios | ||
| ktlint "!**node_modules**" > /dev/null 2>&1 || ktlint "!**node_modules**" | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,30 +7,49 @@ | |||||
| package com.adyenreactnativesdk | ||||||
|
|
||||||
| import android.annotation.SuppressLint | ||||||
| import com.adyen.checkout.components.core.AddressData | ||||||
| import com.adyen.checkout.components.core.internal.analytics.AnalyticsPlatform | ||||||
| import com.adyen.checkout.components.core.internal.analytics.AnalyticsPlatformParams | ||||||
| import com.adyenreactnativesdk.component.MessageBusModule | ||||||
| import com.adyenreactnativesdk.component.SessionHelperModule | ||||||
| import com.adyenreactnativesdk.component.applepay.ApplePayModuleMock | ||||||
| import com.adyenreactnativesdk.component.dropin.DropInModule | ||||||
| import com.adyenreactnativesdk.component.googlepay.GooglePayModule | ||||||
| import com.adyenreactnativesdk.component.instant.InstantModule | ||||||
| import com.adyenreactnativesdk.component.model.AddressDataAdapter | ||||||
| import com.adyenreactnativesdk.cse.ActionModule | ||||||
| import com.adyenreactnativesdk.cse.AdyenCSEModule | ||||||
| import com.adyenreactnativesdk.react.CardViewManager | ||||||
| import com.adyenreactnativesdk.react.PlatformPayViewManager | ||||||
| import com.adyenreactnativesdk.util.messaging.MessageBus | ||||||
| import com.facebook.react.ReactPackage | ||||||
| import com.facebook.react.bridge.NativeModule | ||||||
| import com.facebook.react.bridge.ReactApplicationContext | ||||||
| import com.facebook.react.uimanager.ViewManager | ||||||
| import com.google.gson.GsonBuilder | ||||||
|
|
||||||
| class AdyenPaymentPackage : ReactPackage { | ||||||
| override fun createViewManagers(reactContext: ReactApplicationContext) = listOf(PlatformPayViewManager()) | ||||||
| override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<in Nothing, in Nothing>> { | ||||||
| val messageBus = getOrCreateMessageBus(reactContext) | ||||||
| val cardView = CardViewManager(messageBus) | ||||||
| MessageBusModule.consumers[CardViewManager.NAME] = cardView | ||||||
|
|
||||||
| return listOf( | ||||||
| PlatformPayViewManager(), | ||||||
| cardView, | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { | ||||||
| configureAnalytics() | ||||||
| val messageBus = getOrCreateMessageBus(reactContext) | ||||||
|
|
||||||
| return listOf( | ||||||
| DropInModule(reactContext), | ||||||
| InstantModule(reactContext), | ||||||
| GooglePayModule(reactContext), | ||||||
| ApplePayModuleMock(reactContext), | ||||||
| DropInModule(reactContext, messageBus, gson), | ||||||
| InstantModule(reactContext, messageBus), | ||||||
| GooglePayModule(reactContext, messageBus), | ||||||
| ApplePayModuleMock(reactContext, messageBus), | ||||||
| MessageBusModule(reactContext, messageBus), | ||||||
| AdyenCSEModule(reactContext), | ||||||
| SessionHelperModule(reactContext), | ||||||
| ActionModule(reactContext), | ||||||
|
|
@@ -43,4 +62,25 @@ class AdyenPaymentPackage : ReactPackage { | |||||
| val version = BuildConfig.CHECKOUT_VERSION | ||||||
| AnalyticsPlatformParams.overrideForCrossPlatform(AnalyticsPlatform.REACT_NATIVE, version) | ||||||
| } | ||||||
|
|
||||||
| companion object { | ||||||
| public val messageBus: MessageBus | ||||||
| get() { | ||||||
| return _messageBus ?: throw Exception("AdyenCheckout MessageBus is not initialized") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throwing a generic
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| @Volatile | ||||||
| private var _messageBus: MessageBus? = null | ||||||
| private val lock = Any() | ||||||
|
|
||||||
| private fun getOrCreateMessageBus(context: ReactApplicationContext): MessageBus = | ||||||
| _messageBus ?: synchronized(lock) { | ||||||
| _messageBus ?: MessageBus(context, gson).also { _messageBus = it } | ||||||
| } | ||||||
|
|
||||||
| private val gson = | ||||||
| GsonBuilder() | ||||||
| .registerTypeAdapter(AddressData::class.java, AddressDataAdapter()) | ||||||
| .create() | ||||||
| } | ||||||
| } | ||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.adyenreactnativesdk.component | ||
|
|
||
| import com.adyen.checkout.components.core.action.Action | ||
| import com.adyenreactnativesdk.component.base.BaseModule | ||
| import com.adyenreactnativesdk.component.base.ModuleException | ||
| import com.adyenreactnativesdk.react.ComponentContract | ||
| import com.adyenreactnativesdk.util.ReactNativeJson | ||
| import com.adyenreactnativesdk.util.messaging.MessageBus | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.ReactMethod | ||
| import com.facebook.react.bridge.ReadableMap | ||
| import org.json.JSONException | ||
|
|
||
| class MessageBusModule( | ||
| val context: ReactApplicationContext?, | ||
| val messageBus: MessageBus, | ||
| ) : BaseModule(context) { | ||
| override fun getName(): String = COMPONENT_NAME | ||
|
|
||
| @ReactMethod | ||
| fun addListener(eventName: String?) { | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun removeListeners(count: Int?) { | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun hide( | ||
| success: Boolean, | ||
| message: ReadableMap?, | ||
| ) { | ||
| cleanup() | ||
| } | ||
|
|
||
| @ReactMethod | ||
| fun handle(actionMap: ReadableMap?) { | ||
| val name = | ||
| currentComponent ?: return messageBus.sendErrorEvent(ModuleException.NoPaymentRegistered()) | ||
|
|
||
| val component = | ||
| consumers[name] | ||
| ?: return messageBus.sendErrorEvent(ModuleException.NoConsumer(name)) | ||
|
|
||
| try { | ||
| val jsonObject = ReactNativeJson.convertMapToJson(actionMap) | ||
| val action = Action.Companion.SERIALIZER.deserialize(jsonObject) | ||
| component.onAction(action) | ||
| } catch (e: JSONException) { | ||
| messageBus.sendErrorEvent(ModuleException.InvalidAction(e)) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val TAG = "MessageBusModule" | ||
| private const val COMPONENT_NAME = "AdyenMessageBus" | ||
| var consumers: MutableMap<String, ComponentContract> = mutableMapOf() | ||
| var currentComponent: String? = null | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current approach of running commands twice on failure (e.g.,
yarn test > /dev/null 2>&1 || yarn test) can be inefficient for long-running tasks like tests. A more efficient pattern would be to capture the command's output and only print it if the command fails, thus avoiding a second execution. For example:This would improve the developer experience by speeding up the pre-commit hook when failures occur.