Skip to content

Commit

Permalink
Add more params impls
Browse files Browse the repository at this point in the history
  • Loading branch information
carson-katri committed Aug 22, 2023
1 parent d8cb34d commit 0ae9e6a
Show file tree
Hide file tree
Showing 80 changed files with 315 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,13 @@ import SwiftUI
/// Hides any element.
///
/// ```html
/// <VStack>
/// <Text modifiers={hidden(@native, is_active: true)}>This text is hidden</Text>
/// <Text modifiers={hidden(@native, is_active: false)}>This text is visible</Text>
/// </VStack>
///
/// ## Arguments
/// * ``isActive``
/// <Text modifiers={hidden()}>This text is hidden</Text>
/// ```
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
struct HiddenModifier: ViewModifier, Decodable {
/// A boolean indicating whether the view should be hidden.
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
private var isActive: Bool

func body(content: Content) -> some View {
if isActive {
content.hidden()
} else {
content
}
content.hidden()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ struct OnAppearModifier: 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.onAppear {
self.action()
self.perform()
}
}

enum CodingKeys: String, CodingKey {
case action
case perform
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ struct OnDisappearModifier: 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.onDisappear {
self.action()
self.perform()
}
}

enum CodingKeys: String, CodingKey {
case action
case perform
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNativeSwiftUi.Modifiers.RenameAction do
use LiveViewNativePlatform.Modifier

alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "rename_action" do
field :action, Event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNativeSwiftUi.Modifiers.DropDestination do
use LiveViewNativePlatform.Modifier

alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "drop_destination" do
field :action, Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnTapGesture do
use LiveViewNativePlatform.Modifier

alias LiveViewNativeSwiftUi.Types.Gesture
alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "gesture" do
field :gesture, Gesture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNativeSwiftUi.Modifiers.OnDeleteCommand do
use LiveViewNativePlatform.Modifier

alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "on_delete_command" do
field :perform, Event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNativeSwiftUi.Modifiers.OnHover do
use LiveViewNativePlatform.Modifier

alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "on_hover" do
field :perform, Event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNativeSwiftUi.Modifiers.OnMoveCommand do
use LiveViewNativePlatform.Modifier

alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "on_move_command" do
field :action, Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.OnSubmit do
use LiveViewNativePlatform.Modifier

alias LiveViewNativeSwiftUi.Types.SubmitTriggers
alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "on_submit" do
field :triggers, SubmitTriggers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNativeSwiftUi.Modifiers.Refreshable do
use LiveViewNativePlatform.Modifier

alias LiveViewNativePlatform.Types.Event
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "refreshable" do
field :action, Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.Alert do

change_event()
end

def params(title, params) when is_binary(title) and is_list(params), do: [{:title, title} | params]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ConfirmationDialog do

change_event()
end

def params(title, params) when is_binary(title) and is_list(params), do: [{:title, title} | params]
def params(params), do: params
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule LiveViewNativeSwiftUi.Modifiers.FullScreenCover do
use LiveViewNativePlatform.Modifier

alias LiveViewNativeSwiftUi.Types.{Event, KeyName}
alias LiveViewNativeSwiftUi.Types.KeyName
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "full_screen_cover" do
field(:is_presented, :boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.InteractiveDismissDisabled do
modifier_schema "interactive_dismiss_disabled" do
field(:disabled, :boolean, default: true)
end

def params(disabled) when is_boolean(disabled), do: [disabled: disabled]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PresentationBackground do

field(:content, KeyName, default: nil)
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PresentationBackgroundInteraction do
field(:mode, Ecto.Enum, values: ~w(automatic disabled enabled)a)
field(:maximum_detent, PresentationDetent, default: nil)
end

def params(mode) when is_atom(mode) and not is_boolean(mode) and not is_nil(mode), do: [mode: mode]
def params({:enabled = mode, [up_through: maximum_detent]}), do: [mode: mode, maximum_detent: maximum_detent]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PresentationContentInteraction do
modifier_schema "presentation_content_interaction" do
field(:interaction, Ecto.Enum, values: ~w(automatic resizes scrolls)a)
end

def params(interaction) when is_atom(interaction) and not is_boolean(interaction) and not is_nil(interaction), do: [interaction: interaction]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PresentationCornerRadius do
modifier_schema "presentation_corner_radius" do
field(:radius, :float)
end

def params(radius) when is_number(radius), do: [radius: radius]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PresentationDetents do

change_event()
end

def params(detents, [selection: selection]), do: [detents: detents, selection: selection]
def params([detent | _] = params) do
with {:ok, _} <- PresentationDetent.cast(detent) do
[detents: params]
else
_ ->
params
end
end
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.PresentationDragIndicator do
modifier_schema "presentation_drag_indicator" 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule LiveViewNativeSwiftUi.Modifiers.Sheet do
use LiveViewNativePlatform.Modifier

alias LiveViewNativeSwiftUi.Types.{Event, KeyName}
alias LiveViewNativeSwiftUi.Types.KeyName
alias LiveViewNativePlatform.Modifier.Types.Event

modifier_schema "sheet" do
field(:is_presented, :boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.NavigationBarBackButtonHidden do
modifier_schema "navigation_bar_back_button_hidden" do
field :hides_back_button, :boolean, default: true
end
end

def params(hides_back_button) when is_boolean(hides_back_button), do: [hides_back_button: hides_back_button]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.NavigationBarTitleDisplayMode do
large
)a)
end

def params(display_mode) when is_atom(display_mode) and not is_boolean(display_mode) and not is_nil(display_mode), do: [display_mode: display_mode]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.NavigationSubtitle do
modifier_schema "navigation_subtitle" do
field :subtitle, :string
end

def params(subtitle) when is_binary(subtitle), do: [subtitle: subtitle]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.NavigationTitle do
modifier_schema "navigation_title" do
field :title, :string
end

def params(title) when is_binary(title), do: [title: title]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.TabItem do
modifier_schema "tab_item" do
field :label, KeyName
end

def params(params) do
with {:ok, _} <- KeyName.cast(params) do
[label: params]
else
_ ->
params
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.TabViewStyle do
modifier_schema "tab_view_style" do
field :style, Ecto.Enum, values: ~w(automatic carousel page page_always page_never)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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ScrollBounceBehavior do
field :behavior, Ecto.Enum, values: ~w(automatic always based_on_size)a
field :axes, Ecto.Enum, values: [:horizontal, :vertical, :all], default: :vertical
end

def params(behavior, params) when is_list(params), do: [{:behavior, behavior} | params]
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ScrollContentBackground do
modifier_schema "scroll_content_background" 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]
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ScrollDisabled do
modifier_schema "scroll_disabled" do
field :disabled, :boolean
end

def params(disabled) when is_boolean(disabled), do: [disabled: disabled]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ScrollDismissesKeyboard do
never
)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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ScrollIndicators do
field :visibility, Ecto.Enum, values: ~w(automatic hidden never visible)a
field :axes, Ecto.Enum, values: [:horizontal, :vertical, :all], default: :all
end

