Skip to content

Commit

Permalink
introduce an environment key to manage dismissing of the selfie captu…
Browse files Browse the repository at this point in the history
…re flow.
  • Loading branch information
tobitech committed Oct 10, 2024
1 parent 661c43a commit 91289f0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 43 deletions.
26 changes: 12 additions & 14 deletions Example/SmileID/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ struct HomeView: View {
_viewModel = StateObject(wrappedValue: HomeViewModel(config: config))
}

let columns = [GridItem(.flexible()), GridItem(.flexible())]

var body: some View {
NavigationView {
VStack(spacing: 24) {
Text("Test Our Products")
.font(SmileID.theme.header2)
.foregroundColor(.black)

MyVerticalGrid(
maxColumns: 2,
items: [
ScrollView(showsIndicators: false) {
LazyVGrid(columns: columns) {
ProductCell(
image: "smart_selfie_enroll",
name: "SmartSelfie™ Enrollment",
Expand All @@ -38,7 +38,7 @@ struct HomeView: View {
)
)
}
),
)
ProductCell(
image: "smart_selfie_authentication",
name: "SmartSelfie™ Authentication",
Expand All @@ -51,7 +51,7 @@ struct HomeView: View {
delegate: viewModel
)
}
),
)
ProductCell(
image: "smart_selfie_enroll",
name: "SmartSelfie™ Enrollment (Strict Mode)",
Expand All @@ -71,7 +71,7 @@ struct HomeView: View {
)
)
}
),
)
ProductCell(
image: "smart_selfie_authentication",
name: "SmartSelfie™ Authentication (Strict Mode)",
Expand All @@ -85,7 +85,7 @@ struct HomeView: View {
delegate: viewModel
)
}
),
)
ProductCell(
image: "enhanced_kyc",
name: "Enhanced KYC",
Expand All @@ -101,7 +101,7 @@ struct HomeView: View {
)
)
}
),
)
ProductCell(
image: "biometric",
name: "Biometric KYC",
Expand All @@ -117,7 +117,7 @@ struct HomeView: View {
)
)
}
),
)
ProductCell(
image: "document",
name: "\nDocument Verification",
Expand All @@ -131,7 +131,7 @@ struct HomeView: View {
delegate: viewModel
)
}
),
)
ProductCell(
image: "enhanced_doc_v",
name: "Enhanced Document Verification",
Expand All @@ -146,10 +146,8 @@ struct HomeView: View {
)
}
)
].map {
AnyView($0)
}
)
}

Text("Partner \(viewModel.partnerId) - Version \(version) - Build \(build)")
.font(SmileID.theme.body)
Expand Down
11 changes: 7 additions & 4 deletions Example/SmileID/Home/ProductCell.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import SmileID
import SwiftUI

struct ProductCell: View {
struct ProductCell<Content: View>: View {
let image: String
let name: String
let onClick: (() -> Void)?
@ViewBuilder let content: () -> any View
@ViewBuilder let content: () -> Content
@State private var isPresented: Bool = false

init(
image: String,
name: String,
onClick: (() -> Void)? = nil,
@ViewBuilder content: @escaping () -> any View
@ViewBuilder content: @escaping () -> Content
) {
self.image = image
self.name = name
Expand Down Expand Up @@ -44,7 +44,10 @@ struct ProductCell: View {
.fullScreenCover(
isPresented: $isPresented,
content: {
AnyView(content())
NavigationView {
content()
}
.environment(\.modalMode, $isPresented)
}
)
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/SmileID/Classes/Helpers/NavigationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ extension View {
}
}
}

public struct ModalModeKey: EnvironmentKey {
public static let defaultValue = Binding<Bool>.constant(false)
}

extension EnvironmentValues {
public var modalMode: Binding<Bool> {
get { self[ModalModeKey.self] }
set { self[ModalModeKey.self] = newValue }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Lottie
import SwiftUI

public struct LivenessCaptureInstructionsView: View {
@Environment(\.presentationMode) private var presentationMode
@Environment(\.modalMode) private var modalMode
@State private var showSelfieCaptureView: Bool = false

private let showAttribution: Bool
Expand All @@ -17,7 +17,7 @@ public struct LivenessCaptureInstructionsView: View {
VStack {
HStack {
Button {
presentationMode.wrappedValue.dismiss()
self.modalMode.wrappedValue = false
} label: {
Text(SmileIDResourcesHelper.localizedString(for: "Action.Cancel"))
.foregroundColor(SmileID.theme.accent)
Expand Down Expand Up @@ -49,7 +49,7 @@ public struct LivenessCaptureInstructionsView: View {
),
isActive: $showSelfieCaptureView
) { EmptyView() }

SmileButton(
title: "Action.GetStarted",
clicked: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ public struct OrchestratedSelfieCaptureScreenV2: View {
}

public var body: some View {
NavigationView {
if showInstructions {
LivenessCaptureInstructionsView(
showAttribution: showAttribution,
viewModel: viewModel
)
} else {
SelfieCaptureScreenV2(
viewModel: viewModel,
showAttribution: showAttribution
)
}
if showInstructions {
LivenessCaptureInstructionsView(
showAttribution: showAttribution,
viewModel: viewModel
)
} else {
SelfieCaptureScreenV2(
viewModel: viewModel,
showAttribution: showAttribution
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public struct SelfieCaptureScreenV2: View {
@ObservedObject var viewModel: SelfieViewModelV2
let showAttribution: Bool

@Environment(\.presentationMode) private var presentationMode
@Environment(\.modalMode) private var modalMode

public var body: some View {
GeometryReader { proxy in
Expand All @@ -29,8 +29,7 @@ public struct SelfieCaptureScreenV2: View {
)
UserInstructionsView(viewModel: viewModel)
if let currentLivenessTask = viewModel.livenessCheckManager.currentTask,
viewModel.faceInBounds
{
viewModel.faceInBounds {
LivenessGuidesView(
currentLivenessTask: currentLivenessTask,
topArcProgress: $viewModel.livenessCheckManager.lookUpProgress,
Expand All @@ -42,7 +41,7 @@ public struct SelfieCaptureScreenV2: View {
VStack {
Spacer()
Button {
presentationMode.wrappedValue.dismiss()
self.modalMode.wrappedValue = false
} label: {
Text(SmileIDResourcesHelper.localizedString(for: "Action.Cancel"))
.foregroundColor(SmileID.theme.accent)
Expand All @@ -57,9 +56,6 @@ public struct SelfieCaptureScreenV2: View {
errorMessage: viewModel.errorMessageRes ?? viewModel.errorMessage,
didTapRetry: {
viewModel.showProcessingView = false
},
didTapdone: {
presentationMode.wrappedValue.dismiss()
}
),
isActive: $viewModel.showProcessingView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ struct SelfieProcessingView: View {
var processingState: ProcessingState
var errorMessage: String?
var didTapRetry: () -> Void
var didTapdone: () -> Void

@Environment(\.presentationMode) private var presentationMode
@Environment(\.modalMode) private var modalMode

var body: some View {
VStack {
Expand Down Expand Up @@ -43,7 +42,7 @@ struct SelfieProcessingView: View {

Spacer()
SmileButton(title: "Action.Done") {
self.presentationMode.wrappedValue.dismiss()
self.modalMode.wrappedValue = false
}
case .error:
Spacer()
Expand Down

0 comments on commit 91289f0

Please sign in to comment.