liveview-native / live_view_native

A framework for building native applications with Phoenix LiveView
https://native.live/
MIT License
441 stars 18 forks source link

`platform_id` parsing parameter error #62

Closed ByeongUkChoi closed 8 months ago

ByeongUkChoi commented 8 months ago

https://github.com/liveview-native/live_view_native/blob/main/lib/live_view_native/live_session.ex#L46

as shown above liveview-native can find the platform_id when the app requests

GET /?_platform=swiftui

However, my app requests as follows

GET /?_lvn_platform=swiftui

I just installed it with this command

mix lvn.install

It's probably because it's spent here. https://github.com/liveview-native/liveview-client-swiftui/blob/main/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift#L222

So what do you think about adding this function to the LiveViewNative.LiveSession module as a buffer code?

defp get_platform_context(%{"_lvn_platform" => platform_id} = connect_params) do
  connect_params
  |> Map.put_new("_platform", platform_id)
  |> get_platform_context()
end
supernintendo commented 8 months ago

@ByeongUkChoi These proposed changes have already been implemented in the next branch of this repo. This is happening because of a version mismatch between live_view_native and liveview-client-swiftui within your project:

# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
deps do
  [
    # ...
    {:live_view_native, git: "https://github.com/liveview-native/live_view_native", branch: "next"},
    {:live_view_native_swift_ui, git: "https://github.com/liveview-native/liveview-client-swiftui", branch: "main"}
    # ...
  ]
end

Screenshot 2023-11-06 at 9 24 59 AM

supernintendo commented 8 months ago

Oh just one more thing to note; the next branch of this repo is currently incompatible with the liveview-client-swiftui unless you're using this branch - https://github.com/liveview-native/liveview-client-swiftui/pull/1154. Using a non bleeding-edge / versioned release for both dependencies avoids this.

ByeongUkChoi commented 8 months ago

@supernintendo Hi~ Sources/LiveViewNative/Coordinators/LiveSessionCoordinators.swift In this file, you are sending the platform value with the key _lvn_platform. However, there is still no part of https://github.com/liveview-native/live_view_native/tree/next or https://github.com/liveview-native/liveview-client-swiftui/pull/1154 parsing the _lvn_platform.

ByeongUkChoi commented 8 months ago

@supernintendo Oh Now It works. It changed from :platform to :format

  def render(%{format: :swiftui} = assigns) do
    ~SWIFTUI"""
    <VStack>
      <Text>
        Hello native!
      </Text>
    </VStack>
    """swiftui
  end
supernintendo commented 8 months ago

@ByeongUkChoi Oh right, I forgot to mention that as well. There are a number of breaking changes in the next branch that we'll document with the actual release of 0.2; right now a few things are in flux and subject to change. Thank you for your patience as we get the next version ready to publish 🙂

Also, that _lvn_platform param actually seems to be dead code in the Swift client but I'll look into it a bit more to confirm. The actual connection params have been moved to a map called _lvn; the relevant code for that on both ends is here:

liveview-client-swiftui: https://github.com/liveview-native/liveview-client-swiftui/blob/main/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift#L238 and https://github.com/liveview-native/liveview-client-swiftui/blob/main/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift#L405

live_view_native: https://github.com/liveview-native/live_view_native/blob/next/lib/live_view_native/live_session.ex#L36