def params(visibility, params) when is_list(params), do: [{:visibility, visibility} | params]
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.FindDisabled do
modifier_schema "find_disabled" do
field :disabled, :boolean, default: true
end

def params(disabled) when is_boolean(disabled), do: [disabled: disabled]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ defmodule LiveViewNativeSwiftUi.Modifiers.ReplaceDisabled do
modifier_schema "replace_disabled" do
field :disabled, :boolean, default: true
end

def params(disabled) when is_boolean(disabled), do: [disabled: disabled]
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ defmodule LiveViewNativeSwiftUi.Modifiers.SearchCompletion do
field :completion, :string
field :token, :string
end

def params(token) when is_atom(token) and not is_boolean(token) and not is_nil(token), do: [token: token]
def params(completion) when is_binary(completion), do: [completion: completion]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ defmodule LiveViewNativeSwiftUi.Modifiers.SearchScopes do

change_event()
end

def params(active, params) when is_list(params), do: [{:active, active} | params]
def params(params), do: params
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ defmodule LiveViewNativeSwiftUi.Modifiers.SearchSuggestions do
modifier_schema "search_suggestions" do
field :suggestions, KeyName
end

def params(params) do
with {:ok, _} <- KeyName.cast(params) do
[suggestions: params]
else
_ ->
params
end
end
end
Loading

0 comments on commit 0ae9e6a

Please sign in to comment.