-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert find/replace TextEditor attributes to modifiers (#945)
* Convert findNavigator to modifier Closes #329 * Convert findDisabled to modifier Closes #330 * Convert replaceDisabled to modifier Closes #331
- Loading branch information
1 parent
4e81900
commit f3154c8
Showing
7 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Sources/LiveViewNative/Modifiers/Search Modifiers/FindDisabledModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// FindDisabledModifier.swift | ||
// LiveViewNative | ||
// | ||
// Created by Shadowfacts on 5/19/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Controls whether the find navigator is disabled. | ||
/// | ||
/// Use this modifier with a ``TextEditor``: | ||
/// | ||
/// ```html | ||
/// <TextEditor value-binding="my_text" modifiers={find_disabled(@native, disabled: true)} /> | ||
/// ``` | ||
/// | ||
/// ## Arguments | ||
/// * ``disabled`` | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
@available(iOS 16.0, *) | ||
struct FindDisabledModifier: ViewModifier, Decodable { | ||
/// Whether the find navigator is disabled or not. | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
private let disabled: Bool | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
#if os(iOS) | ||
.findDisabled(disabled) | ||
#endif | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Sources/LiveViewNative/Modifiers/Search Modifiers/FindNavigatorModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Sources/LiveViewNative/Modifiers/Search Modifiers/ReplaceDisabledModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// ReplaceDisabledModifier.swift | ||
// LiveViewNative | ||
// | ||
// Created by Shadowfacts on 5/19/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Controls whether the replace is disabled (but not find). | ||
/// | ||
/// Use this modifier with a ``TextEditor``: | ||
/// | ||
/// ```html | ||
/// <TextEditor value-binding="my_text" modifiers={replace_disabled(@native, disabled: true)} /> | ||
/// ``` | ||
/// | ||
/// ## Arguments | ||
/// * ``disabled`` | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
@available(iOS 16.0, *) | ||
struct ReplaceDisabledModifier: ViewModifier, Decodable { | ||
/// Whether the find navigator is disabled or not. | ||
#if swift(>=5.8) | ||
@_documentation(visibility: public) | ||
#endif | ||
private let disabled: Bool | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
#if os(iOS) | ||
.replaceDisabled(disabled) | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
lib/live_view_native_swift_ui/modifiers/search/find_disabled.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule LiveViewNativeSwiftUi.Modifiers.FindDisabled do | ||
use LiveViewNativePlatform.Modifier | ||
|
||
modifier_schema "find_disabled" do | ||
field :disabled, :boolean, default: true | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
lib/live_view_native_swift_ui/modifiers/search/find_navigator.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 7 additions & 0 deletions
7
lib/live_view_native_swift_ui/modifiers/search/replace_disabled.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule LiveViewNativeSwiftUi.Modifiers.ReplaceDisabled do | ||
use LiveViewNativePlatform.Modifier | ||
|
||
modifier_schema "replace_disabled" do | ||
field :disabled, :boolean, default: true | ||
end | ||
end |