liveview-native / liveview-client-swiftui

MIT License
349 stars 30 forks source link

Support passing view references in `AnyShape` implementation #1326

Open BrooklinJazz opened 2 months ago

BrooklinJazz commented 2 months ago

To convert the following SwiftUI example into the LVN DSL

Image("turtlerock")
  .clipShape(Circle())

I wanted to pass a Circle view to the clipShape modifier using the template attribute like so:

Template

<Image class="image" name="turtlerock">
    <Circle template="example"/>
</Image>

Stylesheet

defmodule LvnWorkshopWeb.Styles.SwiftUI do
  use LiveViewNative.Stylesheet, :swiftui

  ~SHEET"""
  "image" do
    clipShape(shape: :example)
  end
  """
end

However @carson-katri informed me we don't support that syntax, and only support the list of standard shapes: https://developer.apple.com/documentation/swiftui/shape

So we can convert the following syntax into the LVN DSL:

Image("turtlerock")
  .clipShape(.circle)

But not the original syntax used in the example:

Image("turtlerock")
  .clipShape(Circle())
carson-katri commented 2 months ago

This issue should be moved to the SwiftUI client

bcardarella commented 2 months ago

@carson-katri is it possible through the Registry to add support for these on an ad-hoc basis? So if a dev wanted to add support for a non-standard shape in this case they can still do so?

carson-katri commented 2 months ago

Currently there is no way to add custom shapes that can be passed to existing modifiers through the registry. You can create your own modifier that uses your custom shape though.

bcardarella commented 2 months ago

ok, I'd like to explore this in the future but we can go with the work around for now.

AZholtkevych commented 2 months ago

Added to backlog