Unverified Commit 4e604588 authored by xster's avatar xster Committed by GitHub

Fix front layer can be tapped through bug on gallery (#17181)

parent dba7855d
...@@ -24,8 +24,8 @@ final Tween<BorderRadius> _kFrontHeadingBevelRadius = new BorderRadiusTween( ...@@ -24,8 +24,8 @@ final Tween<BorderRadius> _kFrontHeadingBevelRadius = new BorderRadiusTween(
), ),
); );
class _IgnorePointerWhileStatusIsNot extends StatefulWidget { class _TappableWhileStatusIs extends StatefulWidget {
const _IgnorePointerWhileStatusIsNot(this.status, { const _TappableWhileStatusIs(this.status, {
Key key, Key key,
this.controller, this.controller,
this.child, this.child,
...@@ -36,17 +36,17 @@ class _IgnorePointerWhileStatusIsNot extends StatefulWidget { ...@@ -36,17 +36,17 @@ class _IgnorePointerWhileStatusIsNot extends StatefulWidget {
final Widget child; final Widget child;
@override @override
_IgnorePointerWhileStatusIsNotState createState() => new _IgnorePointerWhileStatusIsNotState(); _TappableWhileStatusIsState createState() => new _TappableWhileStatusIsState();
} }
class _IgnorePointerWhileStatusIsNotState extends State<_IgnorePointerWhileStatusIsNot> { class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
bool _ignoring; bool _active;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
widget.controller.addStatusListener(_handleStatusChange); widget.controller.addStatusListener(_handleStatusChange);
_ignoring = widget.controller.status != widget.status; _active = widget.controller.status == widget.status;
} }
@override @override
...@@ -55,20 +55,24 @@ class _IgnorePointerWhileStatusIsNotState extends State<_IgnorePointerWhileStatu ...@@ -55,20 +55,24 @@ class _IgnorePointerWhileStatusIsNotState extends State<_IgnorePointerWhileStatu
super.dispose(); super.dispose();
} }
void _handleStatusChange(AnimationStatus _) { void _handleStatusChange(AnimationStatus status) {
final bool value = widget.controller.status != widget.status; final bool value = widget.controller.status == widget.status;
if (_ignoring != value) { if (_active != value) {
setState(() { setState(() {
_ignoring = value; _active = value;
}); });
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new IgnorePointer( return new AbsorbPointer(
ignoring: _ignoring, absorbing: !_active,
child: widget.child, // Redundant. TODO(xster): remove after https://github.com/flutter/flutter/issues/17179.
child: new IgnorePointer(
ignoring: !_active,
child: widget.child
),
); );
} }
} }
...@@ -103,26 +107,20 @@ class _CrossFadeTransition extends AnimatedWidget { ...@@ -103,26 +107,20 @@ class _CrossFadeTransition extends AnimatedWidget {
return new Stack( return new Stack(
alignment: alignment, alignment: alignment,
children: <Widget>[ children: <Widget>[
new IgnorePointer( new Opacity(
ignoring: opacity1 < 1.0, opacity: opacity1,
child: new Opacity( child: new Semantics(
opacity: opacity1, scopesRoute: true,
child: new Semantics( explicitChildNodes: true,
scopesRoute: true, child: child1,
explicitChildNodes: true,
child: child1,
),
), ),
), ),
new IgnorePointer( new Opacity(
ignoring: opacity2 < 1.0, opacity: opacity2,
child: new Opacity( child: new Semantics(
opacity: opacity2, scopesRoute: true,
child: new Semantics( explicitChildNodes: true,
scopesRoute: true, child: child0,
explicitChildNodes: true,
child: child0,
),
), ),
), ),
], ],
...@@ -291,7 +289,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin ...@@ -291,7 +289,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
), ),
), ),
new Expanded( new Expanded(
child: new _IgnorePointerWhileStatusIsNot( child: new _TappableWhileStatusIs(
AnimationStatus.dismissed, AnimationStatus.dismissed,
controller: _controller, controller: _controller,
child: widget.backLayer, child: widget.backLayer,
...@@ -316,7 +314,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin ...@@ -316,7 +314,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
child: child, child: child,
); );
}, },
child: new _IgnorePointerWhileStatusIsNot( child: new _TappableWhileStatusIs(
AnimationStatus.completed, AnimationStatus.completed,
controller: _controller, controller: _controller,
child: new FadeTransition( child: new FadeTransition(
......
...@@ -2848,7 +2848,9 @@ class RenderAbsorbPointer extends RenderProxyBox { ...@@ -2848,7 +2848,9 @@ class RenderAbsorbPointer extends RenderProxyBox {
@override @override
bool hitTest(HitTestResult result, { Offset position }) { bool hitTest(HitTestResult result, { Offset position }) {
return absorbing ? true : super.hitTest(result, position: position); return absorbing
? size.contains(position)
: super.hitTest(result, position: position);
} }
@override @override
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
void main() {
testWidgets('AbsorbPointers do not block siblings', (WidgetTester tester) async {
bool tapped = false;
await tester.pumpWidget(
new Column(
children: <Widget>[
new Expanded(
child: new GestureDetector(
onTap: () => tapped = true,
),
),
const Expanded(
child: const AbsorbPointer(
absorbing: true,
),
),
],
),
);
await tester.tap(find.byType(GestureDetector));
expect(tapped, true);
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment