Skip to content

Commit

Permalink
Convert findNavigator to modifier
Browse files Browse the repository at this point in the history
Closes #329
  • Loading branch information
shadowfacts committed May 19, 2023
1 parent 4e81900 commit 261f710
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// FindNavigatorModifier.swift
// LiveViewNative
//
// Created by Shadowfacts on 5/19/2023.
//

import SwiftUI

/// Controls whether the find navigator is shown.
///
/// Use this modifier with a ``TextEditor``:
///
/// ```html
/// <TextEditor value-binding="my_text" modifiers={find_navigator(@native, is_presented: :show)} />
/// ```
///
/// ## Arguments
/// * ``isPresented``
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
@available(iOS 16.0, *)
struct FindNavigatorModifier: ViewModifier, Decodable {
/// A binding that controls whether the find navigator is shown.
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
@LiveBinding private var isPresented: Bool

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self._isPresented = try LiveBinding(decoding: .isPresented, in: container)
}

func body(content: Content) -> some View {
content
#if os(iOS)
.findNavigator(isPresented: $isPresented)
#endif
}

enum CodingKeys: String, CodingKey {
case isPresented
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import SwiftUI
/// ## Events
/// - ``focusEvent``
/// - ``blurEvent``
/// ## Bindings
/// - ``isFindPresented``
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
Expand All @@ -29,11 +27,6 @@ struct TextEditor: TextFieldProtocol {
@ObservedElement var element: ElementNode
@FormState var value: String?
@FocusState private var isFocused: Bool
/// The `find-presented` attribute is a live binding that controls whether the system find UI is presented.
#if swift(>=5.8)
@_documentation(visibility: public)
#endif
@LiveBinding(attribute: "find-presented") private var isFindPresented = false

/// An event that fires when the text editor is focused.
#if swift(>=5.8)
Expand Down Expand Up @@ -61,7 +54,6 @@ struct TextEditor: TextFieldProtocol {
SwiftUI.TextEditor(text: textBinding)
.focused($isFocused)
#if os(iOS)
.findNavigator(isPresented: $isFindPresented)
.findDisabled(findDisabled)
.replaceDisabled(replaceDisabled)
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule LiveViewNativeSwiftUi.Modifiers.FindNavigator do
use LiveViewNativePlatform.Modifier

alias LiveViewNativeSwiftUi.Types.NativeBindingName

modifier_schema "find_navigator" do
field :is_presented, NativeBindingName
end
end

0 comments on commit 261f710

Please sign in to comment.