@@ -3,7 +3,13 @@ import UIKit
33
44final class ButtonWidget : WrapperWidget < UIButton > {
55 private let event : UIControl . Event
6-
6+
7+ var canBeFocused : Bool = true
8+
9+ override var canBecomeFocused : Bool {
10+ canBeFocused
11+ }
12+
713 var onTap : ( ( ) -> Void ) ? {
814 didSet {
915 if oldValue == nil {
@@ -33,6 +39,12 @@ final class ButtonWidget: WrapperWidget<UIButton> {
3339final class TextFieldWidget : WrapperWidget < UITextField > , UITextFieldDelegate {
3440 var onChange : ( ( String ) -> Void ) ?
3541 var onSubmit : ( ( ) -> Void ) ?
42+
43+ var canBeFocused : Bool = true
44+
45+ override var canBecomeFocused : Bool {
46+ canBeFocused
47+ }
3648
3749 @objc
3850 func textChanged( ) {
@@ -59,6 +71,12 @@ final class TextFieldWidget: WrapperWidget<UITextField>, UITextFieldDelegate {
5971
6072final class TextEditorWidget : WrapperWidget < UITextView > , UITextViewDelegate {
6173 var onChange : ( ( String ) -> Void ) ?
74+
75+ var canBeFocused : Bool = true
76+
77+ override var canBecomeFocused : Bool {
78+ canBeFocused
79+ }
6280
6381 init ( ) {
6482 super. init ( child: UITextView ( ) )
@@ -73,6 +91,12 @@ final class TextEditorWidget: WrapperWidget<UITextView>, UITextViewDelegate {
7391#if os(tvOS)
7492 final class SwitchWidget : WrapperWidget < UISegmentedControl > {
7593 var onChange : ( ( Bool ) -> Void ) ?
94+
95+ var canBeFocused : Bool = true
96+
97+ override var canBecomeFocused : Bool {
98+ canBeFocused
99+ }
76100
77101 @objc
78102 func switchFlipped( ) {
@@ -97,7 +121,13 @@ final class TextEditorWidget: WrapperWidget<UITextView>, UITextViewDelegate {
97121#else
98122 final class SwitchWidget : WrapperWidget < UISwitch > {
99123 var onChange : ( ( Bool ) -> Void ) ?
100-
124+
125+ var canBeFocused : Bool = true
126+
127+ override var canBecomeFocused : Bool {
128+ canBeFocused
129+ }
130+
101131 @objc
102132 func switchFlipped( ) {
103133 onChange ? ( child. isOn)
@@ -198,9 +228,16 @@ final class HoverableWidget: ContainerWidget {
198228 }
199229 }
200230}
231+
201232@available ( tvOS, unavailable)
202233final class SliderWidget : WrapperWidget < UISlider > {
203234 var onChange : ( ( Double ) -> Void ) ?
235+
236+ var canBeFocused : Bool = true
237+
238+ override var canBecomeFocused : Bool {
239+ canBeFocused
240+ }
204241
205242 private var _decimalPlaces = 17
206243 var decimalPlaces : Int {
@@ -263,11 +300,12 @@ extension UIKitBackend {
263300 action: @escaping ( ) -> Void
264301 ) {
265302 let buttonWidget = button as! ButtonWidget
266-
303+
267304 setButtonTitle ( buttonWidget, label, environment: environment)
268-
305+
269306 buttonWidget. onTap = action
270307 buttonWidget. child. isEnabled = environment. isEnabled
308+ buttonWidget. canBeFocused = environment. isFocusable
271309 }
272310
273311 public func createTextField( ) -> Widget {
@@ -293,6 +331,7 @@ extension UIKitBackend {
293331 let ( keyboardType, contentType) = splitTextContentType ( environment. textContentType)
294332 textFieldWidget. child. keyboardType = keyboardType
295333 textFieldWidget. child. textContentType = contentType
334+ textFieldWidget. canBeFocused = environment. isFocusable
296335
297336 #if os(iOS)
298337 if let updateToolbar = environment. updateToolbar {
@@ -340,6 +379,7 @@ extension UIKitBackend {
340379 let ( keyboardType, contentType) = splitTextContentType ( environment. textContentType)
341380 textEditorWidget. child. keyboardType = keyboardType
342381 textEditorWidget. child. textContentType = contentType
382+ textEditorWidget. canBeFocused = environment. isFocusable
343383
344384 #if os(iOS)
345385 if let updateToolbar = environment. updateToolbar {
@@ -420,6 +460,7 @@ extension UIKitBackend {
420460 let wrapper = switchWidget as! SwitchWidget
421461 wrapper. onChange = onChange
422462 wrapper. child. isEnabled = environment. isEnabled
463+ wrapper. canBeFocused = environment. isFocusable
423464 }
424465
425466 public func setState( ofSwitch switchWidget: Widget , to state: Bool ) {
0 commit comments