diff --git a/Sources/LiveViewNative/Modifiers/Documents Modifiers/RenameActionModifier.swift b/Sources/LiveViewNative/Modifiers/Documents Modifiers/RenameActionModifier.swift index 8b204235b..362b85491 100644 --- a/Sources/LiveViewNative/Modifiers/Documents Modifiers/RenameActionModifier.swift +++ b/Sources/LiveViewNative/Modifiers/Documents Modifiers/RenameActionModifier.swift @@ -14,7 +14,7 @@ import SwiftUI /// ```html /// /// ``` @@ -30,33 +30,21 @@ struct RenameActionModifier: ViewModifier, Decodable { #if swift(>=5.8) @_documentation(visibility: public) #endif - private let event: String - /// The LiveView or LiveComponent to perform the event on. - /// - /// In a component, you may use the `@myself` assign to handle the event on the LiveComponent. - #if swift(>=5.8) - @_documentation(visibility: public) - #endif - private let target: Int? - @Environment(\.coordinatorEnvironment) private var coordinatorEnvironment + @Event private var action: Event.EventHandler init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self.event = try container.decode(String.self, forKey: .event) - self.target = try container.decode(Int?.self, forKey: .target) + self._action = try container.decode(Event.self, forKey: .action) } private enum CodingKeys: String, CodingKey { - case event - case target + case action } func body(content: Content) -> some View { content .renameAction { - Task { - try await coordinatorEnvironment?.pushEvent("click", event, [String:Any](), target) - } + action(value: [String:String]()) } } } diff --git a/Sources/LiveViewNative/Modifiers/Drawing and Graphics Modifiers/MaskModifier.swift b/Sources/LiveViewNative/Modifiers/Drawing and Graphics Modifiers/MaskModifier.swift index f030aa263..d46d877b3 100644 --- a/Sources/LiveViewNative/Modifiers/Drawing and Graphics Modifiers/MaskModifier.swift +++ b/Sources/LiveViewNative/Modifiers/Drawing and Graphics Modifiers/MaskModifier.swift @@ -15,7 +15,7 @@ import SwiftUI /// @native /// |> foreground_color(color: :blue) /// |> font(font: {:system, :large_title}) -/// |> mask(alignment: :center, content: :mask) +/// |> mask(alignment: :center, mask: :mask) /// } /// > /// opacity(opacity: 0.1)} /> @@ -41,7 +41,7 @@ struct MaskModifier: ViewModifier, Decodable { #if swift(>=5.8) @_documentation(visibility: public) #endif - private let content: String + private let mask: String @ObservedElement private var element @LiveContext private var context @@ -50,17 +50,17 @@ struct MaskModifier: ViewModifier, Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) self.alignment = try container.decode(Alignment.self, forKey: .alignment) - self.content = try container.decode(String.self, forKey: .content) + self.mask = try container.decode(String.self, forKey: .mask) } func body(content: Content) -> some View { content.mask(alignment: alignment) { - context.buildChildren(of: element, forTemplate: self.content) + context.buildChildren(of: element, forTemplate: self.mask) } } enum CodingKeys: String, CodingKey { case alignment - case content + case mask } } diff --git a/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnDeleteCommandModifier.swift b/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnDeleteCommandModifier.swift index d25c940fa..a2dfbd8bc 100644 --- a/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnDeleteCommandModifier.swift +++ b/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnDeleteCommandModifier.swift @@ -46,24 +46,24 @@ struct OnDeleteCommandModifier: ViewModifier, Decodable { #if swift(>=5.8) @_documentation(visibility: public) #endif - @Event private var action: Event.EventHandler + @Event private var perform: Event.EventHandler init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self._action = try container.decode(Event.self, forKey: .action) + self._perform = try container.decode(Event.self, forKey: .perform) } func body(content: Content) -> some View { content #if os(macOS) .onDeleteCommand { - action() + perform() } #endif } enum CodingKeys: String, CodingKey { - case action + case perform } } diff --git a/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnHoverModifier.swift b/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnHoverModifier.swift index 48a0d0c6d..5405ea4e5 100644 --- a/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnHoverModifier.swift +++ b/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnHoverModifier.swift @@ -44,24 +44,24 @@ struct OnHoverModifier: ViewModifier, Decodable { #if swift(>=5.8) @_documentation(visibility: public) #endif - @Event private var action: Event.EventHandler + @Event private var perform: Event.EventHandler init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self._action = try container.decode(Event.self, forKey: .action) + self._perform = try container.decode(Event.self, forKey: .perform) } func body(content: Content) -> some View { content #if os(iOS) || os(macOS) .onHover { isHovering in - action(value: isHovering) + perform(value: isHovering) } #endif } enum CodingKeys: String, CodingKey { - case action + case perform } } diff --git a/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnMoveCommandModifier.swift b/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnMoveCommandModifier.swift index 857e97e61..fc3bc56ef 100644 --- a/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnMoveCommandModifier.swift +++ b/Sources/LiveViewNative/Modifiers/Input Events Modifiers/OnMoveCommandModifier.swift @@ -52,12 +52,12 @@ struct OnMoveCommandModifier: ViewModifier, Decodable { #if swift(>=5.8) @_documentation(visibility: public) #endif - @Event private var action: Event.EventHandler + @Event private var perform: Event.EventHandler init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self._action = try container.decode(Event.self, forKey: .action) + self._perform = try container.decode(Event.self, forKey: .perform) } func body(content: Content) -> some View { @@ -66,21 +66,21 @@ struct OnMoveCommandModifier: ViewModifier, Decodable { .onMoveCommand { direction in switch direction { case .up: - action(value: ["direction": "up"]) + perform(value: ["direction": "up"]) case .down: - action(value: ["direction": "down"]) + perform(value: ["direction": "down"]) case .left: - action(value: ["direction": "left"]) + perform(value: ["direction": "left"]) case .right: - action(value: ["direction": "right"]) + perform(value: ["direction": "right"]) @unknown default: - action(value: ["direction": String(describing: direction)]) + perform(value: ["direction": String(describing: direction)]) } } #endif } enum CodingKeys: String, CodingKey { - case action + case perform } } diff --git a/Sources/LiveViewNative/Modifiers/Menus and Commands/MenuIndicatorVisibilityModifier.swift b/Sources/LiveViewNative/Modifiers/Menus and Commands/MenuIndicatorModifier.swift similarity index 84% rename from Sources/LiveViewNative/Modifiers/Menus and Commands/MenuIndicatorVisibilityModifier.swift rename to Sources/LiveViewNative/Modifiers/Menus and Commands/MenuIndicatorModifier.swift index 44f91c8cd..80e64039e 100644 --- a/Sources/LiveViewNative/Modifiers/Menus and Commands/MenuIndicatorVisibilityModifier.swift +++ b/Sources/LiveViewNative/Modifiers/Menus and Commands/MenuIndicatorModifier.swift @@ -10,7 +10,7 @@ import SwiftUI /// Specifies whether the indicator on a ``Menu`` should be visible. /// /// ```html -/// menu_indicator_visibility(visibility: :hidden)}> +/// menu_indicator(visibility: :hidden)}> /// /// Edit Actions /// @@ -28,7 +28,7 @@ import SwiftUI @_documentation(visibility: public) #endif @available(iOS 16.0, macOS 13.0, tvOS 16.0, *) -struct MenuIndicatorVisibilityModifier: ViewModifier, Decodable { +struct MenuIndicatorModifier: ViewModifier, Decodable { /// The indicator visibility. /// /// See ``LiveViewNative/SwiftUI/Visibility`` for possible values. @@ -38,8 +38,9 @@ struct MenuIndicatorVisibilityModifier: ViewModifier, Decodable { private let visibility: Visibility func body(content: Content) -> some View { -#if !os(watchOS) - content.menuIndicator(visibility) -#endif + content + #if !os(watchOS) + .menuIndicator(visibility) + #endif } } diff --git a/lib/live_view_native_swift_ui/modifiers/animation/matched_geometry_effect.ex b/lib/live_view_native_swift_ui/modifiers/animation/matched_geometry_effect.ex index d30079eb3..a842bb51f 100644 --- a/lib/live_view_native_swift_ui/modifiers/animation/matched_geometry_effect.ex +++ b/lib/live_view_native_swift_ui/modifiers/animation/matched_geometry_effect.ex @@ -10,4 +10,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.MatchedGeometryEffect do field :anchor, UnitPoint field :is_source, :boolean, default: true end + + def params([id: id, in: namespace, properties: properties, anchor: anchor, is_source: is_source]), + do: [ + id: id, + namespace: namespace, + properties: properties, + anchor: anchor, + is_source: is_source + ] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/controls_and_indicators/button_border_shape.ex b/lib/live_view_native_swift_ui/modifiers/controls_and_indicators/button_border_shape.ex index 3aecba949..57acd013e 100644 --- a/lib/live_view_native_swift_ui/modifiers/controls_and_indicators/button_border_shape.ex +++ b/lib/live_view_native_swift_ui/modifiers/controls_and_indicators/button_border_shape.ex @@ -5,4 +5,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ButtonBorderShape do field(:shape, Ecto.Enum, values: ~w(automatic capsule rounded_rectangle)a) field(:radius, :float, default: nil) end + + def params(shape) when is_atom(shape) and not is_boolean(shape) and not is_nil(shape), do: [shape: shape] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/documents/rename_action.ex b/lib/live_view_native_swift_ui/modifiers/documents/rename_action.ex index 3522cbfaf..f62b2563e 100644 --- a/lib/live_view_native_swift_ui/modifiers/documents/rename_action.ex +++ b/lib/live_view_native_swift_ui/modifiers/documents/rename_action.ex @@ -1,8 +1,18 @@ defmodule LiveViewNativeSwiftUi.Modifiers.RenameAction do use LiveViewNativePlatform.Modifier + alias LiveViewNativePlatform.Types.Event + modifier_schema "rename_action" do - field :event, :string - field :target, :integer + field :action, Event + end + + def params(params) do + with {:ok, _} <- Event.cast(params) do + [action: params] + else + _ -> + params + end end end diff --git a/lib/live_view_native_swift_ui/modifiers/drag_and_drop/draggable.ex b/lib/live_view_native_swift_ui/modifiers/drag_and_drop/draggable.ex index ca0bb6dcd..bd5db456a 100644 --- a/lib/live_view_native_swift_ui/modifiers/drag_and_drop/draggable.ex +++ b/lib/live_view_native_swift_ui/modifiers/drag_and_drop/draggable.ex @@ -6,4 +6,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Draggable do field :payload, :string field :preview, KeyName end + + def params(payload, [preview: preview]), do: [payload: payload, preview: preview] + def params(payload) when is_binary(payload), do: [payload: payload, preview: nil] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drag_and_drop/drop_destination.ex b/lib/live_view_native_swift_ui/modifiers/drag_and_drop/drop_destination.ex index 8db51eace..6ad3a9b2e 100644 --- a/lib/live_view_native_swift_ui/modifiers/drag_and_drop/drop_destination.ex +++ b/lib/live_view_native_swift_ui/modifiers/drag_and_drop/drop_destination.ex @@ -1,7 +1,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DropDestination do use LiveViewNativePlatform.Modifier - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "drop_destination" do field :action, Event diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/background_style.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/background_style.ex index f89b227da..971fafd4e 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/background_style.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/background_style.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.BackgroundStyle do modifier_schema "background_style" do field :style, ShapeStyle end + + def params(params) do + with {:ok, _} <- ShapeStyle.cast(params) do + [style: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/blend_mode.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/blend_mode.ex index 853506d30..8a4ad9f32 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/blend_mode.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/blend_mode.ex @@ -26,4 +26,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.BlendMode do destination_out )a) end + + def params(blend_mode) when is_atom(blend_mode) and not is_boolean(blend_mode) and not is_nil(blend_mode), + do: [blend_mode: blend_mode] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/border.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/border.ex index b4f0c1177..ce78cec1a 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/border.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/border.ex @@ -7,4 +7,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Border do field :content, ShapeStyle field :width, :float, default: 1.0 end + + def params(content, [width: width]), do: [content: content, width: width] + def params(params) do + with {:ok, _} <- ShapeStyle.cast(params) do + [content: params, width: 1.0] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/brightness.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/brightness.ex index 4e924ceba..5858eeb57 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/brightness.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/brightness.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Brightness do modifier_schema "brightness" do field :amount, :float end + + def params(amount) when is_number(amount), do: [amount: amount] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/clip_shape.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/clip_shape.ex index 23375498c..f75f017da 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/clip_shape.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/clip_shape.ex @@ -7,4 +7,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ClipShape do field :shape, Shape field :style, FillStyle end + + def params(shape, [style: style]), do: [shape: shape, style: style] + def params(params) do + with {:ok, _} <- Shape.cast(params) do + [shape: params, style: nil] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/color_multiply.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/color_multiply.ex index 69b61bbe4..ecc8eb29b 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/color_multiply.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/color_multiply.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ColorMultiply do modifier_schema "color_multiply" do field :color, Color end + + def params(params) do + with {:ok, _} <- Color.cast(params) do + [color: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/contrast.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/contrast.ex index ed791bc06..5ef051555 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/contrast.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/contrast.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Contrast do modifier_schema "contrast" do field :amount, :float end + + def params(amount) when is_number(amount), do: [amount: amount] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/corner_radius.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/corner_radius.ex index ee68cabd7..5a00f061c 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/corner_radius.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/corner_radius.ex @@ -5,4 +5,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.CornerRadius do field(:radius, :float) field(:antialiased, :boolean, default: true) end + + def params(radius, [antialiased: antialiased]), do: [radius: radius, antialiased: antialiased] + def params(radius) when is_number(radius), do: [radius: radius] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/grayscale.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/grayscale.ex index a618a6cc7..437face9f 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/grayscale.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/grayscale.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Grayscale do modifier_schema "grayscale" do field :amount, :float end + + def params(amount) when is_number(amount), do: [amount: amount] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/hue_rotation.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/hue_rotation.ex index bf27f27fc..3592dbc8f 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/hue_rotation.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/hue_rotation.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.HueRotation do modifier_schema "hue_rotation" do field :angle, Angle end + + def params(params) do + with {:ok, _} <- Angle.cast(params) do + [angle: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/mask.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/mask.ex index 98c2dc550..b58b87807 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/mask.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/mask.ex @@ -17,6 +17,6 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Mask do trailing trailing_first_text_baseline )a, default: :center - field :content, KeyName + field :mask, KeyName end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/projection_effect.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/projection_effect.ex index b5fdb79cb..43efb6a58 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/projection_effect.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/projection_effect.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ProjectionEffect do modifier_schema "projection_effect" do field :transform, ProjectionTransform end + + def params(params) do + with {:ok, _} <- ProjectionTransform.cast(params) do + [transform: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_3d_effect.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_3d_effect.ex index 30fd6fcd0..b2e039460 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_3d_effect.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_3d_effect.ex @@ -12,4 +12,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Rotation3DEffect do field :anchor_z, :float, default: 0.0 field :perspective, :float, default: 1.0 end + + def params(angle, [axis: axis, anchor: anchor, anchor_z: anchor_z, perspective: perspective]), + do: [ + angle: angle, + axis: axis, + anchor: anchor, + anchor_z: anchor_z, + perspective: perspective + ] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_effect.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_effect.ex index 744139f91..15c14a853 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_effect.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/rotation_effect.ex @@ -8,4 +8,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.RotationEffect do field :angle, Angle field :anchor, UnitPoint end + + def params(angle, [anchor: anchor]), do: [angle: angle, anchor: anchor] + def params(params) do + with {:ok, _} <- Angle.cast(params) do + [angle: params, anchor: :center] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/saturation.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/saturation.ex index 8271288da..e57e53a12 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/saturation.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/saturation.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Saturation do modifier_schema "saturation" do field :amount, :float end + + def params(amount) when is_number(amount), do: [amount: amount] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/tint.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/tint.ex index cb2aa3895..d57003e7b 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/tint.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/tint.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Tint do modifier_schema "tint" do field :color, Color end + + def params(params) do + with {:ok, _} <- Color.cast(params) do + [color: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/transform_effect.ex b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/transform_effect.ex index 2982dba53..6b1b46481 100644 --- a/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/transform_effect.ex +++ b/lib/live_view_native_swift_ui/modifiers/drawing_and_graphics/transform_effect.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.TransformEffect do modifier_schema "transform_effect" do field :transform, AffineTransform end + + def params(params) do + with {:ok, _} <- AffineTransform.cast(params) do + [transform: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/focus/focus_scope.ex b/lib/live_view_native_swift_ui/modifiers/focus/focus_scope.ex index 9d16dbd3e..9e01c6fd5 100644 --- a/lib/live_view_native_swift_ui/modifiers/focus/focus_scope.ex +++ b/lib/live_view_native_swift_ui/modifiers/focus/focus_scope.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.FocusScope do modifier_schema "focus_scope" do field :namespace, Namespace end + + def params(params) do + with {:ok, _} <- Namespace.cast(params) do + [namespace: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/focus/focusable.ex b/lib/live_view_native_swift_ui/modifiers/focus/focusable.ex index 10dac3b8a..e49be4142 100644 --- a/lib/live_view_native_swift_ui/modifiers/focus/focusable.ex +++ b/lib/live_view_native_swift_ui/modifiers/focus/focusable.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Focusable do modifier_schema "focusable" do field :is_focusable, :boolean, default: true end + + def params(is_focusable) when is_boolean(is_focusable), do: [is_focusable: is_focusable] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/focus/prefers_default_focus.ex b/lib/live_view_native_swift_ui/modifiers/focus/prefers_default_focus.ex index be261260d..e2c4f539f 100644 --- a/lib/live_view_native_swift_ui/modifiers/focus/prefers_default_focus.ex +++ b/lib/live_view_native_swift_ui/modifiers/focus/prefers_default_focus.ex @@ -7,4 +7,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PrefersDefaultFocus do field :prefers_default_focus, :boolean, default: true field :namespace, Namespace end + + # def params(prefers_default_focus \\ true, [in: namespace]), do: [prefers_default_focus: prefers_default_focus, namespace: namespace] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/gestures/defers_system_gestures.ex b/lib/live_view_native_swift_ui/modifiers/gestures/defers_system_gestures.ex index e1dcadaee..dd1f697ab 100644 --- a/lib/live_view_native_swift_ui/modifiers/gestures/defers_system_gestures.ex +++ b/lib/live_view_native_swift_ui/modifiers/gestures/defers_system_gestures.ex @@ -6,4 +6,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DefersSystemGestures do modifier_schema "defers_system_gestures" do field :edges, EdgeSet end + + def params([on: edges]), do: [edges: edges] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/gestures/gesture.ex b/lib/live_view_native_swift_ui/modifiers/gestures/gesture.ex index 255a97e7d..e068f7d06 100644 --- a/lib/live_view_native_swift_ui/modifiers/gestures/gesture.ex +++ b/lib/live_view_native_swift_ui/modifiers/gestures/gesture.ex @@ -2,7 +2,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnTapGesture do use LiveViewNativePlatform.Modifier alias LiveViewNativeSwiftUi.Types.Gesture - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "gesture" do field :gesture, Gesture @@ -10,4 +10,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnTapGesture do field :priority, Ecto.Enum, values: ~w(low high simultaneous)a, default: :low field :mask, Ecto.Enum, values: ~w(none gesture subviews all)a, default: :all end + + def params(gesture, [action: action, priority: priority, mask: mask]), + do: [gesture: gesture, action: action, priority: priority, mask: mask] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/images/antialiased.ex b/lib/live_view_native_swift_ui/modifiers/images/antialiased.ex index ed5ffa077..a23556caf 100644 --- a/lib/live_view_native_swift_ui/modifiers/images/antialiased.ex +++ b/lib/live_view_native_swift_ui/modifiers/images/antialiased.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Antialiased do modifier_schema "antialiased" do field :is_active, :boolean, default: true end + + def params(is_active) when is_boolean(is_active), do: [is_active: is_active] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/images/interpolation.ex b/lib/live_view_native_swift_ui/modifiers/images/interpolation.ex index a802f42b9..ee20a9bef 100644 --- a/lib/live_view_native_swift_ui/modifiers/images/interpolation.ex +++ b/lib/live_view_native_swift_ui/modifiers/images/interpolation.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Interpolation do modifier_schema "interpolation" do field :interpolation, Ecto.Enum, values: ~w(low medium high none)a end + + def params(interpolation) when is_atom(interpolation) and not is_boolean(interpolation) and not is_nil(interpolation), do: [interpolation: interpolation] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/images/rendering_mode.ex b/lib/live_view_native_swift_ui/modifiers/images/rendering_mode.ex index 583db44e2..2b1011611 100644 --- a/lib/live_view_native_swift_ui/modifiers/images/rendering_mode.ex +++ b/lib/live_view_native_swift_ui/modifiers/images/rendering_mode.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.RenderingMode do modifier_schema "rendering_mode" do field :mode, Ecto.Enum, values: ~w(original template)a end + + def params(mode) when is_atom(mode) and not is_boolean(mode) and not is_nil(mode), do: [mode: mode] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/images/symbol_rendering_mode.ex b/lib/live_view_native_swift_ui/modifiers/images/symbol_rendering_mode.ex index 7dc0b11b0..5b42fb2f3 100644 --- a/lib/live_view_native_swift_ui/modifiers/images/symbol_rendering_mode.ex +++ b/lib/live_view_native_swift_ui/modifiers/images/symbol_rendering_mode.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.SymbolRenderingMode do modifier_schema "symbol_rendering_mode" do field :mode, Ecto.Enum, values: ~w(hierarchical monochrome multicolor palette)a end + + def params(mode) when is_atom(mode) and not is_boolean(mode) and not is_nil(mode), do: [mode: mode] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/images/symbol_variant.ex b/lib/live_view_native_swift_ui/modifiers/images/symbol_variant.ex index 301068e54..de5659ab8 100644 --- a/lib/live_view_native_swift_ui/modifiers/images/symbol_variant.ex +++ b/lib/live_view_native_swift_ui/modifiers/images/symbol_variant.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.SymbolVariant do modifier_schema "symbol_variant" do field :variant, SymbolVariants end + + def params(params) do + with {:ok, _} <- SymbolVariants.cast(params) do + [variant: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/allows_hit_testing.ex b/lib/live_view_native_swift_ui/modifiers/input_events/allows_hit_testing.ex index 4601e273d..72fa94fad 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/allows_hit_testing.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/allows_hit_testing.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.AllowsHitTesting do modifier_schema "allows_hit_testing" do field :enabled, :boolean end + + def params(enabled) when is_boolean(enabled), do: [enabled: enabled] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/digital_crown_accessory_visibility.ex b/lib/live_view_native_swift_ui/modifiers/input_events/digital_crown_accessory_visibility.ex index b14c5b41c..b188a3503 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/digital_crown_accessory_visibility.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/digital_crown_accessory_visibility.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DigitalCrownAccessoryVisibility do modifier_schema "digital_crown_accessory_visibility" do field :visibility, Ecto.Enum, values: ~w(automatic visible hidden)a end + + def params(visibility) when is_atom(visibility) and not is_boolean(visibility) and not is_nil(visibility), do: [visibility: visibility] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/hover_effect.ex b/lib/live_view_native_swift_ui/modifiers/input_events/hover_effect.ex index 071e91b38..21027a7fe 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/hover_effect.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/hover_effect.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.HoverEffect do modifier_schema "hover_effect" do field :effect, Ecto.Enum, values: ~w(automatic highlight lift)a, default: :automatic end + + def params(effect) when is_atom(effect) and not is_boolean(effect) and not is_nil(effect), do: [effect: effect] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/on_delete_command.ex b/lib/live_view_native_swift_ui/modifiers/input_events/on_delete_command.ex index eda8dfc54..326e98cee 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/on_delete_command.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/on_delete_command.ex @@ -1,9 +1,9 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnDeleteCommand do use LiveViewNativePlatform.Modifier - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "on_delete_command" do - field :action, Event + field :perform, Event end end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/on_hover.ex b/lib/live_view_native_swift_ui/modifiers/input_events/on_hover.ex index 137495421..33fcf5bdf 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/on_hover.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/on_hover.ex @@ -1,9 +1,9 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnHover do use LiveViewNativePlatform.Modifier - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "on_hover" do - field :action, Event + field :perform, Event end end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/on_move_command.ex b/lib/live_view_native_swift_ui/modifiers/input_events/on_move_command.ex index 82427728d..518e728ef 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/on_move_command.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/on_move_command.ex @@ -1,7 +1,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnMoveCommand do use LiveViewNativePlatform.Modifier - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "on_move_command" do field :action, Event diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/on_submit.ex b/lib/live_view_native_swift_ui/modifiers/input_events/on_submit.ex index 34ec05c92..0505e7673 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/on_submit.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/on_submit.ex @@ -2,10 +2,20 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnSubmit do use LiveViewNativePlatform.Modifier alias LiveViewNativeSwiftUi.Types.SubmitTriggers - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "on_submit" do field :triggers, SubmitTriggers field :action, Event end + + def params([of: triggers], action), do: [triggers: triggers, action: action] + def params(params) do + with {:ok, _} <- Event.cast(params) do + [action: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/input_events/submit_scope.ex b/lib/live_view_native_swift_ui/modifiers/input_events/submit_scope.ex index 0168ccbd1..ec8454f53 100644 --- a/lib/live_view_native_swift_ui/modifiers/input_events/submit_scope.ex +++ b/lib/live_view_native_swift_ui/modifiers/input_events/submit_scope.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.SubmitScope do modifier_schema "submit_scope" do field :is_blocking, :boolean, default: true end + + def params(is_blocking) when is_boolean(is_blocking), do: [is_blocking: is_blocking] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/layout_adjustments/coordinate_space.ex b/lib/live_view_native_swift_ui/modifiers/layout_adjustments/coordinate_space.ex index 1e7b33d75..5baeaa88a 100644 --- a/lib/live_view_native_swift_ui/modifiers/layout_adjustments/coordinate_space.ex +++ b/lib/live_view_native_swift_ui/modifiers/layout_adjustments/coordinate_space.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.CoordinateSpace do modifier_schema "coordinate_space" do field :name, :string end + + def params(name) when is_binary(name), do: [name: name] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/layout_adjustments/ignores_safe_area.ex b/lib/live_view_native_swift_ui/modifiers/layout_adjustments/ignores_safe_area.ex index 4247a0b22..a0cf42153 100644 --- a/lib/live_view_native_swift_ui/modifiers/layout_adjustments/ignores_safe_area.ex +++ b/lib/live_view_native_swift_ui/modifiers/layout_adjustments/ignores_safe_area.ex @@ -7,5 +7,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.IgnoresSafeArea do field :regions, Ecto.Enum, values: ~w(all container keyboard)a, default: :all field :edges, EdgeSet end -end + def params(regions, [edges: edges]), do: [regions: regions, edges: edges] + def params(params), do: params +end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/badge.ex b/lib/live_view_native_swift_ui/modifiers/lists/badge.ex index 94c210309..87931367b 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/badge.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/badge.ex @@ -8,4 +8,15 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Badge do field :label, :string field :count, :integer end + + def params(label) when is_binary(label), do: [label: label] + def params(count) when is_number(count), do: [count: count] + def params(params) do + with {:ok, _} <- KeyName.cast(params) do + [content: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/delete_disabled.ex b/lib/live_view_native_swift_ui/modifiers/lists/delete_disabled.ex index ec1c116a3..e0b476e9e 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/delete_disabled.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/delete_disabled.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DeleteDisabled do modifier_schema "delete_disabled" do field :is_disabled, :boolean end + + def params(is_disabled) when is_boolean(is_disabled), do: [is_disabled: is_disabled] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/disclosure_group_style.ex b/lib/live_view_native_swift_ui/modifiers/lists/disclosure_group_style.ex index 4e988c3d7..55b13e48b 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/disclosure_group_style.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/disclosure_group_style.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DisclosureGroupStyle do modifier_schema "disclosure_group_style" do field :style, Ecto.Enum, values: ~w(automatic)a end + + def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/header_prominence.ex b/lib/live_view_native_swift_ui/modifiers/lists/header_prominence.ex index f942297b7..21952870f 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/header_prominence.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/header_prominence.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.HeaderProminence do modifier_schema "header_prominence" do field :prominence, Ecto.Enum, values: ~w(increased standard)a end -end \ No newline at end of file + + def params(prominence) when is_atom(prominence) and not is_boolean(prominence) and not is_nil(prominence), do: [prominence: prominence] + def params(params), do: params +end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_item_tint.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_item_tint.ex index 5db32efee..de1c7e053 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_item_tint.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_item_tint.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListItemTint do modifier_schema "list_item_tint" do field :tint, ListItemTint end + + def params(params) do + with {:ok, _} <- ListItemTint.cast(params) do + [tint: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_row_background.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_row_background.ex index 181585cb3..69a00e589 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_row_background.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_row_background.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListRowBackground do modifier_schema "list_row_background" do field :content, KeyName end + + def params(params) do + with {:ok, _} <- KeyName.cast(params) do + [content: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_row_insets.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_row_insets.ex index ccccdab02..310f053e0 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_row_insets.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_row_insets.ex @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListRowInsets do modifier_schema "list_row_insets" do field :insets, EdgeInsets end + + def params(params) do + with {:ok, _} <- EdgeInsets.cast(params) do + [insets: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator.ex index 5a93a0135..467ddb29b 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator.ex @@ -3,6 +3,10 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListRowSeparator do modifier_schema "list_row_separator" do field :visibility, Ecto.Enum, values: ~w(automatic visible hidden)a - field :edges, Ecto.Enum, values: ~w(all bottom top)a + field :edges, Ecto.Enum, values: ~w(all bottom top)a, default: :all end + + def params(visibility, [edges: edges]), do: [visibility: visibility, edges: edges] + def params(visibility) when is_atom(visibility) and not is_boolean(visibility) and not is_nil(visibility), do: [visibility: visibility] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator_tint.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator_tint.ex index 5d07eb1d1..75bace833 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator_tint.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_row_separator_tint.ex @@ -7,4 +7,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListRowSeparatorTint do field :color, Color field :edges, Ecto.Enum, values: ~w(all bottom top)a, default: :all end + + def params(color, [edges: edges]), do: [color: color, edges: edges] + def params(params) do + with {:ok, _} <- Color.cast(params) do + [color: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator.ex index 5edc212a0..39bb90e74 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator.ex @@ -5,4 +5,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListSectionSeparator do field :visibility, Ecto.Enum, values: ~w(automatic hidden visible)a field :edges, Ecto.Enum, values: ~w(all bottom top)a, default: :all end + + def params(visibility, [edges: edges]), do: [visibility: visibility, edges: edges] + def params(visibility) when is_atom(visibility) and not is_boolean(visibility) and not is_nil(visibility), do: [visibility: visibility] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator_tint.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator_tint.ex index be4b47e78..b72902e8c 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator_tint.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_section_separator_tint.ex @@ -7,4 +7,14 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListSectionSeparatorTint do field :color, Color field :edges, Ecto.Enum, values: ~w(all bottom top)a, default: :all end + + def params(color, [edges: edges]), do: [color: color, edges: edges] + def params(params) do + with {:ok, _} <- Color.cast(params) do + [color: params] + else + _ -> + params + end + end end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/list_style.ex b/lib/live_view_native_swift_ui/modifiers/lists/list_style.ex index 12357c24b..971e2471c 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/list_style.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/list_style.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ListStyle do modifier_schema "list_style" do field :style, Ecto.Enum, values: ~w(automatic bordered bordered_alternating carousel elliptical grouped inset inset_grouped inset_alternating plain sidebar)a end + + def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/move_disabled.ex b/lib/live_view_native_swift_ui/modifiers/lists/move_disabled.ex index 301a5c497..11e0ae37a 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/move_disabled.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/move_disabled.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.MoveDisabled do modifier_schema "move_disabled" do field :is_disabled, :boolean end + + def params(is_disabled) when is_boolean(is_disabled), do: [is_disabled: is_disabled] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/lists/refreshable.ex b/lib/live_view_native_swift_ui/modifiers/lists/refreshable.ex index 82fd03395..af78d39c4 100644 --- a/lib/live_view_native_swift_ui/modifiers/lists/refreshable.ex +++ b/lib/live_view_native_swift_ui/modifiers/lists/refreshable.ex @@ -1,7 +1,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Refreshable do use LiveViewNativePlatform.Modifier - alias LiveViewNativeSwiftUi.Types.Event + alias LiveViewNativePlatform.Types.Event modifier_schema "refreshable" do field :action, Event diff --git a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_action_dismiss_behavior.ex b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_action_dismiss_behavior.ex index cb4cc9020..f786051d1 100644 --- a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_action_dismiss_behavior.ex +++ b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_action_dismiss_behavior.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.MenuActionDismissBehavior do modifier_schema "menu_action_dismiss_behavior" do field(:behavior, Ecto.Enum, values: ~w(automatic enabled disabled)a) end + + def params(behavior) when is_atom(behavior) and not is_boolean(behavior) and not is_nil(behavior), do: [behavior: behavior] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_indicator_visibility.ex b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_indicator_visibility.ex index ace2b15ec..3a3b9b8be 100644 --- a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_indicator_visibility.ex +++ b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_indicator_visibility.ex @@ -1,7 +1,10 @@ defmodule LiveViewNativeSwiftUi.Modifiers.MenuIndicatorVisibility do use LiveViewNativePlatform.Modifier - modifier_schema "menu_indicator_visibility" do + modifier_schema "menu_indicator" do field(:visibility, Ecto.Enum, values: ~w(automatic hidden visible)a) end + + def params(visibility) when is_atom(visibility) and not is_boolean(visibility) and not is_nil(visibility), do: [visibility: visibility] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_order.ex b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_order.ex index 873df7363..e60b3fd21 100644 --- a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_order.ex +++ b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_order.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.MenuOrder do modifier_schema "menu_order" do field(:order, Ecto.Enum, values: ~w(automatic fixed priority)a) end + + def params(order) when is_atom(order) and not is_boolean(order) and not is_nil(order), do: [order: order] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_style.ex b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_style.ex index afa3a00c2..c149ba841 100644 --- a/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_style.ex +++ b/lib/live_view_native_swift_ui/modifiers/menus_and_commands/menu_style.ex @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.MenuStyle do modifier_schema "menu_style" do field(:style, Ecto.Enum, values: ~w(automatic button)a) end + + def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style] + def params(params), do: params end diff --git a/lib/live_view_native_swift_ui/modifiers/text_input_and_output/keyboard_shortcut.ex b/lib/live_view_native_swift_ui/modifiers/text_input_and_output/keyboard_shortcut.ex index f1d0e558f..79ba38c9b 100644 --- a/lib/live_view_native_swift_ui/modifiers/text_input_and_output/keyboard_shortcut.ex +++ b/lib/live_view_native_swift_ui/modifiers/text_input_and_output/keyboard_shortcut.ex @@ -1,7 +1,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.KeyboardShortcut do use LiveViewNativePlatform.Modifier - alias LiveViewNativeSwiftUi.Types.EventModifier + alias LiveViewNativePlatform.Types.EventModifier alias LiveViewNativeSwiftUi.Types.KeyEquivalent modifier_schema "keyboard_shortcut" do diff --git a/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_appear.ex b/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_appear.ex index f41f0b439..df9911eca 100644 --- a/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_appear.ex +++ b/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_appear.ex @@ -1,7 +1,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnAppear do use LiveViewNativePlatform.Modifier - - alias LiveViewNativeSwiftUi.Types.Event + + alias LiveViewNativePlatform.Types.Event modifier_schema "on_appear" do field :action, Event diff --git a/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_disappear.ex b/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_disappear.ex index 787878284..4bf434b9e 100644 --- a/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_disappear.ex +++ b/lib/live_view_native_swift_ui/modifiers/view_fundamentals/on_disappear.ex @@ -1,7 +1,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnDisappear do use LiveViewNativePlatform.Modifier - - alias LiveViewNativeSwiftUi.Types.Event + + alias LiveViewNativePlatform.Types.Event modifier_schema "on_disappear" do field :action, Event diff --git a/lib/live_view_native_swift_ui/types/event.ex b/lib/live_view_native_swift_ui/types/event.ex deleted file mode 100644 index bada53422..000000000 --- a/lib/live_view_native_swift_ui/types/event.ex +++ /dev/null @@ -1,20 +0,0 @@ -defmodule LiveViewNativeSwiftUi.Types.Event do - @derive Jason.Encoder - defstruct [:event, :type, :params, :target, :debounce, :throttle] - - use LiveViewNativePlatform.Modifier.Type - def type, do: :map - - def cast(nil), do: {:ok, nil} - def cast(event) when is_bitstring(event), do: {:ok, %__MODULE__{event: event}} - - def cast(value) when is_map(value) do - value = - value - |> Map.update(:params, Jason.encode!(Map.new()), fn params -> Jason.encode!(params) end) - - {:ok, struct(__MODULE__, value)} - end - - def cast(_), do: :error -end diff --git a/lib/live_view_native_swift_ui/types/event_modifier.ex b/lib/live_view_native_swift_ui/types/event_modifier.ex index c9908b06a..b43925b39 100644 --- a/lib/live_view_native_swift_ui/types/event_modifier.ex +++ b/lib/live_view_native_swift_ui/types/event_modifier.ex @@ -1,4 +1,4 @@ -defmodule LiveViewNativeSwiftUi.Types.EventModifier do +defmodule LiveViewNativePlatform.Types.EventModifier do use LiveViewNativePlatform.Modifier.Type def type, do: {:array, :string}