Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add _ShapeView and background modifiers support to Fiber renderers #491

Merged
merged 68 commits into from
Jun 15, 2022

Conversation

carson-katri
Copy link
Member

@carson-katri carson-katri commented May 29, 2022

This adds support for _ShapeView and related styling, as well as the various background modifiers to the Fiber renderers:

Screen Shot 2022-05-29 at 4 55 32 PM

HStack {
    Text("Hello")
        .font(.largeTitle)
        .bold()
        .foregroundStyle(.white)
        .background(LinearGradient(colors: [.blue, .green], startPoint: .leading, endPoint: .trailing))
    Text("World")
        .font(.largeTitle)
        .bold()
        .foregroundStyle(.white)
        .background(LinearGradient(colors: [.red, .purple], startPoint: .leading, endPoint: .trailing))
}

Overriding View Bodies

It also introduces the capability to override the body of a View in a specific Fiber renderer using the visitPrimitiveChildren protocol requirement on FiberRenderer:

func visitPrimitiveChildren<Primitive, Visitor>(
  _ view: Primitive
) -> ViewVisitorF<Visitor>? where Primitive: View, Visitor: ViewVisitor

In this function, we can optionally return a new function that will override the default _visitChildren function on the View.

carson-katri and others added 30 commits February 6, 2022 13:57
@carson-katri carson-katri changed the base branch from main to fiber/layout May 29, 2022 20:59
@carson-katri carson-katri added SwiftUI compatibility Tokamak API differences with SwiftUI DOM/HTML renderer Tokamak in the browser labels May 29, 2022
@@ -183,3 +223,54 @@ extension _ShapeView: _HTMLPrimitive {
}
}
}

@_spi(TokamakStaticHTML) extension _ShapeView: HTMLConvertible {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: let's keep declaration attributes consistently on a separate line

Suggested change
@_spi(TokamakStaticHTML) extension _ShapeView: HTMLConvertible {
@_spi(TokamakStaticHTML)
extension _ShapeView: HTMLConvertible {

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented May 30, 2022

Is visitPrimitiveChildren supposed to be a replacement for Deferred infrastructure of the stack reconciler, or is this a different thing with a different use case?

@carson-katri
Copy link
Member Author

Yes, exactly. Its the equivalent to primitiveBody(for:) in a StackReconciler renderer, except we provide a view visitor function instead of an AnyView so the Views keep their types.

Base automatically changed from fiber/layout to main May 30, 2022 19:49
@carson-katri carson-katri added the Fiber Changes related to the FiberReconciler or a FiberRenderer label Jun 4, 2022
MaxDesiatov
MaxDesiatov previously approved these changes Jun 6, 2022
Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Small formatting nits, otherwise seems legit 👍

@MaxDesiatov
Copy link
Collaborator

snapshot tests are failing though

@carson-katri carson-katri requested a review from MaxDesiatov June 15, 2022 14:14
@carson-katri carson-katri enabled auto-merge (squash) June 15, 2022 14:14
Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Seems legit, thanks!

@carson-katri carson-katri merged commit c935744 into main Jun 15, 2022
@carson-katri carson-katri deleted the fiber/shapeview branch June 15, 2022 14:33
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
DOM/HTML renderer Tokamak in the browser Fiber Changes related to the FiberReconciler or a FiberRenderer SwiftUI compatibility Tokamak API differences with SwiftUI
Development

Successfully merging this pull request may close these issues.

2 participants