Skip to content

Instantly share code, notes, and snippets.

@aliakhtar49
Last active December 25, 2022 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliakhtar49/90e470d17ac5dfa9868b3487e8d66646 to your computer and use it in GitHub Desktop.
Save aliakhtar49/90e470d17ac5dfa9868b3487e8d66646 to your computer and use it in GitHub Desktop.
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