generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ImageReference, ManagedViewUpdate, CaseIterablePicker and Tiles (#45
) # Add ImageReference, ManagedViewUpdate, CaseIterablePicker and Tiles ## ♻️ Current situation & Problem This PR moves some infrastructure from other Spezi packages to SpeziViews (this includes SpeziScheduler, NAMS and SpeziDevices). ## ⚙️ Release Notes * Added `ImageReference` as a way to pass around image resources including system image names. * Added `ManagedViewUpdate` as a mechanism to manually trigger view updates include based on dates * Added `SimpleTile` and `TileHeader` as new layout components. * Adde new `CaseIterablePicker`. * `ListRow` is now using [`LabeledContent`](https://developer.apple.com/documentation/swiftui/labeledcontent/) under the hood. Additionally, `LabeledContent` received some convenience initializers. ## 📚 Documentation Reorganized some of the sections of the documentation catalog. ## ✅ Testing Added snapshot testing for the new layout components. We added an UI test to verify the behavior of `@ManagedViewUpdate`. ## 📝 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).
- Loading branch information
Showing
60 changed files
with
1,603 additions
and
166 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
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
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
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
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
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
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,91 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Reference an Image Resource. | ||
public enum ImageReference { | ||
/// Provides the system name for an image. | ||
case system(String) | ||
/// Reference an image from the asset catalog of a bundle. | ||
case asset(String, bundle: Bundle? = nil) | ||
|
||
|
||
/// A system image is referenced. | ||
public var isSystemImage: Bool { | ||
if case .system = self { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} | ||
|
||
|
||
extension ImageReference { | ||
/// Retrieve Image. | ||
/// | ||
/// Returns `nil` if the image resource could not be located. | ||
public var image: Image? { | ||
switch self { | ||
case let .system(name): | ||
return Image(systemName: name) | ||
case let .asset(name, bundle: bundle): | ||
#if canImport(UIKit) | ||
// also available on watchOS | ||
guard UIImage(named: name, in: bundle, with: nil) != nil else { | ||
return nil | ||
} | ||
#elseif canImport(AppKit) | ||
guard NSImage(named: name) != nil else { | ||
return nil | ||
} | ||
#endif | ||
return Image(name, bundle: bundle) | ||
} | ||
} | ||
|
||
#if canImport(UIKit) // also available on watchOS | ||
/// Retrieve an UIImage. | ||
/// | ||
/// Returns `nil` if the image resource could not be located. | ||
public var uiImage: UIImage? { | ||
switch self { | ||
case let .system(name): | ||
UIImage(systemName: name) | ||
case let .asset(name, bundle): | ||
UIImage(named: name, in: bundle, with: nil) | ||
} | ||
} | ||
|
||
#if canImport(WatchKit) | ||
/// Retrieve a WKImage. | ||
/// | ||
/// Returns `nil` if the image resource could not be located. | ||
public var wkImage: WKImage? { | ||
uiImage.map { WKImage(image: $0) } | ||
} | ||
#endif | ||
#elseif canImport(AppKit) | ||
/// Retrieve a NSImage. | ||
/// | ||
/// Returns `nil` if the image resource could not be located. | ||
public var nsImage: NSImage? { | ||
switch self { | ||
case let .system(name): | ||
NSImage(systemSymbolName: name, accessibilityDescription: nil) | ||
case let .asset(name, _): | ||
NSImage(named: name) | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
|
||
extension ImageReference: Hashable, Sendable {} |
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.