Wire up canRequestFocus and skipTraversal in FocusScopeNode (#43013)
This adds a canRequestFocus and skipTraversal argument to FocusScope and FocusScopeNode, so that a scope can prevent being traversed. This allows a fix for a problem in the gallery where the focus while traversing the list of items would sometimes appear to disappear, since it would be focusing things that were in the backdrop that were part of the tree, but were not visible. Related Issues Fixes #42955
This commit is contained in:
@@ -22,6 +22,65 @@ const Cubic _kDecelerateCurve = Cubic(0.23, 0.94, 0.41, 1.0);
|
||||
const double _kPeakVelocityTime = 0.248210;
|
||||
const double _kPeakVelocityProgress = 0.379146;
|
||||
|
||||
class _TappableWhileStatusIs extends StatefulWidget {
|
||||
const _TappableWhileStatusIs(
|
||||
this.status, {
|
||||
Key key,
|
||||
this.controller,
|
||||
this.child,
|
||||
}) : super(key: key);
|
||||
|
||||
final AnimationController controller;
|
||||
final AnimationStatus status;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
_TappableWhileStatusIsState createState() => _TappableWhileStatusIsState();
|
||||
}
|
||||
|
||||
class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
|
||||
bool _active;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.addStatusListener(_handleStatusChange);
|
||||
_active = widget.controller.status == widget.status;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeStatusListener(_handleStatusChange);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleStatusChange(AnimationStatus status) {
|
||||
final bool value = widget.controller.status == widget.status;
|
||||
if (_active != value) {
|
||||
setState(() {
|
||||
_active = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget child = AbsorbPointer(
|
||||
absorbing: !_active,
|
||||
child: widget.child,
|
||||
);
|
||||
|
||||
if (!_active) {
|
||||
child = FocusScope(
|
||||
canRequestFocus: false,
|
||||
debugLabel: '$_TappableWhileStatusIs',
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
class _FrontLayer extends StatelessWidget {
|
||||
const _FrontLayer({
|
||||
Key key,
|
||||
@@ -275,12 +334,20 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
return Stack(
|
||||
key: _backdropKey,
|
||||
children: <Widget>[
|
||||
widget.backLayer,
|
||||
_TappableWhileStatusIs(
|
||||
AnimationStatus.dismissed,
|
||||
controller: _controller,
|
||||
child: widget.backLayer,
|
||||
),
|
||||
PositionedTransition(
|
||||
rect: _layerAnimation,
|
||||
child: _FrontLayer(
|
||||
onTap: _toggleBackdropLayerVisibility,
|
||||
child: widget.frontLayer,
|
||||
child: _TappableWhileStatusIs(
|
||||
AnimationStatus.completed,
|
||||
controller: _controller,
|
||||
child: widget.frontLayer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -66,10 +66,19 @@ class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AbsorbPointer(
|
||||
Widget child = AbsorbPointer(
|
||||
absorbing: !_active,
|
||||
child: widget.child,
|
||||
);
|
||||
|
||||
if (!_active) {
|
||||
child = FocusScope(
|
||||
canRequestFocus: false,
|
||||
debugLabel: '$_TappableWhileStatusIs',
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,10 +284,14 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Visibility(
|
||||
child: widget.backLayer,
|
||||
visible: _controller.status != AnimationStatus.completed,
|
||||
maintainState: true,
|
||||
child: _TappableWhileStatusIs(
|
||||
AnimationStatus.dismissed,
|
||||
controller: _controller,
|
||||
child: Visibility(
|
||||
child: widget.backLayer,
|
||||
visible: _controller.status != AnimationStatus.completed,
|
||||
maintainState: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user