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

SwiftUI sample #398

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

kutakmir
Copy link

This is the first step towards resolving some of the SwiftUI-related issues that many of us have and to showcase the compatibility of CareKit with SwiftUI.

Here I only rewrote the existing sample.

@ericlewis
Copy link
Contributor

Great work! I look forward to seeing this fleshed out more perhaps with more SwiftUI proper examples perhaps, maybe even a catalog for SwiftUI examples.

@gavirawson-apple
Copy link
Collaborator

Thank you for this contribution @kutakmir! There are some great examples in here for CareKit SwiftUI adapters.

It seems like this work will be well suited as an example for others who want to use SwiftUI with CareKit. It's probably best that we don't merge this into master given that it is such a targeted example. But what are your thoughts on these two options:

  1. Extracting pieces of this work to put into our Readme in the SwiftUI section. If we go this route, it will probably be most helpful to provide examples of CareKit views and synchronized view controllers adapted for SwiftUI (for example, an OCKSimpleTaskView and an OCKSimpleTaskViewController).

  2. Use this as a starting point for a SwiftUI branch, where we host examples of adapting CareKit views and view controllers for SwiftUI.

Let us know which route will be most helpful for you and the community!

@kutakmir
Copy link
Author

@gavirawson-apple wouldn't it be better in the master branch though? I'll go ahead and start implementing the catalog as @ericlewis suggested. The most helpful for the community would be to have a set of real-world examples and best practices on how to use CareKit in a SwiftUI app. SwiftUI is the future, heavily promoted by Apple, so I don't see a reason why not to include it in the master branch as it is one of the hot topics in the CareKit issues on GitHub. @gavirawson-apple if you don't allow to merge the SwiftUI target to the master branch, then let's go the separate branch route so that devs immediately have the code to play with.

@ericlewis I saw your comments in: #394. What is the status of your wrappers? Shall we sync up to collaborate on this feature?

@ericlewis
Copy link
Contributor

ericlewis commented Mar 30, 2020

@kutakmir would love to sync up, I have been working on something more along these lines: https://github.com/ericlewis/CKUI/blob/master/CKUI/ContentView.swift

I am considering that implementing the UI as pure SwiftUI would be the easier move, and wanted to create more idiomatic SwiftUI-ish wrappers around the controllers for easy of use.

Eventually there will be a SimpleTaskView component that basically works as the sync versions of the view controllers. still WIP

@kutakmir
Copy link
Author

I see. Writing pure SwiftUI has many benefits. @gavirawson-apple what is the Apple's strategy regarding SwiftUI?

@gavirawson-apple
Copy link
Collaborator

gavirawson-apple commented Mar 31, 2020

SwiftUI is definitely a powerful tool, and something we are thinking of supporting in the future. However, at the moment all of our views are written using UIKit. Using tools like UIViewRepresentable and UIViewControllerRepresentable are definitely the correct approach for adapting the views for SwiftUI. But, as you have probably encountered, they do come along with some tradeoffs and occasional layout issues. For that reason, it is probably best if we showcase our UIKit views as UIKit views.

@ericlewis's approach of rebuilding the views in SwiftUI will be a good route going forward. While the views will need to be recreated from scratch, our controllers are equipped and ready for SwiftUI. The general approach is outlined here. If you're up for the work, you might want to consider creating a SwiftUI catalog running parallel to our UIKit catalog.

@kutakmir
Copy link
Author

kutakmir commented Apr 2, 2020

@gavirawson-apple If tools like UIViewRepresentable and UIViewControllerRepresentable are definitely the correct approach for adapting CK views to SwiftUI, would you guys consider the effort to create a SwiftUI-based sample app useful and worthwhile at this stage?
It could be used to showcase the various CK views adapted to SwiftUI.
Do you foresee the tradeoffs and occasional layout issues to become show-stoppers for such an effort?
The initial chart animation is broken to name one example. Is it safe to assume it will be fixed in a new edition of the SwiftUI framework?
What is your guidance?

@gavirawson-apple
Copy link
Collaborator

gavirawson-apple commented Apr 7, 2020

To clarify, I think it will be useful to have a section in the catalog app that showcases pure SwiftUI views built from scratch. Building out the views in SwiftUI will help solve any layout issues you have encountered. Showcasing the UIKit views using SwiftUI adapters is probably less useful, given that the process is generally the same for all of the views (using UIViewControllerRepresentable/UIViewRepresentable).

Copy link
Collaborator

@gavirawson-apple gavirawson-apple left a comment

Choose a reason for hiding this comment

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

Thank you for this hard work! As I mentioned before, it will be most useful to provide examples of CareKit views rewritten in SwiftUI. Those can be best showcased inside of a new tab in OCKCatalog (not within a copy of the target).

See this PR for a new SwiftUI API around the InstructionsTaskView. Also check out our updated README with info on SwiftUI in CareKit and SwiftUI in CareKitUI. The API is a starting point to demonstrate the SwiftUI API architecture. We would love to integrate community contributions that follow the API structure!

@gharary
Copy link

gharary commented Apr 29, 2021

Hi,
As you are working on providing a swiftui sample, I would like to ask for a sample in Charts for SwiftUI too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants