Last active
December 25, 2022 13:51
-
-
Save aliakhtar49/90e470d17ac5dfa9868b3487e8d66646 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol PaymentDetailsViewLoadable { | |
/// Communication with client | |
var output: AnyPublisher<PaymentDetailLoadableOutput, Never> { get } | |
/// render payment details view into the view provided | |
func renderView( | |
componentId: String, | |
into containerView: UIView | |
) | |
} | |
/// Types of publish events for client | |
public enum PaymentDetailLoadableOutput { | |
case hide | |
} | |
public final class PaymentDetailsViewLoader: PaymentDetailsViewLoadable { | |
private var cancellables = Set<AnyCancellable>() | |
private let subject = PassthroughSubject<PaymentDetailLoadableOutput, Never>() | |
public var output: AnyPublisher<PaymentDetailLoadableOutput, Never> { | |
subject.eraseToAnyPublisher() | |
} | |
public func renderView( | |
componentId: String, | |
into containerView: UIView | |
) { | |
let paymentDetailsViewModel = DefaultPaymentDetailsViewModel() | |
paymentDetailsViewModel.parentViewModelPublisher | |
.sink { [weak self] output in | |
switch output { | |
case .hide: | |
self?.outputSubject.send(.hide) | |
} | |
} | |
.store(in: &cancellables) | |
let paymentDetailsContainer = PaymentDetailsContainerView( | |
paymentDetailsViewModel: paymentDetailsViewModel | |
) | |
containerView.addSubview(paymentDetailsContainer) | |
paymentDetailsContainer.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 0).isActive = true | |
paymentDetailsContainer.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: 0).isActive = true | |
paymentDetailsContainer.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 0).isActive = true | |
paymentDetailsContainer.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 0).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment