Unverified Commit 12ec91a5 authored by Aliaksei Chorny's avatar Aliaksei Chorny Committed by GitHub

The covered child in AnimatedCrossFade should not get touch events (#91349)

parent 15de4aa4
......@@ -342,11 +342,13 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
bottomChild = TickerMode(
key: bottomKey,
enabled: _isTransitioning,
child: ExcludeSemantics( // Always exclude the semantics of the widget that's fading out.
child: ExcludeFocus(
child: FadeTransition(
opacity: bottomAnimation,
child: bottomChild,
child: IgnorePointer(
child: ExcludeSemantics( // Always exclude the semantics of the widget that's fading out.
child: ExcludeFocus(
child: FadeTransition(
opacity: bottomAnimation,
child: bottomChild,
),
),
),
),
......@@ -354,13 +356,16 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
topChild = TickerMode(
key: topKey,
enabled: true, // Top widget always has its animations enabled.
child: ExcludeSemantics(
excluding: false, // Always publish semantics for the widget that's fading in.
child: ExcludeFocus(
excluding: false,
child: FadeTransition(
opacity: topAnimation,
child: topChild,
child: IgnorePointer(
ignoring: false,
child: ExcludeSemantics(
excluding: false, // Always publish semantics for the widget that's fading in.
child: ExcludeFocus(
excluding: false,
child: FadeTransition(
opacity: topAnimation,
child: topChild,
),
),
),
),
......
......@@ -384,6 +384,53 @@ void main() {
await tester.pump();
expect(hiddenNode.hasPrimaryFocus, isFalse);
});
testWidgets('AnimatedCrossFade second child do not receive touch events',
(WidgetTester tester) async {
int numberOfTouchEventNoticed = 0;
Future<void> buildAnimatedFrame(CrossFadeState crossFadeState) {
return tester.pumpWidget(
SizedBox(
width: 300,
height: 600,
child: Directionality(
textDirection: TextDirection.ltr,
child: AnimatedCrossFade(
firstChild: const Text('AAA'),
secondChild: TextButton(
style: TextButton.styleFrom(minimumSize: const Size(double.infinity, 600)),
onPressed: () {
numberOfTouchEventNoticed++;
},
child: const Text('BBB'),
),
crossFadeState: crossFadeState,
duration: const Duration(milliseconds: 50),
),
),
),
);
}
Future<void> touchSecondButton() async {
final TestGesture gestureTouchSecondButton = await tester
.startGesture(const Offset(150, 300));
return gestureTouchSecondButton.up();
}
await buildAnimatedFrame(CrossFadeState.showSecond);
await touchSecondButton();
expect(numberOfTouchEventNoticed, 1);
await buildAnimatedFrame(CrossFadeState.showFirst);
await touchSecondButton();
await touchSecondButton();
expect(numberOfTouchEventNoticed, 1);
});
}
class _TickerWatchingWidget extends StatefulWidget {
......
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