Skip to content

Support for LiveViewNative? #708

Open

Description

@mayel

As LVN is almost ready for production I was wondering if anyone's tried using Surface for it, and if not yet doable what changes would be needed?

One aspect of it would be being able to have multiple markup files for the same component/view:

  • my_component.sface
  • my_component.swiftui
  • my_component.jetpack
  • etc

Activity

  1. mayel commented on Sep 17, 2023

    @mayel
    ContributorAuthor

    So gave it a shot and the good news is that it mostly works! :)

    Surface and LiveViewNative happily live side by side in components and views. E.g.:

            use Surface.Component
            use LiveViewNative.Component
    

    The only thing that doesn't seem to work is collocating .sface and LVN files as I mentioned above and documented here: https://hexdocs.pm/live_view_native/render-patterns.html#external-template-files

    This works in the meantime, though I'd still prefer being able to have separate files:

      def render(%{platform_id: :swiftui} = assigns) do
        # This UI renders on the iOS/Mac app
        ~SWIFTUI"""
        <VStack>
          <Text>
            Hello native!
          </Text>
        </VStack>
        """
      end
    
      def render(assigns) do
        assigns
        |> render_sface()
      end
    
  2. mayel commented on Sep 17, 2023

    @mayel
    ContributorAuthor
  3. noozo commented on Oct 13, 2023

    @noozo

    i think it mostly works, the main issue RN is layouts, me thinks.

  4. mayel commented on Oct 13, 2023

    @mayel
    ContributorAuthor

    @noozo I had no issues doing this for the live layout:

    defmodule MyApp.Web.LayoutLive do
            use Surface.Component
            use LiveViewNative.Component
    
      def render(%{platform_id: :swiftui} = assigns) do
        # This renders a layout for the iOS/Mac app
        ~SWIFTUI"""
        <VStack>
          <%= @inner_content %>
        </VStack>
        """
      end
    
      def render(assigns) do
      # This layout renders for the web (with Surface)
        ~F"""
        <div
          id="layout_live"
    [...]
  5. mayel commented on Dec 21, 2023

    @mayel
    ContributorAuthor

    With the LiveViewNative 0.2 beta, there's a PR to get layouts working: liveview-native/live_view_native#108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions