From 7f10f1201a078d5c2801c127c02c5d6d0558a97d Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Wed, 5 Mar 2025 03:53:08 -0500 Subject: [PATCH 1/9] Fix float parsing (#1550) --- CHANGELOG.md | 1 + .../swiftui/rules_parser/tokens.ex | 24 +++++++++---------- .../swiftui/rules_parser_test.exs | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe49811b..42d593551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Views will now update properly when the server changes the value of a form field (#1483) +- Fixed float parsing for stylesheet rules ## [0.3.1] 2024-10-02 diff --git a/lib/live_view_native/swiftui/rules_parser/tokens.ex b/lib/live_view_native/swiftui/rules_parser/tokens.ex index 64ed52536..ae30f9212 100644 --- a/lib/live_view_native/swiftui/rules_parser/tokens.ex +++ b/lib/live_view_native/swiftui/rules_parser/tokens.ex @@ -21,32 +21,30 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Tokens do def nil_(), do: replace(string("nil"), nil) - def minus(), do: string("-") - - def underscored_integer() do - integer(min: 1) + def digits() do + ascii_char([?0..?9]) |> repeat( choice([ ascii_char([?0..?9]), - ignore(string("_")) - |> ascii_char([?0..?9]) + ignore(string("_")) |> ascii_char([?0..?9]) ]) - |> reduce({List, :to_string, []}) ) - |> reduce({Enum, :join, [""]}) + |> reduce({List, :to_string, []}) + end + + def minus(), do: string("-") + + def frac() do + concat(string("."), digits()) end def integer() do optional(minus()) - |> concat(underscored_integer()) + |> concat(digits()) |> reduce({Enum, :join, [""]}) |> map({String, :to_integer, []}) end - def frac() do - concat(string("."), underscored_integer()) - end - def float() do integer() |> concat(frac()) diff --git a/test/live_view_native/swiftui/rules_parser_test.exs b/test/live_view_native/swiftui/rules_parser_test.exs index 6f8cdff6b..d285ff6dc 100644 --- a/test/live_view_native/swiftui/rules_parser_test.exs +++ b/test/live_view_native/swiftui/rules_parser_test.exs @@ -117,8 +117,8 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do assert parse(input) == output - input = "background(Color.blue.opacity(0.2).blendMode(.multiply).mix(with: .orange).opacity(0.7))" - output = {:background, [], [{:., [], [{:., [], [{:., [], [{:., [], [{:., [], [:Color, :blue]}, {:opacity, [], [0.2]}]}, {:blendMode, [], [{:., [], [nil, :multiply]}]}]}, {:mix, [], [{:with, {:., [], [nil, :orange]}}]}]}, {:opacity, [], [0.7]}]}]} + input = "background(Color.blue.opacity(0.02).blendMode(.multiply).mix(with: .orange).opacity(0.7))" + output = {:background, [], [{:., [], [{:., [], [{:., [], [{:., [], [{:., [], [:Color, :blue]}, {:opacity, [], [0.02]}]}, {:blendMode, [], [{:., [], [nil, :multiply]}]}]}, {:mix, [], [{:with, {:., [], [nil, :orange]}}]}]}, {:opacity, [], [0.7]}]}]} assert parse(input) == output end From 8b8df68340faa65f711e0b7f7d8eaf34264d67b4 Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Wed, 5 Mar 2025 03:53:47 -0500 Subject: [PATCH 2/9] Update Package.resolved --- Package.resolved | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index cd7f7fa36..27381643a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "4dd8c7cbc917ecfea85da314dc244366302002117a41d066ce90dade52deba33", + "originHash" : "a1b1e06fbdf5f90d2817b4e4ba491ff6fc177e87dad20844f45d67caa0b58193", "pins" : [ { "identity" : "liveview-native-core", "kind" : "remoteSourceControl", "location" : "https://github.com/liveview-native/liveview-native-core", "state" : { - "revision" : "7b490ee3ab76c7e83220e7255ad5b0d9d901a767", - "version" : "0.4.1-rc-1" + "revision" : "c067c8b458458c6eb01ef73f9e40e282aa79719a", + "version" : "0.4.1-rc-2" } }, { From dd02963b991090c97bcd6205002c1fff39c60d32 Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Wed, 5 Mar 2025 03:54:38 -0500 Subject: [PATCH 3/9] Fix CI --- .github/workflows/elixir.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 2208abf6d..6c7c6ad99 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -14,7 +14,7 @@ env: jobs: build: name: Build and test - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Elixir From 705a500d56aefe8b0d297d962a5ec0a841c07052 Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Wed, 19 Mar 2025 18:20:27 -0700 Subject: [PATCH 4/9] reconnect on an error in any reply, should push to flash --- .../Coordinators/LiveSessionCoordinator.swift | 22 +++++++++++-------- .../Coordinators/LiveViewCoordinator.swift | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift index 2418bc2a4..d742c38d2 100644 --- a/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift @@ -266,15 +266,7 @@ public class LiveSessionCoordinator: ObservableObject { } } - let liveChannel = try await self.liveSocket!.joinLiveviewChannel( - .some([ - "_format": .str(string: LiveSessionParameters.platform), - "_interface": .object(object: LiveSessionParameters.platformParams) - ]), - nil - ) - - self.navigationPath.last!.coordinator.join(liveChannel) + try await self.joinLiveViewChannel() self.state = .connected @@ -328,6 +320,18 @@ public class LiveSessionCoordinator: ObservableObject { } } + + func joinLiveViewChannel() async throws { + let liveChannel = try await self.liveSocket!.joinLiveviewChannel( + .some([ + "_format": .str(string: LiveSessionParameters.platform), + "_interface": .object(object: LiveSessionParameters.platformParams) + ]), + nil + ) + + self.navigationPath.last?.coordinator.join(liveChannel) + } private func disconnect(preserveNavigationPath: Bool = false) async { do { diff --git a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift index bfc4e741b..3326a95aa 100644 --- a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift @@ -270,6 +270,9 @@ public class LiveViewCoordinator: ObservableObject { guard !Task.isCancelled else { return } do { switch event.event { + case .phoenix(phoenix: .error): + logger.error("encountered error in reply - channel reconnecting"); + try await session.joinLiveViewChannel() case .user(user: "diff"): switch event.payload { case let .jsonPayload(json): From 6275b47257e0b9cbffdd4ed7fe2373867e7a75b8 Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Wed, 19 Mar 2025 18:24:28 -0700 Subject: [PATCH 5/9] cleanup --- .../LiveViewNative/Coordinators/LiveViewCoordinator.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift index 3326a95aa..1a5475833 100644 --- a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift @@ -345,6 +345,13 @@ public class LiveViewCoordinator: ObservableObject { } func join(_ liveChannel: LiveViewNativeCore.LiveChannel) { + if let old = self.liveChannel { + let channel = old.channel() + Task { @MainActor in + try await channel.shutdown() + } + } + self.liveChannel = liveChannel let channel = liveChannel.channel() self.channel = channel From 06cf88164c646aafc02e04c9cfc48793b0a33c4c Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Wed, 19 Mar 2025 18:36:29 -0700 Subject: [PATCH 6/9] cleanup --- .../Coordinators/LiveViewCoordinator.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift index 1a5475833..90920f6f0 100644 --- a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift @@ -272,6 +272,10 @@ public class LiveViewCoordinator: ObservableObject { switch event.event { case .phoenix(phoenix: .error): logger.error("encountered error in reply - channel reconnecting"); + if let liveChannel { + let channel = liveChannel.channel() + try await channel.shutdown() + } try await session.joinLiveViewChannel() case .user(user: "diff"): switch event.payload { @@ -345,12 +349,6 @@ public class LiveViewCoordinator: ObservableObject { } func join(_ liveChannel: LiveViewNativeCore.LiveChannel) { - if let old = self.liveChannel { - let channel = old.channel() - Task { @MainActor in - try await channel.shutdown() - } - } self.liveChannel = liveChannel let channel = liveChannel.channel() From 03348c130809d732a8fcf01d86b572a7f9e52ac0 Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Wed, 19 Mar 2025 18:20:27 -0700 Subject: [PATCH 7/9] reconnect on an error in any reply, should push to flash --- .../Coordinators/LiveSessionCoordinator.swift | 22 +++++++++++-------- .../Coordinators/LiveViewCoordinator.swift | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift index 2418bc2a4..d742c38d2 100644 --- a/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift @@ -266,15 +266,7 @@ public class LiveSessionCoordinator: ObservableObject { } } - let liveChannel = try await self.liveSocket!.joinLiveviewChannel( - .some([ - "_format": .str(string: LiveSessionParameters.platform), - "_interface": .object(object: LiveSessionParameters.platformParams) - ]), - nil - ) - - self.navigationPath.last!.coordinator.join(liveChannel) + try await self.joinLiveViewChannel() self.state = .connected @@ -328,6 +320,18 @@ public class LiveSessionCoordinator: ObservableObject { } } + + func joinLiveViewChannel() async throws { + let liveChannel = try await self.liveSocket!.joinLiveviewChannel( + .some([ + "_format": .str(string: LiveSessionParameters.platform), + "_interface": .object(object: LiveSessionParameters.platformParams) + ]), + nil + ) + + self.navigationPath.last?.coordinator.join(liveChannel) + } private func disconnect(preserveNavigationPath: Bool = false) async { do { diff --git a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift index bfc4e741b..3326a95aa 100644 --- a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift @@ -270,6 +270,9 @@ public class LiveViewCoordinator: ObservableObject { guard !Task.isCancelled else { return } do { switch event.event { + case .phoenix(phoenix: .error): + logger.error("encountered error in reply - channel reconnecting"); + try await session.joinLiveViewChannel() case .user(user: "diff"): switch event.payload { case let .jsonPayload(json): From e3ecbfe5f5295e12179b7a211bc8a545533f3972 Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Wed, 19 Mar 2025 18:24:28 -0700 Subject: [PATCH 8/9] cleanup --- .../LiveViewNative/Coordinators/LiveViewCoordinator.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift index 3326a95aa..1a5475833 100644 --- a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift @@ -345,6 +345,13 @@ public class LiveViewCoordinator: ObservableObject { } func join(_ liveChannel: LiveViewNativeCore.LiveChannel) { + if let old = self.liveChannel { + let channel = old.channel() + Task { @MainActor in + try await channel.shutdown() + } + } + self.liveChannel = liveChannel let channel = liveChannel.channel() self.channel = channel From f1c61fb67fa7a15ef9e56505d10490e105497dc0 Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Wed, 19 Mar 2025 18:36:29 -0700 Subject: [PATCH 9/9] cleanup --- .../Coordinators/LiveViewCoordinator.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift index 1a5475833..90920f6f0 100644 --- a/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift +++ b/Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift @@ -272,6 +272,10 @@ public class LiveViewCoordinator: ObservableObject { switch event.event { case .phoenix(phoenix: .error): logger.error("encountered error in reply - channel reconnecting"); + if let liveChannel { + let channel = liveChannel.channel() + try await channel.shutdown() + } try await session.joinLiveViewChannel() case .user(user: "diff"): switch event.payload { @@ -345,12 +349,6 @@ public class LiveViewCoordinator: ObservableObject { } func join(_ liveChannel: LiveViewNativeCore.LiveChannel) { - if let old = self.liveChannel { - let channel = old.channel() - Task { @MainActor in - try await channel.shutdown() - } - } self.liveChannel = liveChannel let channel = liveChannel.channel()