Skip to content

Commit 962a487

Browse files
Add more modifier constructors (#991)
* Add constructors for padding modifier * Add background, overlay, grid modifier constructors * Add layout adjustment modifiers * Add constructors for animation modifiers * Add controls and indicators constructors * Apply suggestions from code review Co-authored-by: May Matyi <[email protected]> Signed-off-by: Carson Katri <[email protected]> * Add guards for bool/nil --------- Signed-off-by: Carson Katri <[email protected]> Co-authored-by: May Matyi <[email protected]>
1 parent 8a17e87 commit 962a487

20 files changed

+100
-2
lines changed

lib/live_view_native_swift_ui/modifiers/animation/animation.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Animation do
77
field :animation, Animation
88
field :value, :string
99
end
10+
11+
def params(animation, [value: value]), do: [animation: animation, value: value]
12+
def params(params), do: params
1013
end

lib/live_view_native_swift_ui/modifiers/animation/content_transition.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ContentTransition do
66
modifier_schema "content_transition" do
77
field :transition, ContentTransition
88
end
9+
10+
def params(params) do
11+
with {:ok, _} <- ContentTransition.cast(params) do
12+
[transition: params]
13+
else
14+
_ ->
15+
params
16+
end
17+
end
918
end

lib/live_view_native_swift_ui/modifiers/animation/transition.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Transition do
66
modifier_schema "transition" do
77
field :transition, Transition
88
end
9+
10+
def params(params) do
11+
with {:ok, _} <- Transition.cast(params) do
12+
[transition: params]
13+
else
14+
_ ->
15+
params
16+
end
17+
end
918
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/button_style.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ButtonStyle do
1010
plain
1111
)a)
1212
end
13+
14+
def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style]
15+
def params(params), do: params
1316
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/control_size.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ControlSize do
44
modifier_schema "control_size" do
55
field(:size, Ecto.Enum, values: ~w(mini small regular large)a)
66
end
7+
8+
def params(size) when is_atom(size) and not is_boolean(size) and not is_nil(size), do: [size: size]
9+
def params(params), do: params
710
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/date_picker_style.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DatePickerStyle do
1111
stepper_field
1212
)a)
1313
end
14+
15+
def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style]
16+
def params(params), do: params
1417
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/default_wheel_picker_item_height.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.DefaultWheelPickerItemHeight do
44
modifier_schema "default_wheel_picker_item_height" do
55
field(:height, :float)
66
end
7+
8+
def params(height) when is_number(height), do: [height: height]
9+
def params(params), do: params
710
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/gauge_style.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.GaugeStyle do
1111
accessory_linear
1212
)a)
1313
end
14+
15+
def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style]
16+
def params(params), do: params
1417
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/picker_style.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PickerStyle do
1313
palette
1414
)a)
1515
end
16+
17+
def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style]
18+
def params(params), do: params
1619
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/progress_view_style.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ProgressViewStyle do
88
circular
99
)a)
1010
end
11+
12+
def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style]
13+
def params(params), do: params
1114
end

lib/live_view_native_swift_ui/modifiers/controls_and_indicators/toggle_style.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ToggleStyle do
99
checkbox
1010
)a)
1111
end
12+
13+
def params(style) when is_atom(style) and not is_boolean(style) and not is_nil(style), do: [style: style]
14+
def params(params), do: params
1215
end

lib/live_view_native_swift_ui/modifiers/layout_adjustments/layout_priority.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.LayoutPriority do
44
modifier_schema "layout_priority" do
55
field :value, :float
66
end
7-
end
7+
8+
def params(value) when is_number(value), do: [value: value]
9+
def params(params), do: params
10+
end

lib/live_view_native_swift_ui/modifiers/layout_adjustments/padding.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Padding do
99
field :edges, EdgeSet
1010
field :length, :float
1111
end
12+
13+
def params(), do: []
14+
15+
def params(edges, length) when is_atom(edges) or is_list(edges), do: [edges: edges, length: length]
16+
17+
def params(length) when is_number(length), do: [length: length]
18+
def params(edges) when is_atom(edges) and not is_boolean(edges) and not is_nil(edges), do: [edges: edges]
19+
def params([e | _] = edges) when is_atom(e) and not is_boolean(e) and not is_nil(e), do: [edges: edges]
20+
def params([{k, v} | _] = insets) when is_atom(k) and not is_boolean(k) and not is_nil(k) and is_number(v), do: [insets: insets]
21+
def params(insets) when is_map(insets), do: [insets: insets]
22+
23+
def params(params), do: params
1224
end

