Closed bcardarella closed 9 months ago
Using the ACCEPT header with text/swiftui
content-type gives us the root layout rendering because that is always a DeadView render. The following setup is necessary:
# config.exs
config :mime, :types, %{
"text/swiftui" => ["swiftui"]
}
# router.ex
# note the :accepts and :put_root_layout plugs
pipeline :browser do
plug :accepts, ["html", "json", "swiftui"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {LvnDemo3Web.Layouts, :root}, swiftui: {LvnDemo3Web.Layouts, :root_swiftui}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
# layouts.ex
embed_templates "layouts/*.html"
embed_templates "layouts/*.swiftui", suffix: "_swiftui"
I still don't know yet if we will require the LiveViewNative.SessionPlug
any longer. That plug provides the format, layouts, and LiveReload functionality. The upstream PR in LV covers all of this except LiveReload and that is only not rendering out because of a constraint against the HTML content-type: https://github.com/phoenixframework/phoenix_live_reload/blob/main/lib/phoenix_live_reload/live_reloader.ex#L154
now the file root.swiftui.heex
can be added to layouts/
. Because the root layout is a DeadView render only I advocate for not putting any actual application views in there and believe it should be limited to just:
<meta name="csrf-token" content={get_csrf_token()} />
<%= @inner_content %>
Because the root layout is a DeadView render only I advocate for not putting any actual application views in there
You need to put the navigation structure in the root layout so that it exists outside of the LiveView. This could be a NavigationStack
, NavigationSplitView
, TabView
, etc.
@carson-katri and I discussed in Slack. There are few catches when it comes to the navigation views and why just merging the ViewTree on top of it may break things.
The plan right now is to recommend Navigation views be put into the root
template as that is currently working. Once v0.2 is released and we're in development cycle for v0.3 we'll try to implement a method that would allow for nav views to be put into the app layout and some intelligence on the client about how to pop content out
Blocked by upstream changes
This has been completed with https://github.com/liveview-native/live_view_native/commit/17d246342c8254b5011a17b3248012e94b501ad3
If https://github.com/phoenixframework/phoenix_live_view/pull/2962 is accepted then the following changes will need to be done to the client:
text/swiftui
ACCEPT header should be used instead of a query param?_phoenix_format=swiftui
will be usedSo all of the
<!-- ... -->
elements should be ignored in the client if they aren't already