liveview-native / liveview-client-swiftui

MIT License
349 stars 29 forks source link

Add `_observeTextReference` to update modifiers with `TextReference` types #1383

Open carson-katri opened 5 days ago

carson-katri commented 5 days ago

Closes #1380

The _observeTextReference modifier tracks changed to the element associated with a TextReference type. In the content block, modifiers that use the referenced Text element can be applied. They will now properly update their contents in response to changes from the server.

In this example, the navigationTitle and badge modifiers use TextReference types, and update when the count changes.

<List style="navigationTitle(:title)">
    <Button phx-click="increment" style='badge(:badge)'>
        Increment

        <Text template="badge">
            <%= @count %>
        </Text>
    </Button>

    <Text template="title">
        <%= @count %>
    </Text>
</List>

https://github.com/liveview-native/liveview-client-swiftui/assets/13581484/73c87981-7507-42a7-921c-dfccf44e8054