From bef3512d1432718eb7086fad773931bf9de4c346 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 6 May 2020 13:06:02 -0700 Subject: [PATCH] DoubleTap recognizer support and improved error message (#56328) --- .../flutter/lib/src/rendering/paragraph.dart | 5 ++- .../test/rendering/paragraph_test.dart | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index 202af72064..e68b69d3e2 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -916,10 +916,13 @@ class RenderParagraph extends RenderBox if (recognizer is TapGestureRecognizer) { configuration.onTap = recognizer.onTap; configuration.isLink = true; + } else if (recognizer is DoubleTapGestureRecognizer) { + configuration.onTap = recognizer.onDoubleTap; + configuration.isLink = true; } else if (recognizer is LongPressGestureRecognizer) { configuration.onLongPress = recognizer.onLongPress; } else { - assert(false); + assert(false, '${recognizer.runtimeType} is not supported.'); } } final SemanticsNode newChild = (_cachedChildNodes?.isNotEmpty == true) diff --git a/packages/flutter/test/rendering/paragraph_test.dart b/packages/flutter/test/rendering/paragraph_test.dart index 004d1d550d..0f05e78280 100644 --- a/packages/flutter/test/rendering/paragraph_test.dart +++ b/packages/flutter/test/rendering/paragraph_test.dart @@ -417,4 +417,37 @@ void main() { expect(boxes[8], const TextBox.fromLTRBD(14.0, 28.0, 28.0, 42.0 , TextDirection.ltr)); // Ahem-based tests don't yet quite work on Windows or some MacOS environments }, skip: isWindows || isMacOS || isBrowser); + + test('Supports gesture recognizer semantics', () { + final RenderParagraph paragraph = RenderParagraph( + TextSpan(text: _kText, children: [ + TextSpan(text: 'one', recognizer: TapGestureRecognizer()..onTap = () {}), + TextSpan(text: 'two', recognizer: LongPressGestureRecognizer()..onLongPress = () {}), + TextSpan(text: 'three', recognizer: DoubleTapGestureRecognizer()..onDoubleTap = () {}), + ]), + textDirection: TextDirection.rtl, + ); + layout(paragraph); + + paragraph.assembleSemanticsNode(SemanticsNode(), SemanticsConfiguration(), []); + }); + + test('Asserts on unsupported gesture recognizer', () { + final RenderParagraph paragraph = RenderParagraph( + TextSpan(text: _kText, children: [ + TextSpan(text: 'three', recognizer: MultiTapGestureRecognizer()..onTap = (int id) {}), + ]), + textDirection: TextDirection.rtl, + ); + layout(paragraph); + + bool failed = false; + try { + paragraph.assembleSemanticsNode(SemanticsNode(), SemanticsConfiguration(), []); + } catch(e) { + failed = true; + expect(e.message, 'MultiTapGestureRecognizer is not supported.'); + } + expect(failed, true); + }); }