Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

docs: add welcome documentation #235

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule MyAppWeb.HelloLive do
use MyAppNative, :live_view
end

# liv/my_app_web/live/hello_live_swiftui.ex
# lib/my_app_web/live/hello_live_swiftui.ex
defmodule MyAppWeb.HelloLive.SwiftUI do
use MyAppNative, [:render_component, format: :swiftui]

Expand Down
1 change: 1 addition & 0 deletions guides/getting-started/setting-up-liveview-native.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Setting Up LiveView Native
145 changes: 145 additions & 0 deletions guides/introduction/welcome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Welcome

Welcome to the LiveView Native documentation. LiveView Native is a platform built on
[Phoenix LiveView](https://github.com/phoenixframework/phoenix_live_view) designed for
building native applications. A general overview of LiveView Native and its benefits
[can be seen in our README](https://github.com/live_view_native/live_view_native).

## What is LiveView Native?

LiveView Native is an extention of Phoenix LiveView, designed to serve
platform-specific server-rendered markup to a variety of supported clients.

Since LiveView Native is built on Phoenix LiveView, LiveView Native inherits all
the same rendering benefits of Phoenix LiveView while maintaining a familiar developer
experience – making it a good pick for both your new and existing LiveView servers.

To begin with LiveView Native, a basic understanding of Elixir and Phoenix LiveView
is recommended. [You can find the documentation for Phoenix LiveView here](https://hexdocs.pm/phoenix_live_view/welcome.html).

## How does LiveView Native work?

To understand the fundementals of LiveView Native, it is important to analyze LiveView Native
and its relationship to Phoenix LiveView and LiveView Native's markup processors.

### Querying

Unlike Phoenix LiveView, when a client makes a request to a LiveView Native route, the route expects additional query
parameters to be provided to denote platform-specific information from the client. This information is what allows
LiveView Native to delegate the request to the appropriate markup processor, and
maintain support with Phoenix LiveView.

The query parameters are as follows.

| Query Parameter | Arguments | Required? | Description |
|-----------------|--------------------------|-----------|--------------------------------------------------------|
| `_format` | swiftui, jetpack, html | ✅ | The content type to be processed by LiveView Native |
| `_interface` | mobile, watch, tv | | The general device type |

This is formatted as `/?_format=xx&_interface=xx`, and when no query parameters are provided,
will default to the corresponding Phoenix LiveView route (presuming a route is provided).
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI that we're looking at moving over to headers instead of query params. The QPs I think will continue to work as a fallback.

Copy link
Contributor

Choose a reason for hiding this comment

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

That change won't take place until 0.5.0 if it does at all


### Processing

Once a request is sucessfully delegated by LiveView Native, it will attempt to match on your LiveView route.

By design, LiveView Native does not ship with a client, and instead seperates
itself into a series of distinct packages. Each package ships with its own modifiers to handle its respective client,
and unlike many framework agnostic development frameworks, intentionally seperates your markup by platform.

Copy link
Contributor

@bcardarella bcardarella Mar 12, 2025

Choose a reason for hiding this comment

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

I think this is a good opportunity to show a matrix of the clients:

platform client ready?
Apple liveview-client-swiftui
Android liveview-client-jetpack

We can expand on this in the future, for example when we add WinUI3. There is a Flutter client out there but I don't know the status of it (it's not built by us) and we have a semi-implemented Ice client.

Copy link
Author

Choose a reason for hiding this comment

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

for sure ill add it here :))

This is to maintain instant feature parity with your platform(s) of choice, as LiveView Native is not concerned with
a cross-platform abstraction layer (or an application bridge). This allows LiveView Native and its corresponding markup processor
to send back a UI representation of your application.

So long as your client supports the underlying markup sent back, it will render!

> #### Note {: .warning}
> Similar to Phoenix LiveView, LiveView Native follows secure best practices and will only send back markup.
> LiveView Native will never send back remote executable code.

Let's see an example.

