generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup, Swift 6, Consent Contraint and SignatureView improvements (#60)
# Cleanup, Swift 6, Consent Contraint and SignatureView improvements ## ♻️ Current situation & Problem The repo needed some cleanup and improvements. Similar, the `SignatureView` should be able to be used individually. ## ⚙️ Release Notes - Swift 6 language mode - The `OnboardingDateSource` and `ConsentConstraint` were removed in favor of a way simple export-handeling closure on the `OnboardingConsentView`. - `SignatureView` is now `public` and has a date associated with it (also exported in the PDF) - `OnboardingConsentView` now has proper progress indication for the `action` closure. - General cleanup of the application, as quite some dead code / inconsistencies has been accumulated, especially in the consent export part. ## 📚 Documentation Some doc fixes and improvements. ## ✅ Testing Manual testing and UI tests ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md). --------- Co-authored-by: Philipp Zagar <[email protected]>
- Loading branch information
1 parent
e3b8d50
commit a7cc789
Showing
65 changed files
with
1,238 additions
and
1,378 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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
69 changes: 69 additions & 0 deletions
69
Sources/SpeziOnboarding/Consent/Export/ConsentDocument+Export.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import PDFKit | ||
import PencilKit | ||
import SwiftUI | ||
import TPPDF | ||
|
||
|
||
/// Extension of `ConsentDocument` enabling the export of the signed consent page. | ||
extension ConsentDocument { | ||
/// Creates the export representation of the ``ConsentDocument`` including all necessary content. | ||
var exportRepresentation: ConsentDocumentExportRepresentation { | ||
get async { | ||
#if !os(macOS) | ||
.init( | ||
markdown: await self.markdown(), | ||
signature: signatureImage, | ||
name: self.name, | ||
formattedSignatureDate: self.formattedConsentSignatureDate, | ||
configuration: self.exportConfiguration | ||
) | ||
#else | ||
.init( | ||
markdown: await self.markdown(), | ||
signature: self.signature, | ||
name: self.name, | ||
formattedSignatureDate: self.formattedConsentSignatureDate, | ||
configuration: self.exportConfiguration | ||
) | ||
#endif | ||
} | ||
} | ||
|
||
#if !os(macOS) | ||
private var signatureImage: UIImage { | ||
var updatedDrawing = PKDrawing() | ||
|
||
for stroke in signature.strokes { | ||
// As the `PKDrawing.image()` function automatically converts the ink color dependent on the used color scheme (light or dark mode), | ||
// force the ink used in the `UIImage` of the `PKDrawing` to always be black by adjusting the signature ink according to the color scheme. | ||
let blackStroke = PKStroke( | ||
ink: PKInk(stroke.ink.inkType, color: colorScheme == .light ? .black : .white), | ||
path: stroke.path, | ||
transform: stroke.transform, | ||
mask: stroke.mask | ||
) | ||
|
||
updatedDrawing.strokes.append(blackStroke) | ||
} | ||
|
||
#if os(iOS) | ||
let scale = UIScreen.main.scale | ||
#else | ||
let scale = 3.0 // retina scale is default | ||
#endif | ||
|
||
return updatedDrawing.image( | ||
from: .init(x: 0, y: 0, width: signatureSize.width, height: signatureSize.height), | ||
scale: scale | ||
) | ||
} | ||
#endif | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.