TokamakUI / Tokamak

SwiftUI-compatible framework for building browser apps with WebAssembly and native apps for other platforms
Apache License 2.0
2.62k stars 111 forks source link

Add `_ShapeView` and `background` modifiers support to Fiber renderers #491

Closed carson-katri closed 2 years ago

carson-katri commented 2 years ago

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.

MaxDesiatov commented 2 years ago

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 commented 2 years ago

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.

MaxDesiatov commented 2 years ago

snapshot tests are failing though