Skip to content

Add basic SwiftUI Support#56

Merged
benpious merged 3 commits intomasterfrom
swiftui-support
Jun 25, 2019
Merged

Add basic SwiftUI Support#56
benpious merged 3 commits intomasterfrom
swiftui-support

Conversation

@benpious
Copy link
Copy Markdown
Collaborator

As the title. See the comments for details on what this entails and what parts can use more work.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 12, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@benpious benpious requested review from elsh, reidmain and rudro June 12, 2019 20:40
Comment thread Cyborg/SwiftUIView.swift
self.drawable = drawable
}

public func makeUIView(context: UIViewRepresentableContext<VectorDrawableView>) -> VectorView {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

shouldn't there be a body function for swiftui?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, this isn't a View. It's a UIViewRepresentable.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay technically this is a View. But its Body is already specified as Never in UIKitRepresentable, which is a subtype of View.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wait really? UIViewRepresentable is a View as well so it can have all of the standard modifiers applied to it?

developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I assume this is some sort of Xcode 11 artifact?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think so. I didn't add it deliberately.

Comment thread Cyborg/SwiftUIView.swift
}

/// The key for Vector Drawable themes.
public struct ThemeKey: EnvironmentKey {
Copy link
Copy Markdown

@reidmain reidmain Jun 19, 2019

Choose a reason for hiding this comment

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

Having watched a couple more WWDC videos on SwiftUI do think it is worthwhile to create your own Theme environment variable? Could we use the \.colorScheme key and accentColor modifier instead? Or I guess add our own accentColor method to make it feel like a first class citizen?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

How would that work?

ColorScheme limits us in terms of what colors we can read (I don't think we can even get system colors from it).

accentColor only seems to work as a tint, and we need to support arbitrary colors.

I agree that this is kind of bad, but I don't see any other options.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In my mind to be a first class citizen of SwiftUI modifiers like foregroundColor, tintColor, etc should work for a custom view. Requiring custom environment values for a single custom view seems heavy handed. If you had half a dozen custom views that all required unique environment variables to style them I can't see that being enjoyable. Also if we wanted to create another custom view in a different open source repository that also had a theme we'd have to make these repos dependent on one another which isn't ideal.

If there is no way know if a modifier has been applied to your custom view I would think that implementing the modifiers would be the next step. If a modifier is called you then store the values locally and use it to update the look of your custom view.

With respect to dark mode I will admit I don't have first hand experience but I read that Apple allows you to define a color set for normal mode as well as dark mode and that we would expect developers to leverage this and our custom views should also work in this system and not require developers to do any extra work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think you can get the environment values out of SwiftUI in a form that you can put into UIKit. If you print the contents of EnvironmentValues, there's a bunch of private types that are used as keys.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Boooooo what kind of 1.0 is this 🍎?

@benpious benpious merged commit abe0914 into master Jun 25, 2019
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.

5 participants