-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Setting Up LiveView Native |
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). | |||||||||||
|
|||||||||||
### 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. | |||||||||||
|
|||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | |||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been intending to write a section on how Right now the only differences from HEEx:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be helpful to loop back with you |
|||||||||||
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. | |||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | | | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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