Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optional confirmation on docv #228

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## 10.2.9

### Added
* Document capture cleanup and optionally showing confirmation and returning the captured image if false

## 10.2.8

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- Sentry (8.32.0):
- Sentry/Core (= 8.32.0)
- Sentry/Core (8.32.0)
- SmileID (10.2.8):
- SmileID (10.2.9):
- lottie-ios (~> 4.4.2)
- ZIPFoundation (~> 0.9)
- SwiftLint (0.55.1)
Expand Down Expand Up @@ -43,7 +43,7 @@ SPEC CHECKSUMS:
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
Sentry: 96ae1dcdf01a644bc3a3b1dc279cecaf48a833fb
SmileID: 8d3a64e845a5fb82239516def978391d4d814c9e
SmileID: cbeaf5142f11cea7a4778d7c000fa9b766c4afa2
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c

Expand Down
4 changes: 2 additions & 2 deletions SmileID.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = 'SmileID'
s.version = '10.2.8'
s.version = '10.2.9'
s.summary = 'The Official Smile Identity iOS SDK.'
s.homepage = 'https://docs.usesmileid.com/integration-options/mobile/ios-v10-beta'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Japhet' => '[email protected]', 'Juma Allan' => '[email protected]', 'Vansh Gandhi' => '[email protected]'}
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.7" }
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.9" }
s.ios.deployment_target = '13.0'
s.dependency 'ZIPFoundation', '~> 0.9'
s.dependency 'lottie-ios', '~> 4.4.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct DocumentCaptureScreen: View {
let instructionsSubtitleText: String
let captureTitleText: String
let knownIdAspectRatio: Double?
let showConfirmation: Bool
let onConfirm: (Data) -> Void
let onError: (Error) -> Void
let onSkip: () -> Void
Expand All @@ -28,6 +29,7 @@ public struct DocumentCaptureScreen: View {
instructionsSubtitleText: String,
captureTitleText: String,
knownIdAspectRatio: Double?,
showConfirmation: Bool = true,
onConfirm: @escaping (Data) -> Void,
onError: @escaping (Error) -> Void,
onSkip: @escaping () -> Void = {}
Expand All @@ -42,73 +44,98 @@ public struct DocumentCaptureScreen: View {
self.instructionsSubtitleText = instructionsSubtitleText
self.captureTitleText = captureTitleText
self.knownIdAspectRatio = knownIdAspectRatio
self.showConfirmation = showConfirmation
self.onConfirm = onConfirm
self.onError = onError
self.onSkip = onSkip
viewModel = DocumentCaptureViewModel(knownAspectRatio: knownIdAspectRatio)
}

public var body: some View {
if let captureError = viewModel.captureError {
let _ = onError(captureError)
} else if showInstructions, !viewModel.acknowledgedInstructions {
DocumentCaptureInstructionsScreen(
heroImage: instructionsHeroImage,
title: instructionsTitleText,
subtitle: instructionsSubtitleText,
showAttribution: showAttribution,
allowPhotoFromGallery: allowGallerySelection,
showSkipButton: showSkipButton,
onSkip: onSkip,
onInstructionsAcknowledgedSelectFromGallery: viewModel.onGalleryClick,
onInstructionsAcknowledgedTakePhoto: viewModel.onTakePhotoClick
)
.sheet(isPresented: $viewModel.showPhotoPicker) {
ImagePicker(onImageSelected: viewModel.onPhotoSelectedFromGallery)
ZStack {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Thanks for refactoring this. It's more readable this way.

if let captureError = viewModel.captureError {
errorView(error: captureError)
} else if showInstructions && !viewModel.acknowledgedInstructions {
instructionsView
} else if let imageToConfirm = viewModel.documentImageToConfirm {
confirmationView(imageToConfirm: imageToConfirm)
} else {
captureView
}
} else if let imageToConfirm = viewModel.documentImageToConfirm {
ImageCaptureConfirmationDialog(
title: SmileIDResourcesHelper.localizedString(for: "Document.Confirmation.Header"),
subtitle: SmileIDResourcesHelper.localizedString(
for: "Document.Confirmation.Callout"
),
image: UIImage(data: imageToConfirm) ?? UIImage(),
confirmationButtonText: SmileIDResourcesHelper.localizedString(
for: "Document.Confirmation.Accept"
),
onConfirm: { onConfirm(imageToConfirm) },
retakeButtonText: SmileIDResourcesHelper.localizedString(
for: "Document.Confirmation.Decline"
),
onRetake: viewModel.onRetry,
scaleFactor: 1.0
)
} else {
CaptureScreenContent(
title: captureTitleText,
subtitle: SmileIDResourcesHelper.localizedString(for: viewModel.directive.rawValue),
idAspectRatio: viewModel.idAspectRatio,
areEdgesDetected: viewModel.areEdgesDetected,
showCaptureInProgress: viewModel.isCapturing,
showManualCaptureButton: viewModel.showManualCaptureButton,
cameraManager: viewModel.cameraManager,
onCaptureClick: viewModel.captureDocument
)
.alert(item: $viewModel.unauthorizedAlert) { alert in
Alert(
title: Text(alert.title),
message: Text(alert.message ?? ""),
primaryButton: .default(
Text(SmileIDResourcesHelper.localizedString(for: "Camera.Unauthorized.PrimaryAction")),
action: {
viewModel.openSettings()
}
}
}

private var instructionsView: some View {
DocumentCaptureInstructionsScreen(
heroImage: instructionsHeroImage,
title: instructionsTitleText,
subtitle: instructionsSubtitleText,
showAttribution: showAttribution,
allowPhotoFromGallery: allowGallerySelection,
showSkipButton: showSkipButton,
onSkip: onSkip,
onInstructionsAcknowledgedSelectFromGallery: viewModel.onGalleryClick,
onInstructionsAcknowledgedTakePhoto: viewModel.onTakePhotoClick
)
.sheet(isPresented: $viewModel.showPhotoPicker) {
ImagePicker(onImageSelected: viewModel.onPhotoSelectedFromGallery)
}
}

private func errorView(error: Error) -> some View {
Color.clear.onAppear { onError(error) }
}

private func confirmationView(imageToConfirm: Data) -> some View {
Group {
if showConfirmation {
ImageCaptureConfirmationDialog(
title: SmileIDResourcesHelper.localizedString(for: "Document.Confirmation.Header"),
subtitle: SmileIDResourcesHelper.localizedString(
for: "Document.Confirmation.Callout"
),
image: UIImage(data: imageToConfirm) ?? UIImage(),
confirmationButtonText: SmileIDResourcesHelper.localizedString(
for: "Document.Confirmation.Accept"
),
onConfirm: { onConfirm(imageToConfirm) },
retakeButtonText: SmileIDResourcesHelper.localizedString(
for: "Document.Confirmation.Decline"
),
secondaryButton: .cancel()
onRetake: viewModel.onRetry,
scaleFactor: 1.0
)
} else {
Color.clear.onAppear { onConfirm(imageToConfirm) }
}
}
}

private var captureView: some View {
CaptureScreenContent(
title: captureTitleText,
subtitle: SmileIDResourcesHelper.localizedString(for: viewModel.directive.rawValue),
idAspectRatio: viewModel.idAspectRatio,
areEdgesDetected: viewModel.areEdgesDetected,
showCaptureInProgress: viewModel.isCapturing,
showManualCaptureButton: viewModel.showManualCaptureButton,
cameraManager: viewModel.cameraManager,
onCaptureClick: viewModel.captureDocument
)
.alert(item: $viewModel.unauthorizedAlert) { alert in
Alert(
title: Text(alert.title),
message: Text(alert.message ?? ""),
primaryButton: .default(
Text(SmileIDResourcesHelper.localizedString(for: "Camera.Unauthorized.PrimaryAction")),
action: {
viewModel.openSettings()
}
),
secondaryButton: .cancel()
)
}
}
}

struct CaptureScreenContent: View {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SmileID/Classes/SmileID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
import UIKit

public class SmileID {
public static let version = "10.2.8"
public static let version = "10.2.9"
@Injected var injectedApi: SmileIDServiceable
public static var configuration: Config { config }

Expand Down
Loading