Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:adaptyteam/onboardings-ios into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksei-valiano committed Aug 29, 2024
2 parents 4e0e2d2 + c0a1ab6 commit b347922
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,10 @@ struct ApplicationMainView: View {
}
}

var body: some View {
var applicationWithOnboarding: some View {
ZStack {
if showPaywall, let paywall = viewModel.adaptyPaywall,
let viewConfig = viewModel.adaptyViewConfiguration
{
applicationView
.zIndex(0)
.paywall(
isPresented: $showPaywall,
paywall: paywall,
viewConfiguration: viewConfig,
didFailPurchase: { _, _ in },
didFinishRestore: { _ in },
didFailRestore: { _ in },
didFailRendering: { _ in }
)
.onAppear {
showOnboarding = false
}
} else {
applicationView
.zIndex(0)
}
applicationView
.zIndex(0)

if showOnboarding, let onboardingId = viewModel.onboardingId {
Onboardings.swiftuiView(
Expand All @@ -75,6 +56,10 @@ struct ApplicationMainView: View {
},
onOpenPaywallAction: { _ in
showPaywall = true

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.showOnboarding = false
}
},
onStateUpdatedAction: { action in
viewModel.handleOnboardingStateUpdatedAction(action)
Expand All @@ -92,19 +77,38 @@ struct ApplicationMainView: View {
ApplicationSplashView()
.zIndex(1)
}
}
.onAppear {
viewModel.onError = { error in
errorAlert = .init(value: error)

if let paywall = viewModel.adaptyPaywall,
let viewConfig = viewModel.adaptyViewConfiguration
{
Color.clear
.paywall(
isPresented: $showPaywall,
paywall: paywall,
viewConfiguration: viewConfig,
didFailPurchase: { _, _ in },
didFinishRestore: { _ in },
didFailRestore: { _ in },
didFailRendering: { _ in }
)
}
viewModel.loadOnboardingId()
}
.alert(item: $errorAlert) { error in
Alert(
title: Text("Error!"),
message: Text(error.value.localizedDescription),
dismissButton: .cancel()
)
}
}

var body: some View {
applicationWithOnboarding
.onAppear {
viewModel.onError = { error in
errorAlert = .init(value: error)
}
viewModel.loadOnboardingId()
}
.alert(item: $errorAlert) { error in
Alert(
title: Text("Error!"),
message: Text(error.value.localizedDescription),
dismissButton: .cancel()
)
}
}
}
17 changes: 11 additions & 6 deletions Sources/Rendering/OnboardingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ public final class OnboardingController: UIViewController {
self.delegate = delegate
self.viewModel = OnboardingViewModel(
stamp: stamp,
url: url )
url: url
)

super.init(nibName: nil, bundle: nil)
self.viewModel.onMessage = { [weak self] message in

viewModel.onMessage = { [weak self] message in
self?.handleMessage(message)
}
self.viewModel.onError = { [weak self] error in

viewModel.onError = { [weak self] error in
self?.handleError(error)
}
}
Expand Down Expand Up @@ -62,7 +63,11 @@ public final class OnboardingController: UIViewController {
}

private func buildWebView() -> WKWebView {
let webView = WKWebView()
let config = WKWebViewConfiguration()
config.allowsInlineMediaPlayback = true
config.mediaTypesRequiringUserActionForPlayback = []

let webView = WKWebView(frame: .zero, configuration: config)

return webView
}
Expand Down

0 comments on commit b347922

Please sign in to comment.