-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add '_spi(TokamakCore)' to ideally internal public members. #386
Conversation
@@ -62,7 +62,8 @@ public struct WindowGroup<Content>: Scene, TitledScene where Content: View { | |||
self.title = Text(title) | |||
self.content = content() | |||
} | |||
|
|||
|
|||
@_spi(TokamakCore) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you apply SwiftFormat as swiftformat .
in the project directory to get rid of trailing whitespaces? You can also install a pre-commit hook as described here, which will apply formatting fixes automatically for you before you commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I had forgotten that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems legit 👍
Is it possible to do the extension View where Body == Never {
@_spi(TokamakCore)
var body: Never { neverBody("\(Self.self)") }
} Then we can just use |
Yes it is. I introduced a /// A `View` that offers primitive functionality, which renders its `body` inaccessible.
public protocol PrimitiveView: View where Body == Never {}
public extension PrimitiveView {
@_spi(BubbleCore)
var body: Never {
neverBody(String(describing: Self.self))
}
}
I added a new protocol instead of a conditional default-implementation on |
I am also in a dilemma when it comes to whether |
I am all for the addition of PrimitiveView. I am doing some experiments where I do some recursion through the view hierarchy and need to have the Never-body views marked by a protocol. I call it BuiltinView inspired by objc.ui Swift Talks. Regarding ViewDeferredToRenderer I was initially confused by that name since I interpreted it to mean Never-body views, whereas it's actually a workaround to supply a body for a never-body view. So I don't think it's actually being deferred to the renderer, but to some other view... |
I'm going to significantly refactor or even get rid of The conflicting conformances isssue and inability to use any renderer other than the test one is pretty severe in my opinion. Most probably the logic currently handled by |
This makes sense to me. |
Excellent - I also think that most uses of Regarding 'package' level access control, have you seen this pitch? https://forums.swift.org/t/pitch-swift-package-access-control/45174 |
Thanks for sharing it, this seems like a good pitch that could help us clean up things a bit! |
Currently, a public type conforming to a public protocol requires that this protocol's witnesses have a public access level. This, though, doesn't mean that the visibility of protocol witnesses is tied to the visibility of that protocol. For instance, the property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
I look forward to using PrimitiveView in my own experiments. :-)
neverBody("Group") | ||
} | ||
} | ||
extension Group: PrimitiveView & View where Content: View {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that it's conforming to both PrimitiveView and View? Is the former not a refinement of the latter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, conditionally conforming a type to a "refining" protocol (such as PrimitiveView
) requires that either that type have separate conditional conformances (i.e. extension Group: View where Content: View {}
and then the PrimitiveView
conformance), or that both conformances be explicitly written (as is done above).
Also, I have no preference as to whether the above is written as PrimitiveView & View
or PrimitiveView, View
; whatever you prefer.
@@ -22,12 +22,23 @@ public protocol View { | |||
} | |||
|
|||
public extension Never { | |||
@_spi(TokamakCore) | |||
var body: Never { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that the body implementation from the PrimitiveView conformance is not good enough?
There probably is, but I'm not at a computer, so I can't try it out right now. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just that a Never
instance can, as the name suggests, never exist. Thus, I thought it would be misleading to use the primitive view conformance. Not to mention that relying on the PrimitiveView
default implementation causes problems with Never
-body scenes (for reasons I don't fully understand).
In my opinion, instance members of no-case enums, like Never
, should non require a body anyway. This behavior is actually in place for functions taking no-case enums, meaning that func a(_: Never) -> Int {}
is perfectly valid.
This PR adds
_spi(TokamakCore)
to the modules:The attribute is applied to:
View
bodies in TokamakCore — either primitive or regular likeColor
ViewDeferredToRenderer
bodiesParentView
children
membersView
modifiers (such as_onMount(perform:)
)Color._withScheme
, and_AnyApp._launch
)The attribute semantics (from my brief testing)
public
declarations@_spi(Module) public enum A {}; public var a: A
is illegal)body
ofText
, but autocompletion hides it).@_spi(Module)
, a client has to write@_spi(Module) import Library
in order to normally access such SPI declarations.