Merge pull request #1829 from Hixie/size-obs-2
SizeObserver crusade: drawer
This commit is contained in:
commit
601089ecf1
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
import 'colors.dart';
|
import 'colors.dart';
|
||||||
@ -81,7 +82,7 @@ class DrawerControllerState extends State<DrawerController> {
|
|||||||
|
|
||||||
LocalHistoryEntry _historyEntry;
|
LocalHistoryEntry _historyEntry;
|
||||||
// TODO(abarth): This should be a GlobalValueKey when those exist.
|
// TODO(abarth): This should be a GlobalValueKey when those exist.
|
||||||
GlobalKey get _focusKey => new GlobalObjectKey(config.key);
|
GlobalKey get _drawerKey => new GlobalObjectKey(config.key);
|
||||||
|
|
||||||
void _ensureHistoryEntry() {
|
void _ensureHistoryEntry() {
|
||||||
if (_historyEntry == null) {
|
if (_historyEntry == null) {
|
||||||
@ -89,7 +90,7 @@ class DrawerControllerState extends State<DrawerController> {
|
|||||||
if (route != null) {
|
if (route != null) {
|
||||||
_historyEntry = new LocalHistoryEntry(onRemove: _handleHistoryEntryRemoved);
|
_historyEntry = new LocalHistoryEntry(onRemove: _handleHistoryEntryRemoved);
|
||||||
route.addLocalHistoryEntry(_historyEntry);
|
route.addLocalHistoryEntry(_historyEntry);
|
||||||
Focus.moveScopeTo(_focusKey, context: context);
|
Focus.moveScopeTo(_drawerKey, context: context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,19 +117,20 @@ class DrawerControllerState extends State<DrawerController> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AnimationController _controller;
|
AnimationController _controller;
|
||||||
double _width = _kEdgeDragWidth;
|
|
||||||
|
|
||||||
void _handleSizeChanged(Size newSize) {
|
|
||||||
setState(() {
|
|
||||||
_width = newSize.width;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleTapDown(Point position) {
|
void _handleTapDown(Point position) {
|
||||||
_controller.stop();
|
_controller.stop();
|
||||||
_ensureHistoryEntry();
|
_ensureHistoryEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double get _width {
|
||||||
|
assert(!Scheduler.debugInFrame); // we should never try to read the tree state while building or laying out
|
||||||
|
RenderBox drawerBox = _drawerKey.currentContext?.findRenderObject();
|
||||||
|
if (drawerBox != null)
|
||||||
|
return drawerBox.size.width;
|
||||||
|
return _kWidth; // drawer not being shown currently
|
||||||
|
}
|
||||||
|
|
||||||
void _move(double delta) {
|
void _move(double delta) {
|
||||||
_controller.value += delta / _width;
|
_controller.value += delta / _width;
|
||||||
}
|
}
|
||||||
@ -193,18 +195,15 @@ class DrawerControllerState extends State<DrawerController> {
|
|||||||
child: new Align(
|
child: new Align(
|
||||||
alignment: const FractionalOffset(1.0, 0.5),
|
alignment: const FractionalOffset(1.0, 0.5),
|
||||||
widthFactor: _controller.value,
|
widthFactor: _controller.value,
|
||||||
child: new SizeObserver(
|
|
||||||
onSizeChanged: _handleSizeChanged,
|
|
||||||
child: new RepaintBoundary(
|
child: new RepaintBoundary(
|
||||||
child: new Focus(
|
child: new Focus(
|
||||||
key: _focusKey,
|
key: _drawerKey,
|
||||||
child: config.child
|
child: config.child
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -215,11 +215,12 @@ abstract class Scheduler extends BindingBase {
|
|||||||
_postFrameCallbacks.add(callback);
|
_postFrameCallbacks.add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isInFrame = false;
|
static bool get debugInFrame => _debugInFrame;
|
||||||
|
static bool _debugInFrame = false;
|
||||||
|
|
||||||
void _invokeTransientFrameCallbacks(Duration timeStamp) {
|
void _invokeTransientFrameCallbacks(Duration timeStamp) {
|
||||||
Timeline.startSync('Animate');
|
Timeline.startSync('Animate');
|
||||||
assert(_isInFrame);
|
assert(_debugInFrame);
|
||||||
Map<int, FrameCallback> callbacks = _transientCallbacks;
|
Map<int, FrameCallback> callbacks = _transientCallbacks;
|
||||||
_transientCallbacks = new Map<int, FrameCallback>();
|
_transientCallbacks = new Map<int, FrameCallback>();
|
||||||
callbacks.forEach((int id, FrameCallback callback) {
|
callbacks.forEach((int id, FrameCallback callback) {
|
||||||
@ -239,8 +240,8 @@ abstract class Scheduler extends BindingBase {
|
|||||||
/// [addPostFrameCallback].
|
/// [addPostFrameCallback].
|
||||||
void handleBeginFrame(Duration rawTimeStamp) {
|
void handleBeginFrame(Duration rawTimeStamp) {
|
||||||
Timeline.startSync('Begin frame');
|
Timeline.startSync('Begin frame');
|
||||||
assert(!_isInFrame);
|
assert(!_debugInFrame);
|
||||||
_isInFrame = true;
|
assert(() { _debugInFrame = true; return true; });
|
||||||
Duration timeStamp = new Duration(
|
Duration timeStamp = new Duration(
|
||||||
microseconds: (rawTimeStamp.inMicroseconds / timeDilation).round());
|
microseconds: (rawTimeStamp.inMicroseconds / timeDilation).round());
|
||||||
_hasRequestedABeginFrameCallback = false;
|
_hasRequestedABeginFrameCallback = false;
|
||||||
@ -255,7 +256,7 @@ abstract class Scheduler extends BindingBase {
|
|||||||
for (FrameCallback callback in localPostFrameCallbacks)
|
for (FrameCallback callback in localPostFrameCallbacks)
|
||||||
invokeFrameCallback(callback, timeStamp);
|
invokeFrameCallback(callback, timeStamp);
|
||||||
|
|
||||||
_isInFrame = false;
|
assert(() { _debugInFrame = false; return true; });
|
||||||
Timeline.finishSync();
|
Timeline.finishSync();
|
||||||
|
|
||||||
// All frame-related callbacks have been executed. Run lower-priority tasks.
|
// All frame-related callbacks have been executed. Run lower-priority tasks.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user