forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to recognize gestures on text spans
Currently the interface for recognizing gestures on text spans is pretty ugly, but hopefully we can improve it with time. Fixes flutter#156
- Loading branch information
Showing
3 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2015 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/gestures.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('Can tap a hyperlink', () { | ||
testWidgets((WidgetTester tester) { | ||
bool didTapLeft = false; | ||
TapGestureRecognizer tapLeft = new TapGestureRecognizer( | ||
router: Gesturer.instance.pointerRouter, | ||
gestureArena: Gesturer.instance.gestureArena, | ||
onTap: () { | ||
didTapLeft = true; | ||
} | ||
); | ||
|
||
bool didTapRight = false; | ||
TapGestureRecognizer tapRight = new TapGestureRecognizer( | ||
router: Gesturer.instance.pointerRouter, | ||
gestureArena: Gesturer.instance.gestureArena, | ||
onTap: () { | ||
didTapRight = true; | ||
} | ||
); | ||
|
||
Key textKey = new Key('text'); | ||
|
||
tester.pumpWidget( | ||
new Center( | ||
child: new RichText( | ||
key: textKey, | ||
text: new TextSpan( | ||
children: <TextSpan>[ | ||
new TextSpan( | ||
text: 'xxxxxxxx', | ||
recognizer: tapLeft | ||
), | ||
new TextSpan(text: 'yyyyyyyy'), | ||
new TextSpan( | ||
text: 'zzzzzzzzz', | ||
recognizer: tapRight | ||
), | ||
] | ||
) | ||
) | ||
) | ||
); | ||
|
||
Element element = tester.findElementByKey(textKey); | ||
RenderBox box = element.renderObject; | ||
|
||
expect(didTapLeft, isFalse); | ||
expect(didTapRight, isFalse); | ||
|
||
tester.tapAt(box.localToGlobal(Point.origin) + new Offset(2.0, 2.0)); | ||
|
||
expect(didTapLeft, isTrue); | ||
expect(didTapRight, isFalse); | ||
|
||
didTapLeft = false; | ||
|
||
tester.tapAt(box.localToGlobal(Point.origin) + new Offset(30.0, 2.0)); | ||
|
||
expect(didTapLeft, isTrue); | ||
expect(didTapRight, isFalse); | ||
|
||
didTapLeft = false; | ||
|
||
tester.tapAt(box.localToGlobal(new Point(box.size.width, 0.0)) + new Offset(-2.0, 2.0)); | ||
|
||
expect(didTapLeft, isFalse); | ||
expect(didTapRight, isTrue); | ||
}); | ||
}); | ||
} |