feat: Build CareKit for macOS and visionOS#716
feat: Build CareKit for macOS and visionOS#716cbaker6 wants to merge 37 commits intocarekit-apple:mainfrom
Conversation
| #endif | ||
| } | ||
|
|
||
| private func rowValueOfIndexPath(_ indexPath: IndexPath) -> Int { |
There was a problem hiding this comment.
Added this method because iOS and macOS use row/item respectively
| // First make sure there is no matching event already stored in the data structure. | ||
| let indexPath = self.indexPath(of: event) | ||
| guard indexPath == nil else { return (self[indexPath!.section][indexPath!.row], false) } | ||
| guard indexPath == nil else { |
There was a problem hiding this comment.
See comment below about row/item is handled for how iOS/macOS
| } | ||
|
|
||
| #if os(macOS) | ||
| func checkStoreProtection(_ protection: FileProtectionType) throws { |
There was a problem hiding this comment.
This test is currently needed for macOS because macOS is the only one that reports these attributes directly on the file.
| RoundedRectangle(cornerRadius: style.appearance.cornerRadius2, style: .continuous) | ||
| } | ||
|
|
||
| private var foregroundColor: Color { |
There was a problem hiding this comment.
A helper computed property to help handle SwiftUI and UIKit types.
| #if !os(macOS) | ||
| return isComplete ? Color.accentColor : Color(style.color.clear) | ||
| #else | ||
| return isComplete ? Color.accentColor : style.color.clear |
There was a problem hiding this comment.
Needed to modify this helper computed property to help handle SwiftUI and UIKit types.
| #if !os(macOS) | ||
| return isComplete ? .init(style.color.tertiaryCustomFill) : .accentColor | ||
| #else | ||
| return isComplete ? style.color.tertiaryCustomFill : .accentColor |
There was a problem hiding this comment.
Needed to modify this helper computed property to help handle SwiftUI and UIKit types.
|
|
||
| #else | ||
|
|
||
| return 1 |
There was a problem hiding this comment.
This scale value may not be correct, made this change because I could only find UIFontMetrics in UIKit, let me know if you have an improvement on this.
|
|
||
| #elseif os(macOS) | ||
|
|
||
| var secondaryCustomGroupedBackground: Color { get } |
There was a problem hiding this comment.
Using SwiftUI Color directly for macOS
|
|
||
| #elseif os(macOS) | ||
|
|
||
| var secondaryCustomGroupedBackground: Color { .white } |
There was a problem hiding this comment.
I chose .white for this and tertiaryCustomFill, let me know if you think a better color should be used for macOS
|
|
||
| #if os(iOS) || os(visionOS) || os(watchOS) | ||
|
|
||
| var white: UIColor { .white } |
There was a problem hiding this comment.
Every supported OS except for macOS will use UIKit for these colors
| private let completionButtonTextPadding: CGFloat = 14 | ||
| #elseif os(watchOS) | ||
| #else | ||
| private let completionButtonTextPadding: CGFloat = 8 |
There was a problem hiding this comment.
I made every OS other than iOS use this padding value, let me know if we should update it to be more specific.
| } | ||
| } | ||
|
|
||
| func webView(withURL url: URL, link: LinkItem) -> some View { |
There was a problem hiding this comment.
Created this method because some of the OS's don't support UIKit for SafariView or it didn't work properly (visionOS using Canvas). Let me know if you have an improvement here.
| func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController { | ||
| let config = SFSafariViewController.Configuration() | ||
| #if !os(visionOS) | ||
| config.barCollapsingEnabled = true |
There was a problem hiding this comment.
Not available on visionOS
|
|
||
| private func updateFileProtectionPathAtURL(_ url: URL) throws { | ||
|
|
||
| #if os(macOS) |
There was a problem hiding this comment.
Currently only needed for macOS, but this method calls through just incase it's needed for other OS's later
| descriptor.type = NSSQLiteStoreType | ||
| descriptor.shouldAddStoreAsynchronously = false | ||
| #if !os(macOS) | ||
| descriptor.setOption(storeType.securityClass as NSObject, forKey: NSPersistentStoreFileProtectionKey) |
There was a problem hiding this comment.
Handling macOS and a later call below
| XCTAssertEqual(outcomeValues.count, 2) | ||
| XCTAssertEqual(outcomeValues.first?.doubleValue, 70) | ||
| #if !os(macOS) && !os(visionOS) | ||
| XCTAssertEqual(outcomeValues[safe: 1]?.doubleValue, 80) |
There was a problem hiding this comment.
macOS and visionOS don't like safe
Removed the 'testRepetitionMode' property from the test plan.
|
@gavirawson-apple this PR has the latest updates and is ready for review |
CareKitUI currently can't be built for macOS due to its use of UIKit. In addition, the whole framework currently doesn't build for visionOS. Close #515. Tracking the build across all OS's can be seen here: cbaker6#14 along with more details about the PR.
The following items are completed:
CareKitUIto build for macOS similar to watchOS by allowing SwiftUI based CareKit viewsCareStoreandCareKitto build for macOSCareKitframeworks to build for visionOSNote
#if !os(watchOS) && !os(macOS) && !os(visionOS)