Browse Source

fix widget rebuild

lucky1213 4 years ago
parent
commit
fb378b4b9a

+ 1
- 0
packages/zefyr/example/android/gradle.properties View File

@@ -1 +1,2 @@
1 1
 org.gradle.jvmargs=-Xmx1536M
2
+android.enableR8=true

+ 21
- 12
packages/zefyr/lib/src/widgets/buttons.dart View File

@@ -516,8 +516,9 @@ class _ImageButtonState extends State<ImageButton> {
516 516
                             child: FlatButton(
517 517
                                 shape: RoundedRectangleBorder(),
518 518
                                 color: Color(0xFFF6F6F6),
519
-                                onPressed: () async {
520
-                                  List<AssetEntity> imgList = await PhotoPicker.pickAsset(
519
+                                onPressed: () {
520
+                                  toolbar.editor.tapHandle = TapHandle.pickAsset;
521
+                                  PhotoPicker.pickAsset(
521 522
                                     context: context,
522 523
                                     rowCount: 4,
523 524
                                     itemRadio: 1,
@@ -526,8 +527,9 @@ class _ImageButtonState extends State<ImageButton> {
526 527
                                     sortDelegate: SortDelegate.common,
527 528
                                     pickType: PickType.onlyImage,
528 529
                                     photoPathList: null,
529
-                                  );
530
-                                  print(imgList);
530
+                                  ).then((List<AssetEntity> imgList) {
531
+                                    
532
+                                  });
531 533
                                 },
532 534
                                 child: Container(
533 535
                                   child: Column(
@@ -557,14 +559,21 @@ class _ImageButtonState extends State<ImageButton> {
557 559
                       ),
558 560
                     ),
559 561
                     Expanded(
560
-                      child: PhotoPicker.buildGallery(
561
-                        context: context,
562
-                        itemWidth: (toolbar.keyboardHeight - 50) * 0.5,
563
-                        padding: 4,
564
-                        provider: I18nProvider.chinese,
565
-                        sortDelegate: SortDelegate.common,
566
-                        pickType: PickType.onlyImage,
567
-                        photoPathList: null,
562
+                      child: Listener(
563
+                        behavior: HitTestBehavior.translucent,
564
+                        onPointerUp: (PointerUpEvent event) {
565
+                          toolbar.editor.tapHandle = TapHandle.previewImage;
566
+                        },
567
+                        child: PhotoPicker.buildGallery(
568
+                          context: context,
569
+                          padding: 4,
570
+                          thumbSize: 300,
571
+                          itemRadio: 0.5,
572
+                          provider: I18nProvider.chinese,
573
+                          sortDelegate: SortDelegate.common,
574
+                          pickType: PickType.onlyImage,
575
+                          photoPathList: null,
576
+                        ),
568 577
                       ),
569 578
                     ),
570 579
                   ],

+ 10
- 6
packages/zefyr/lib/src/widgets/editable_text.dart View File

@@ -117,11 +117,8 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
117 117
   void requestKeyboard() {
118 118
     final scope = ZefyrScope.of(context);
119 119
     if (_focusNode.hasFocus) {
120
-      var show = scope.toolbarStatus == ToolbarStatus.open ? false : true;
121
-      _input.openConnection(widget.controller.plainTextEditingValue, widget.keyboardAppearance, show: show);
122
-      if (show) {
123
-        print(MediaQuery.of(context).viewInsets.bottom);
124
-      }
120
+      // var show = scope.overlayBuilder == null ? true : false;
121
+      _input.openConnection(widget.controller.plainTextEditingValue, widget.keyboardAppearance, show: _focusNode.consumeKeyboardToken());
125 122
     } else {
126 123
       FocusScope.of(context).requestFocus(_focusNode);
127 124
     }
@@ -310,8 +307,15 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
310 307
   }
311 308
 
312 309
   void _handleFocusChange() {
310
+    final scope = ZefyrScope.of(context);
311
+    var show = true;
312
+    if (_focusNode.consumeKeyboardToken()) {
313
+      show = scope.tapHandle == null;
314
+    } else {
315
+      show = false;
316
+    }
313 317
     _input.openOrCloseConnection(_focusNode,
314
-        widget.controller.plainTextEditingValue, widget.keyboardAppearance, show: !_focusNode.consumeKeyboardToken());
318
+        widget.controller.plainTextEditingValue, widget.keyboardAppearance, show: show);
315 319
     _cursorTimer.startOrStop(_focusNode, selection);
316 320
     updateKeepAlive();
317 321
   }

+ 3
- 3
packages/zefyr/lib/src/widgets/editor.dart View File

@@ -95,14 +95,12 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
95 95
     assert(_toolbarKey == null);
96 96
     _toolbarKey = GlobalKey();
97 97
     _scaffold.showToolbar(buildToolbar);
98
-    _scope.toolbarStatus = ToolbarStatus.show;
99 98
   }
100 99
 
101 100
   void hideToolbar() {
102 101
     if (_toolbarKey == null) return;
103 102
     _scaffold.hideToolbar(buildToolbar);
104 103
     _toolbarKey = null;
105
-    _scope.toolbarStatus = ToolbarStatus.hide;
106 104
   }
107 105
 
108 106
   Widget buildToolbar(BuildContext context) {
@@ -118,7 +116,9 @@ class _ZefyrEditorState extends State<ZefyrEditor> {
118 116
 
119 117
   void _handleChange() {
120 118
     if (_scope.focusOwner == FocusOwner.none) {
121
-      hideToolbar();
119
+      if (_scope.tapHandle == null) {
120
+        hideToolbar();
121
+      }
122 122
     } else if (!hasToolbar) {
123 123
       showToolbar();
124 124
     } else {

+ 0
- 16
packages/zefyr/lib/src/widgets/scaffold.dart View File

@@ -39,22 +39,6 @@ class ZefyrScaffoldState extends State<ZefyrScaffold> {
39 39
   Widget build(BuildContext context) {
40 40
     final toolbar =
41 41
         (_toolbarBuilder == null) ? Container() : _toolbarBuilder(context);
42
-    // return Container(
43
-    //   margin: EdgeInsets.only(
44
-    //     bottom: MediaQuery.of(context).viewInsets.bottom > 0
45
-    //         ? MediaQuery.of(context).viewInsets.bottom
46
-    //         : 0,
47
-    //   ),
48
-    //   child: _ZefyrScaffoldAccess(
49
-    //     scaffold: this,
50
-    //     child: Column(
51
-    //       children: <Widget>[
52
-    //         Expanded(child: widget.child),
53
-    //         toolbar,
54
-    //       ],
55
-    //     ),
56
-    //   ),
57
-    // );
58 42
     return _ZefyrScaffoldAccess(
59 43
         scaffold: this,
60 44
         child: Column(

+ 36
- 12
packages/zefyr/lib/src/widgets/scope.dart View File

@@ -71,22 +71,37 @@ class ZefyrScope extends ChangeNotifier {
71 71
   InputConnectionController _input;
72 72
   InputConnectionController get input => _input;
73 73
 
74
-  ToolbarStatus _toolbarStatus = ToolbarStatus.hide;
75
-  ToolbarStatus get toolbarStatus => _toolbarStatus;
76
-  set toolbarStatus(ToolbarStatus value) {
77
-    if (_toolbarStatus != value) {
78
-      _toolbarStatus = value;
79
-      if (_toolbarStatus == ToolbarStatus.open) {
80
-        hideKeyboard();
81
-      } else if (_toolbarStatus == ToolbarStatus.hide) {
82
-        closeKeyboard();
83
-      } else if (_toolbarStatus == ToolbarStatus.show) {
84
-        showKeyboard();
85
-      }
74
+  TapHandle _tapHandle;
75
+  TapHandle get tapHandle => _tapHandle;
76
+  set tapHandle(TapHandle value) {
77
+    if (_tapHandle != value) {
78
+      _tapHandle = value;
86 79
       notifyListeners();
87 80
     }
88 81
   }
89 82
 
83
+  // ToolbarStatus _toolbarStatus = ToolbarStatus.hide;
84
+  // ToolbarStatus get toolbarStatus => _toolbarStatus;
85
+  // set toolbarStatus(ToolbarStatus value) {
86
+  //   if (_toolbarStatus != value) {
87
+  //     _toolbarStatus = value;
88
+  //     notifyListeners();
89
+  //   }
90
+  // }
91
+
92
+  // WidgetBuilder _overlayBuilder;
93
+  // WidgetBuilder get overlayBuilder => _overlayBuilder;
94
+  // set overlayBuilder(WidgetBuilder builder) {
95
+  //   _overlayBuilder = builder;
96
+  //   if (builder != null) {
97
+  //     hideKeyboard();
98
+  //   } else {
99
+  //     showKeyboard();
100
+  //   }
101
+  //   notifyListeners();
102
+  // }
103
+
104
+
90 105
   ZefyrImageDelegate _imageDelegate;
91 106
   ZefyrImageDelegate get imageDelegate => _imageDelegate;
92 107
   set imageDelegate(ZefyrImageDelegate value) {
@@ -215,18 +230,21 @@ class ZefyrScope extends ChangeNotifier {
215 230
     assert(isEditable);
216 231
     assert(!_disposed);
217 232
     _focusNode.unfocus();
233
+    tapHandle = null;
218 234
   }
219 235
 
220 236
   void showKeyboard() {
221 237
     assert(isEditable);
222 238
     assert(!_disposed);
223 239
     SystemChannels.textInput.invokeMethod('TextInput.show');
240
+    tapHandle = null;
224 241
   }
225 242
 
226 243
   void hideKeyboard() {
227 244
     assert(isEditable);
228 245
     assert(!_disposed);
229 246
     SystemChannels.textInput.invokeMethod('TextInput.hide');
247
+    tapHandle = null;
230 248
   }
231 249
 
232 250
   @override
@@ -283,4 +301,10 @@ enum ToolbarStatus {
283 301
   show,
284 302
   hide,
285 303
   open,
304
+}
305
+
306
+enum TapHandle {
307
+  previewImage,
308
+  pickAsset,
309
+  takePhoto,
286 310
 }

+ 16
- 11
packages/zefyr/lib/src/widgets/toolbar.dart View File

@@ -203,8 +203,8 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
203 203
   double get keyboardHeight => _keyboardHeight;
204 204
 
205 205
   ZefyrToolbarDelegate _delegate;
206
-  AnimationController _overlayAnimation;
207 206
   WidgetBuilder _overlayBuilder;
207
+  AnimationController _overlayAnimation;
208 208
   Completer<void> _overlayCompleter;
209 209
 
210 210
   TextSelection _selection;
@@ -233,7 +233,7 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
233 233
       _overlayCompleter = completer;
234 234
       _overlayAnimation.forward();
235 235
     });
236
-    editor.toolbarStatus = ToolbarStatus.open;
236
+    editor.hideKeyboard();
237 237
     return completer.future;
238 238
   }
239 239
 
@@ -245,7 +245,7 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
245 245
         _overlayCompleter?.complete();
246 246
         _overlayCompleter = null;
247 247
       });
248
-      editor.toolbarStatus = ToolbarStatus.show;
248
+      editor.showKeyboard();
249 249
     });
250 250
   }
251 251
 
@@ -284,7 +284,7 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
284 284
     final theme = ZefyrTheme.of(context).toolbarTheme;
285 285
     
286 286
     final layers = <Widget>[];
287
-    var overlay;
287
+    Widget overlay;
288 288
 
289 289
     // Must set unique key for the toolbar to prevent it from reconstructing
290 290
     // new state each time we toggle overlay.
@@ -296,20 +296,25 @@ class ZefyrToolbarState extends State<ZefyrToolbar>
296 296
     );
297 297
     layers.add(toolbar);
298 298
     if (hasOverlay) {
299
-      Widget widget = Builder(builder: _overlayBuilder);
299
+      Widget widget = Container(
300
+        height: keyboardHeight ?? 300,
301
+        child: Builder(builder: _overlayBuilder),
302
+      );
300 303
       assert(widget != null);
301 304
       overlay = FadeTransition(
302 305
         key: _overlayKey,
303 306
         opacity: _overlayAnimation,
304 307
         child: widget,
305 308
       );
309
+      layers.add(overlay);
310
+    } else {
311
+      layers.add(
312
+        Container(
313
+          height: keyboardHeight ?? 300,
314
+        ),
315
+      );
306 316
     }
307
-    layers.add(
308
-      Container(
309
-        height: keyboardHeight,
310
-        child: overlay,
311
-      ),
312
-    );
317
+    
313 318
 
314 319
     return _ZefyrToolbarScope(
315 320
       toolbar: this,