lib/live_view_native_swift_ui/modifiers/layout_adjustments/scene_padding.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ScenePadding do
77
field :padding, Ecto.Enum, values: ~w(automatic minimum navigation_bar)a, default: :automatic
88
field :edges, EdgeSet
99
end
10+
11+
def params(padding, [edges: edges]), do: [padding: padding, edges: edges]
12+
def params(padding) when is_atom(padding) and not is_boolean(padding) and not is_nil(padding), do: [padding: padding]
13+
def params(params), do: params
1014
end

lib/live_view_native_swift_ui/modifiers/layout_fundamentals/background.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Background do
2323
field :ignores_safe_area_edges, EdgeSet
2424
field :fill_style, FillStyle
2525
end
26+
27+
def params({type, _} = style, [in: shape, fill_style: fill_style]) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style, shape: shape, fill_style: fill_style]
28+
def params({type, _} = style, [in: shape]) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style, shape: shape]
29+
def params({type, _} = style, [ignores_safe_area_edges: edges]) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style, ignores_safe_area_edges: edges]
30+
def params([in: shape, fill_style: fill_style]), do: [shape: shape, fill_style: fill_style]
31+
def params([in: shape]), do: [shape: shape]
32+
def params({type, _} = style) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style]
33+
def params(params), do: params
2634
end
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
defmodule LiveViewNativeSwiftUi.Modifiers.GridCellAnchor do
22
use LiveViewNativePlatform.Modifier
33

4+
alias LiveViewNativeSwiftUi.Types.UnitPoint
5+
46
modifier_schema "grid_cell_anchor" do
5-
field :anchor, LiveViewNativeSwiftUi.Types.UnitPoint
7+
field :anchor, UnitPoint
8+
end
9+
10+
def params(params) do
11+
with {:ok, _} <- UnitPoint.cast(params) do
12+
[anchor: params]
13+
else
14+
_ ->
15+
params
16+
end
617
end
718
end

lib/live_view_native_swift_ui/modifiers/layout_fundamentals/grid_cell_columns.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.GridCellColumns do
44
modifier_schema "grid_cell_columns" do
55
field :count, :integer
66
end
7+
8+
def params(count) when is_number(count), do: [count: count]
9+
def params(params), do: params
710
end

lib/live_view_native_swift_ui/modifiers/layout_fundamentals/grid_cell_unsized_axes.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.GridCellUnsizedAxes do
44
modifier_schema "grid_cell_unsized_axes" do
55
field :axes, Ecto.Enum, values: [:horizontal, :vertical, :all]
66
end
7+
8+
def params(axes) when is_atom(axes) and not is_boolean(axes) and not is_nil(axes), do: [axes: axes]
9+
def params(params), do: params
710
end

lib/live_view_native_swift_ui/modifiers/layout_fundamentals/grid_column_alignment.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.GridColumnAlignment do
44
modifier_schema "grid_column_alignment" do
55
field :guide, Ecto.Enum, values: [:leading, :center, :trailing]
66
end
7+
8+
def params(guide) when is_atom(guide) and not is_boolean(guide) and not is_nil(guide), do: [guide: guide]
9+
def params(params), do: params
710
end

lib/live_view_native_swift_ui/modifiers/layout_fundamentals/overlay.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Overlay do
2323
field :ignores_safe_area_edges, EdgeSet
2424
field :fill_style, FillStyle
2525
end
26+
27+
def params({type, _} = style, [in: shape, fill_style: fill_style]) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style, shape: shape, fill_style: fill_style]
28+
def params({type, _} = style, [in: shape]) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style, shape: shape]
29+
def params({type, _} = style, [ignores_safe_area_edges: edges]) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style, ignores_safe_area_edges: edges]
30+
def params({type, _} = style) when is_atom(type) and not is_boolean(type) and not is_nil(type), do: [style: style]
31+
def params(params), do: params
2632
end

0 commit comments

Comments
 (0)