Преглед изворни кода

Added support for iOS keyboard appearance (#230)

Anatoly Pulyaevskiy пре 5 година
родитељ
комит
cab33e8823
No account linked to committer's email address

+ 1
- 0
packages/zefyr/example/lib/src/full_page.dart Прегледај датотеку

@@ -94,6 +94,7 @@ class _FullPageEditorScreenState extends State<FullPageEditorScreen> {
94 94
             focusNode: _focusNode,
95 95
             mode: _editing ? ZefyrMode.edit : ZefyrMode.select,
96 96
             imageDelegate: CustomImageDelegate(),
97
+            keyboardAppearance: Brightness.dark,
97 98
           ),
98 99
         ),
99 100
       ),

+ 13
- 3
packages/zefyr/lib/src/widgets/editable_text.dart Прегледај датотеку

@@ -40,9 +40,11 @@ class ZefyrEditableText extends StatefulWidget {
40 40
     this.mode = ZefyrMode.edit,
41 41
     this.padding = const EdgeInsets.symmetric(horizontal: 16.0),
42 42
     this.physics,
43
+    this.keyboardAppearance = Brightness.light,
43 44
   })  : assert(mode != null),
44 45
         assert(controller != null),
45 46
         assert(focusNode != null),
47
+        assert(keyboardAppearance != null),
46 48
         super(key: key);
47 49
 
48 50
   /// Controls the document being edited.
@@ -75,6 +77,13 @@ class ZefyrEditableText extends StatefulWidget {
75 77
   /// Padding around editable area.
76 78
   final EdgeInsets padding;
77 79
 
80
+  /// The appearance of the keyboard.
81
+  ///
82
+  /// This setting is only honored on iOS devices.
83
+  ///
84
+  /// If unset, defaults to the brightness of [Brightness.light].
85
+  final Brightness keyboardAppearance;
86
+
78 87
   @override
79 88
   _ZefyrEditableTextState createState() => _ZefyrEditableTextState();
80 89
 }
@@ -103,7 +112,8 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
103 112
   /// keyboard become visible.
104 113
   void requestKeyboard() {
105 114
     if (_focusNode.hasFocus) {
106
-      _input.openConnection(widget.controller.plainTextEditingValue);
115
+      _input.openConnection(
116
+          widget.controller.plainTextEditingValue, widget.keyboardAppearance);
107 117
     } else {
108 118
       FocusScope.of(context).requestFocus(_focusNode);
109 119
     }
@@ -293,8 +303,8 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
293 303
   }
294 304
 
295 305
   void _handleFocusChange() {
296
-    _input.openOrCloseConnection(
297
-        _focusNode, widget.controller.plainTextEditingValue);
306
+    _input.openOrCloseConnection(_focusNode,
307
+        widget.controller.plainTextEditingValue, widget.keyboardAppearance);
298 308
     _cursorTimer.startOrStop(_focusNode, selection);
299 309
     updateKeepAlive();
300 310
   }

+ 13
- 0
packages/zefyr/lib/src/widgets/editor.dart Прегледај датотеку

@@ -27,6 +27,7 @@ class ZefyrEditor extends StatefulWidget {
27 27
     this.imageDelegate,
28 28
     this.selectionControls,
29 29
     this.physics,
30
+    this.keyboardAppearance,
30 31
   })  : assert(mode != null),
31 32
         assert(controller != null),
32 33
         assert(focusNode != null),
@@ -69,6 +70,13 @@ class ZefyrEditor extends StatefulWidget {
69 70
   /// Padding around editable area.
70 71
   final EdgeInsets padding;
71 72
 
73
+  /// The appearance of the keyboard.
74
+  ///
75
+  /// This setting is only honored on iOS devices.
76
+  ///
77
+  /// If unset, defaults to the brightness of [ThemeData.primaryColorBrightness].
78
+  final Brightness keyboardAppearance;
79
+
72 80
   @override
73 81
   _ZefyrEditorState createState() => _ZefyrEditorState();
74 82
 }
@@ -178,6 +186,10 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
178 186
 
179 187
   @override
180 188
   Widget build(BuildContext context) {
189
+    final ThemeData themeData = Theme.of(context);
190
+    final Brightness keyboardAppearance =
191
+        widget.keyboardAppearance ?? themeData.primaryColorBrightness;
192
+
181 193
     Widget editable = ZefyrEditableText(
182 194
       controller: _scope.controller,
183 195
       focusNode: _scope.focusNode,
@@ -187,6 +199,7 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
187 199
       mode: widget.mode,
188 200
       padding: widget.padding,
189 201
       physics: widget.physics,
202
+      keyboardAppearance: keyboardAppearance,
190 203
     );
191 204
 
192 205
     return ZefyrTheme(

+ 9
- 0
packages/zefyr/lib/src/widgets/field.dart Прегледај датотеку

@@ -21,6 +21,13 @@ class ZefyrField extends StatefulWidget {
21 21
   final ZefyrImageDelegate imageDelegate;
22 22
   final ScrollPhysics physics;
23 23
 
24
+  /// The appearance of the keyboard.
25
+  ///
26
+  /// This setting is only honored on iOS devices.
27
+  ///
28
+  /// If unset, defaults to the brightness of [ThemeData.primaryColorBrightness].
29
+  final Brightness keyboardAppearance;
30
+
24 31
   const ZefyrField({
25 32
     Key key,
26 33
     this.decoration,
@@ -32,6 +39,7 @@ class ZefyrField extends StatefulWidget {
32 39
     this.toolbarDelegate,
33 40
     this.imageDelegate,
34 41
     this.physics,
42
+    this.keyboardAppearance,
35 43
   }) : super(key: key);
36 44
 
37 45
   @override
@@ -50,6 +58,7 @@ class _ZefyrFieldState extends State<ZefyrField> {
50 58
       toolbarDelegate: widget.toolbarDelegate,
51 59
       imageDelegate: widget.imageDelegate,
52 60
       physics: widget.physics,
61
+      keyboardAppearance: widget.keyboardAppearance,
53 62
     );
54 63
 
55 64
     if (widget.height != null) {

+ 5
- 3
packages/zefyr/lib/src/widgets/input.dart Прегледај датотеку

@@ -24,15 +24,16 @@ class InputConnectionController implements TextInputClient {
24 24
 
25 25
   /// Opens or closes input connection based on the current state of
26 26
   /// [focusNode] and [value].
27
-  void openOrCloseConnection(FocusNode focusNode, TextEditingValue value) {
27
+  void openOrCloseConnection(FocusNode focusNode, TextEditingValue value,
28
+      Brightness keyboardAppearance) {
28 29
     if (focusNode.hasFocus && focusNode.consumeKeyboardToken()) {
29
-      openConnection(value);
30
+      openConnection(value, keyboardAppearance);
30 31
     } else if (!focusNode.hasFocus) {
31 32
       closeConnection();
32 33
     }
33 34
   }
34 35
 
35
-  void openConnection(TextEditingValue value) {
36
+  void openConnection(TextEditingValue value, Brightness keyboardAppearance) {
36 37
     if (!hasConnection) {
37 38
       _lastKnownRemoteTextEditingValue = value;
38 39
       _textInputConnection = TextInput.attach(
@@ -42,6 +43,7 @@ class InputConnectionController implements TextInputClient {
42 43
           obscureText: false,
43 44
           autocorrect: true,
44 45
           inputAction: TextInputAction.newline,
46
+          keyboardAppearance: keyboardAppearance,
45 47
           textCapitalization: TextCapitalization.sentences,
46 48
         ),
47 49
       )..setEditingState(value);