|
5 | 5 | // Created by Divyesh Vekariya on 22/10/24. |
6 | 6 | // |
7 | 7 |
|
8 | | -//#if iOS || macOS || os(visionOS) |
9 | | -//import SwiftUI |
10 | | -// |
11 | | -///// This struct can configure a ``RichTextKeyboardToolbar``. |
12 | | -//public struct RichTextKeyboardToolbarConfig { |
13 | | -// |
14 | | -// /// Create a custom keyboard toolbar configuration. |
15 | | -// /// |
16 | | -// /// - Parameters: |
17 | | -// /// - alwaysDisplayToolbar: Whether or not to always show the toolbar, by default `false`. |
18 | | -// /// - leadingActions: The leading actions, by default `.undo` and `.redo`. |
19 | | -// /// - trailingActions: The trailing actions, by default `.dismissKeyboard`. |
20 | | -// public init( |
21 | | -// alwaysDisplayToolbar: Bool = false, |
22 | | -// leadingActions: [RichTextAction] = [.undo, .redo], |
23 | | -// trailingActions: [RichTextAction] = [.dismissKeyboard] |
24 | | -// ) { |
25 | | -// self.alwaysDisplayToolbar = alwaysDisplayToolbar |
26 | | -// self.leadingActions = leadingActions |
27 | | -// self.trailingActions = trailingActions |
28 | | -// } |
29 | | -// |
30 | | -// /// Whether or not to always show the toolbar. |
31 | | -// public var alwaysDisplayToolbar: Bool |
32 | | -// |
33 | | -// /// The leading toolbar actions. |
34 | | -// public var leadingActions: [RichTextAction] |
35 | | -// |
36 | | -// /// The trailing toolbar actions. |
37 | | -// public var trailingActions: [RichTextAction] |
38 | | -//} |
39 | | -// |
40 | | -//public extension RichTextKeyboardToolbarConfig { |
41 | | -// |
42 | | -// /// The standard rich text keyboard toolbar config. |
43 | | -// /// |
44 | | -// /// You can override this to change the global default. |
45 | | -// static var standard = RichTextKeyboardToolbarConfig() |
46 | | -//} |
47 | | -// |
48 | | -//public extension View { |
49 | | -// |
50 | | -// /// Apply a ``RichTextKeyboardToolbar`` configuration. |
51 | | -// func richTextKeyboardToolbarConfig( |
52 | | -// _ config: RichTextKeyboardToolbarConfig |
53 | | -// ) -> some View { |
54 | | -// self.environment(\.richTextKeyboardToolbarConfig, config) |
55 | | -// } |
56 | | -//} |
57 | | -// |
58 | | -//private extension RichTextKeyboardToolbarConfig { |
59 | | -// |
60 | | -// struct Key: EnvironmentKey { |
61 | | -// |
62 | | -// public static var defaultValue: RichTextKeyboardToolbarConfig = .standard |
63 | | -// } |
64 | | -//} |
65 | | -// |
66 | | -//public extension EnvironmentValues { |
67 | | -// |
68 | | -// /// This value can bind to a keyboard toolbar config. |
69 | | -// var richTextKeyboardToolbarConfig: RichTextKeyboardToolbarConfig { |
70 | | -// get { self [RichTextKeyboardToolbarConfig.Key.self] } |
71 | | -// set { self [RichTextKeyboardToolbarConfig.Key.self] = newValue } |
72 | | -// } |
73 | | -//} |
74 | | -//#endif |
75 | | -// |
| 8 | +#if iOS || macOS || os(visionOS) |
| 9 | +import SwiftUI |
| 10 | + |
| 11 | +/// This struct can configure a ``RichTextKeyboardToolbar``. |
| 12 | +public struct RichTextKeyboardToolbarConfig { |
| 13 | + |
| 14 | + /// Create a custom keyboard toolbar configuration. |
| 15 | + /// |
| 16 | + /// - Parameters: |
| 17 | + /// - alwaysDisplayToolbar: Whether or not to always show the toolbar, by default `false`. |
| 18 | + /// - leadingActions: The leading actions, by default `.undo` and `.redo`. |
| 19 | + /// - trailingActions: The trailing actions, by default `.dismissKeyboard`. |
| 20 | + public init( |
| 21 | + alwaysDisplayToolbar: Bool = false, |
| 22 | + leadingActions: [RichTextAction] = [.undo, .redo], |
| 23 | + trailingActions: [RichTextAction] = [.dismissKeyboard] |
| 24 | + ) { |
| 25 | + self.alwaysDisplayToolbar = alwaysDisplayToolbar |
| 26 | + self.leadingActions = leadingActions |
| 27 | + self.trailingActions = trailingActions |
| 28 | + } |
| 29 | + |
| 30 | + /// Whether or not to always show the toolbar. |
| 31 | + public var alwaysDisplayToolbar: Bool |
| 32 | + |
| 33 | + /// The leading toolbar actions. |
| 34 | + public var leadingActions: [RichTextAction] |
| 35 | + |
| 36 | + /// The trailing toolbar actions. |
| 37 | + public var trailingActions: [RichTextAction] |
| 38 | +} |
| 39 | + |
| 40 | +public extension RichTextKeyboardToolbarConfig { |
| 41 | + |
| 42 | + /// The standard rich text keyboard toolbar config. |
| 43 | + /// |
| 44 | + /// You can override this to change the global default. |
| 45 | + static var standard = RichTextKeyboardToolbarConfig() |
| 46 | +} |
| 47 | + |
| 48 | +public extension View { |
| 49 | + |
| 50 | + /// Apply a ``RichTextKeyboardToolbar`` configuration. |
| 51 | + func richTextKeyboardToolbarConfig( |
| 52 | + _ config: RichTextKeyboardToolbarConfig |
| 53 | + ) -> some View { |
| 54 | + self.environment(\.richTextKeyboardToolbarConfig, config) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +private extension RichTextKeyboardToolbarConfig { |
| 59 | + |
| 60 | + struct Key: EnvironmentKey { |
| 61 | + |
| 62 | + public static var defaultValue: RichTextKeyboardToolbarConfig = .standard |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +public extension EnvironmentValues { |
| 67 | + |
| 68 | + /// This value can bind to a keyboard toolbar config. |
| 69 | + var richTextKeyboardToolbarConfig: RichTextKeyboardToolbarConfig { |
| 70 | + get { self [RichTextKeyboardToolbarConfig.Key.self] } |
| 71 | + set { self [RichTextKeyboardToolbarConfig.Key.self] = newValue } |
| 72 | + } |
| 73 | +} |
| 74 | +#endif |
| 75 | + |
0 commit comments