mmmrrr

mmmrrr

Hey everybody. I’m currently working on the reimplementation of an app and we’re using phoenix coupled with Turbo and Stimulus. The only reason we didn’t went with LiveView is turbo-ios which is a fantastic library for a native iOS client: it’s very lightweight (the whole “framework” is only around 3000 LOC) and allows you to build hybrid apps fast.

The idea of this companion library (it also exists for android, too) is to have native navigation and web content. The UX is really great, since turbo will cache a lot and hence navigation feels instant in many cases. For the most part it feels like a native app. You can also simply mix in native views easily (for example maps, code scanner, login screen, or whatever makes sense for your application).

The downside to all this is: while the programming model, of only having to send stateless html pages over the wire, seems very simple at first, it gets really, really hairy after a while. Breaking the application down is done via turbo-frames which you can update in place through “turbo-streams” (which we feed through phoenix channels). You also have to always pick the correct http verb when sending data so that turbo will react the way you intended - which is not always as easy as it sounds.

Enough praise/rant, I’d like to build something like turbo-ios/turbo-android but for LiveView. I think the main features would need to be:

  • Native navigation patterns (one web view that gets reused and rendered inside a native navigation stack)
  • Patching native components through LV
  • “caching” already visited pages (i. e. display screenshots/cached html of the last visit even when offline)

I could have started by simply forking turbo-ios but I don’t know enough about the internals of LiveView to decide if this is something that is feasible at all or if there are currently some properties preventing my envisioned use cases.

Also I’d like to learn about prior art in this space (for example, I know about elixir-desktop which is very, very interesting, but not what I’m after).

Showing Posts 1 to 10

AstonJ

AstonJ

This sounds really cool and I was going to suggest you look at Elixir Desktop.. but looks like you’re already aware of it :smiley: Any reason in particular why it’s not what you’re after? Would your project just be for iOS/Android?

Either way good luck, I’m sure a lot of people will be interested in seeing what you come up with :023:

mmmrrr

mmmrrr OP

Yes! elixir-desktop is just the opposite of what I’m after: it is an app running on the users device rendering all UI elements with web technologies.

What I want to achieve instead is a wrapper using platform native, navigational UI elements and displaying content and cross platform UI elements generated by a central server. (Like described here for Turbo: Basecamp 3 for iOS: Hybrid Architecture - Signal v. Noise)

And this also answers the second question:

Probably, since I don’t have use for anything else currently, but in the end it would be possible to write such a wrapper for any platform that can display a web view. The main problem will be to define the api making the communication between LV and the “native” components feasible.

kujua

kujua

Author of Erlang and Elixir for Imperative Programmers

A few thoughts (I may be out of my depth):

If you have web views you could use js hooks. There exists something similar with React (have not played with it). But: the client (the webview) needs to interpret what the server wants. So you need a bridge (in fact data that can be interpreted).

I guess the same approach could be taken with a native app.so the LivevView acts like a server"and owns the state. The reply tells the app what to display.

mayel

mayel

Interesting… Not sure about rendering native UI elements using LiveView, but for interacting with device feature via JS maybe you could reuse Cordova’s plugins?

mayel

mayel

And there’s also https://capacitorjs.com by Ionic

mayel

mayel

And regarding UI, if you’re satisfied with using a web view (at least for some parts of the app), then maybe something like CSS Components - Onsen UI - Onsen UI and JavaScript / Web Components API - Onsen UI - Onsen UI would plug-in in to LiveView nicely

Exadra37

Exadra37

ALERT: Unpopular opinion ahead.

For context I work as a Developer Advocate for Mobile API Security, and at work we need to maintain a lot of quickstarts and examples for hybrid frameworks, and what a poor developer experience it is to work with such frameworks, one worst then the other, but all them are a nightmare to maintain and keep them working on each developers machine, especially when sometime elapsed from its creation.

Not wanting to trash any JS suggestions, but if possible my advice is to stay away from them as much as you can. If you really need to choose one go for the one that as the more direct bridge (doesn’t build on top of others) and has the less complex build system, with fewer dependencies and moving parts.

If you build your own JS bridge, don’t go fancy with JS dependencies. Try instead to consolidate them under your own code. Yes, copy paste whenever the license allows. Managing security advisories in a huge tree of dependencies on JS land becomes sometimes impractical until other packages that aren’t direct dependencies of our project update their dependencies to fix the security advisory.

mmmrrr

mmmrrr OP

I need to parrot @Exadra37 on this. The beauty of something like turbo-ios is that it is really lightweight and precisely why we did not go with capacitor, react-native, flutter, etc.

Those frameworks are measured in million lines of code. If something goes astray, I don’t want to be the one trying to fix it. That’s one reason why I decided against using a cross platform solution.

The second reason is that you almost always need platform native code in any sufficiently complex project. And e. g. with cordova you then need to write a wrapper / plugin to make it available - so that’s another indirection.

And last but not least, I enjoy using apps which look and feels like the belong on the specific platform. :slight_smile:

Precisely. The thing I’m most unsure of is how I could hijack the dom diffs that LiveView sends to then update the native components.

Exadra37

Exadra37

I also advise against wrapping your entire mobile app in an webview, because if then you need to harden the security of your mobile app you will be out of luck. Believe me that nowadays any “serious” app will need it sooner or later… Its not a question of if, but when. The when is normally when companies discover that they are vulnerable to some attack, or indeed under attack, or worst, already breached. At this point developers need to scramble for finding a solution and the business needs to deal with potential financial losses and angry users that may go away and never comeback.

Plan for your Mobile and API security from day zero, even if you don’t implement it, at least take it in consideration on your software architecture decisions to allow for an easier integration of security measures when you need to scramble to find one that is easy and quick to implement to defend against whatever attack you are suffering. A very important thing to keep in mind is to allow for the HTTP stack being used to be customisable with another one. This will come in hand when you need to add certificate pinning and other more advanced security protections to protect the communication of your mobile app with the APIs it uses.

derek-zhou

derek-zhou

I think it is possible to rewrite the client side of LV in Swift or Kotlin and maintain wire protocol compatibility with the server side LV. It is a much bigger job than turbo-ios but it can be done. The only significant dependency of LV is morphdom which have zero dependency.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews