Skip to content

Commit

Permalink
fix: allow reload iOS cmponents in DEBUG mode
Browse files Browse the repository at this point in the history
  • Loading branch information
descorp committed Jul 17, 2023
1 parent dabefd4 commit b1288b1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
20 changes: 8 additions & 12 deletions ios/Components/AdyenDropIn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ import React

@objc(AdyenDropIn)
final internal class AdyenDropIn: BaseModule {

private var dropInComponent: DropInComponent?

override func supportedEvents() -> [String]! { super.supportedEvents() }

private var dropInComponent: DropInComponent? {
currentComponent as? DropInComponent
}

@objc
func hide(_ success: NSNumber, event: NSDictionary) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

self.dropInComponent?.finalizeIfNeeded(with: success.boolValue) {
self.cleanUp()
self.dropInComponent = nil
}
}
dismiss(success.boolValue)
}

@objc
Expand Down Expand Up @@ -55,8 +51,8 @@ final internal class AdyenDropIn: BaseModule {
let component = DropInComponent(paymentMethods: paymentMethods,
configuration: config,
style: dropInComponentStyle)
dropInComponent = component
dropInComponent?.delegate = self
currentComponent = component
component.delegate = self
present(component: component)
}

Expand Down
11 changes: 3 additions & 8 deletions ios/Components/ApplePayComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ import React

@objc(AdyenApplePay)
final internal class ApplePayComponent: BaseModule {

override func supportedEvents() -> [String]! { super.supportedEvents() }

@objc
func hide(_ success: NSNumber, event: NSDictionary) {
DispatchQueue.main.async {[weak self] in
guard let self = self else { return }

self.currentComponent?.finalizeIfNeeded(with: success.boolValue) {
self.cleanUp()
}
}
dismiss(success.boolValue)
}

@objc
Expand Down
17 changes: 17 additions & 0 deletions ios/Components/BaseModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import Adyen
import Adyen3DS2

internal class BaseModule: RCTEventEmitter {

#if DEBUG
override func invalidate() {
super.invalidate()
dismiss(false)
}
#endif

@objc
override static func requiresMainQueueSetup() -> Bool { true }
Expand Down Expand Up @@ -135,6 +142,16 @@ internal class BaseModule: RCTEventEmitter {
currentPresenter = nil
}

internal func dismiss(_ result: Bool) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

self.currentComponent?.finalizeIfNeeded(with: result) {
self.cleanUp()
}
}
}

}

extension BaseModule {
Expand Down
9 changes: 2 additions & 7 deletions ios/Components/InstantComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ import React

@objc(AdyenInstant)
final internal class InstantComponent: BaseModule {

override func supportedEvents() -> [String]! { super.supportedEvents() }

@objc
func hide(_ success: NSNumber, event: NSDictionary) {
DispatchQueue.main.async {[weak self] in
guard let self = self else { return }

self.currentComponent?.finalizeIfNeeded(with: success.boolValue) {
self.cleanUp()
}
}
dismiss(success.boolValue)
}

@objc
Expand Down

0 comments on commit b1288b1

Please sign in to comment.