```elixir
# This entry point to your LiveView, which can handle events from any platform
# lib/my_app_web/live/hello_live.ex
defmodule MyAppWeb.HelloLive do
use MyAppWeb, :live_view
use MyAppNative, :live_view

def mount(_params, _session, socket) do
{:ok, socket}
end
end

# This module will be called on if the format is :swift_ui
# lib/my_app_web/live/hello_live_swiftui.ex
defmodule MyAppWeb.HelloLive.SwiftUI do
use MyAppNative, :live_view

# Within formats, you can target sub-platforms, offering versatility in your views
def render(assigns, %{"target" => "watchos"}) do
~LVN"""
<VStack>
<Text>
Hello WatchOS!
</Text>
</VStack>
"""
end

def render(assigns, _interface) do
~LVN"""
<VStack>
<Text>
Hello SwiftUI!
</Text>
</VStack>
"""
end
end

# This module will be called on if the format is :jetpack
# lib/my_app_web/live/hello_live_jetpack.ex
defmodule MyAppWeb.HelloLive.Jetpack do
use MyAppNative, :live_view

def render(assigns, _interface) do
~LVN"""
<Text>Hello Jetpack Compose!</Text>
"""
end
end
```

The modules above show a distinct path to each format handled by its respective markup processor.
We start in our Phoenix LiveView, which handles our mount and event handling. From there, LiveView Native
delegates the request to our markup modules, which handle our rendering. We use the `~LVN` sigil to define a
NEEx template, which stands for Native+EEx. They are nearly identical to HEEx templates, but used to denote
Copy link
Contributor

Choose a reason for hiding this comment

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

I have been intending to write a section on how NEEx differs from HEEx. If you want to tackle that I can help. It should go in LiveViewNative.Component and probably add a new section to the sigil_LVN macro documentation: https://github.com/liveview-native/live_view_native/blob/main/lib/live_view_native/component.ex#L190

Right now the only differences from HEEx:

  • tag name casing is preserved, so we can emit <Text> and not have it downcased to <text>
  • We don't permit boolean attributes, for example <text on> would mean on is true in HTML. And the lack of that attribute would be presumed to be false. In NEEx we cannot make that presumption because there are times in the upstream native clients that a value's default is false. So we run into a logic error. Instead everything must be explicit: <Text on={true}>
  • the :interface-* special attribute, that docuemntation is already there but can just bre rolled into this section

Copy link
Author

Choose a reason for hiding this comment

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

may be helpful to loop back with you
ill see what I can gather for now, but as I move along with this pr, ill start to ask for you help here

the usage of native markup.

This is a similar procedure to standard LiveViews, with the only difference being the `LiveViewNative.Component.sigil_LVN/2` and our two arity
`render/2` function – containing a map we can use to match on device type and other metadata (Similar
to LiveView, we import above functions automatically when using `LiveViewNative.LiveView`).

The rest is quite akin to a standard LiveView, and will interop directly into your existing Phoenix LiveView
application. For more information on the component lifecycle, check `LiveViewNative.Component`.

### Handling

Once a sucessful response is sent back from the server, we need a client to process this data.
Similar to most native development, we need the respective platform's development tools to build and deploy
your LiveView Native client, but as we continue to build our tooling, we are begining to offer platform-specific applications
to test your project.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to point people to LVN Go as an alternative to using Xcode because of Xcode's compilation time. It's just easy to get going. However, they should only use LVN Go if they're using a release version of LVN. For example, if they're on main or an RC version we don't support LVN Go for those situations.

Copy link
Author

Choose a reason for hiding this comment

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

For sure I can put more of an emphasis on LVN Go


Corresponding documentation for each client is available in our supported markup processors, and will walk you through
the setup needed to test in each environment.

## Supported Clients

LiveView Native enables client frameworks in the following.

| UI Framework | Devices | Markup Processor | Build Tool | Testing Client |
|------------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------|----------------|-------------------------------------------------------------|
| SwiftUI | iPhone, iPad, AppleTV, Apple Watch, MacOS, Apple Vision Pro | [LiveView Native SwiftUI](https://github.com/liveview-native/liveview-client-swiftui) | XCode | [LVN Go](https://apps.apple.com/us/app/lvn-go/id6614695506) |
| JetPack Compose | Android family | [LiveView Native Jetpack](https://github.com/liveview-native/liveview-client-jetpack) | Android Studio | |
| HTML | | [LiveView Native HTML](https://github.com/liveview-native/liveview-client-html) | | |
14 changes: 13 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ defmodule LiveViewNative.MixProject do

defp docs do
[
extras: ["README.md"],
extras: extras(),
main: "readme",
groups_for_extras: groups_for_extras(),
source_url: @source_url,
source_ref: @version
]
end

defp extras do
["README.md"] ++ Path.wildcard("guides/*/*.md")
end

defp groups_for_extras do
[
Introduction: ~r"guides/introduction/",
"Getting Started": ~r"guides/getting-started/"
]
end

defp description, do: "LiveView Native"

defp package do
Expand Down