Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f8c4a6e0
Commit
f8c4a6e0
authored
Jun 19, 2017
by
Jason Simmons
Committed by
GitHub
Jun 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defer the animation of text fields to the caret position (#10782)
Fixes
https://github.com/flutter/flutter/issues/10681
parent
95eba52e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
27 deletions
+23
-27
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+7
-5
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+16
-22
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
f8c4a6e0
...
@@ -460,11 +460,13 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
...
@@ -460,11 +460,13 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
// selection, then scroll the caret into view.
// selection, then scroll the caret into view.
if
(
_textChangedSinceLastCaretUpdate
)
{
if
(
_textChangedSinceLastCaretUpdate
)
{
_textChangedSinceLastCaretUpdate
=
false
;
_textChangedSinceLastCaretUpdate
=
false
;
scheduleMicrotask
(()
{
_scrollController
.
animateTo
(
_scrollController
.
animateTo
(
_getScrollOffsetForCaret
(
caretRect
),
_getScrollOffsetForCaret
(
caretRect
),
curve:
Curves
.
fastOutSlowIn
,
curve:
Curves
.
fastOutSlowIn
,
duration:
const
Duration
(
milliseconds:
50
),
duration:
const
Duration
(
milliseconds:
50
),
);
);
});
}
}
}
}
...
...
packages/flutter/test/material/text_field_test.dart
View file @
f8c4a6e0
...
@@ -38,6 +38,11 @@ Widget overlay(Widget child) {
...
@@ -38,6 +38,11 @@ Widget overlay(Widget child) {
);
);
}
}
Future
<
Null
>
skipPastScrollingAnimation
(
WidgetTester
tester
)
async
{
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
}
void
main
(
)
{
void
main
(
)
{
final
MockClipboard
mockClipboard
=
new
MockClipboard
();
final
MockClipboard
mockClipboard
=
new
MockClipboard
();
SystemChannels
.
platform
.
setMockMethodCallHandler
(
mockClipboard
.
handleMethodCall
);
SystemChannels
.
platform
.
setMockMethodCallHandler
(
mockClipboard
.
handleMethodCall
);
...
@@ -112,8 +117,7 @@ void main() {
...
@@ -112,8 +117,7 @@ void main() {
expect
(
textFieldValue
,
equals
(
testValue
));
expect
(
textFieldValue
,
equals
(
testValue
));
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
});
});
}
}
...
@@ -219,8 +223,7 @@ void main() {
...
@@ -219,8 +223,7 @@ void main() {
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// Tap to reposition the caret.
// Tap to reposition the caret.
final
int
tapIndex
=
testValue
.
indexOf
(
'e'
);
final
int
tapIndex
=
testValue
.
indexOf
(
'e'
);
...
@@ -263,8 +266,7 @@ void main() {
...
@@ -263,8 +266,7 @@ void main() {
expect
(
controller
.
value
.
text
,
testValue
);
expect
(
controller
.
value
.
text
,
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
isCollapsed
,
true
);
...
@@ -299,8 +301,7 @@ void main() {
...
@@ -299,8 +301,7 @@ void main() {
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// Long press the 'e' to select 'def'.
// Long press the 'e' to select 'def'.
final
Offset
ePos
=
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
));
final
Offset
ePos
=
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
));
...
@@ -362,8 +363,7 @@ void main() {
...
@@ -362,8 +363,7 @@ void main() {
final
String
testValue
=
'abc def ghi'
;
final
String
testValue
=
'abc def ghi'
;
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// Tap the selection handle to bring up the "paste / select all" menu.
// Tap the selection handle to bring up the "paste / select all" menu.
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
)));
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
)));
...
@@ -382,8 +382,7 @@ void main() {
...
@@ -382,8 +382,7 @@ void main() {
// COPY should reset the selection.
// COPY should reset the selection.
await
tester
.
tap
(
find
.
text
(
'COPY'
));
await
tester
.
tap
(
find
.
text
(
'COPY'
));
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
isCollapsed
,
true
);
// Tap again to bring back the menu.
// Tap again to bring back the menu.
...
@@ -418,8 +417,7 @@ void main() {
...
@@ -418,8 +417,7 @@ void main() {
final
String
testValue
=
'abc def ghi'
;
final
String
testValue
=
'abc def ghi'
;
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// Tap the selection handle to bring up the "paste / select all" menu.
// Tap the selection handle to bring up the "paste / select all" menu.
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
)));
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
)));
...
@@ -532,8 +530,7 @@ void main() {
...
@@ -532,8 +530,7 @@ void main() {
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValue
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// Check that the text spans multiple lines.
// Check that the text spans multiple lines.
final
Offset
firstPos
=
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'First'
));
final
Offset
firstPos
=
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'First'
));
...
@@ -1340,8 +1337,7 @@ void main() {
...
@@ -1340,8 +1337,7 @@ void main() {
await
tester
.
enterText
(
find
.
byType
(
TextField
),
'a1b
\n
2c3'
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
'a1b
\n
2c3'
);
expect
(
textController
.
text
,
'123'
);
expect
(
textController
.
text
,
'123'
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
'123'
.
indexOf
(
'2'
)));
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
'123'
.
indexOf
(
'2'
)));
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
...
@@ -1382,8 +1378,7 @@ void main() {
...
@@ -1382,8 +1378,7 @@ void main() {
final
String
longText
=
'a'
*
20
;
final
String
longText
=
'a'
*
20
;
await
tester
.
enterText
(
find
.
byType
(
TextField
),
longText
);
await
tester
.
enterText
(
find
.
byType
(
TextField
),
longText
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
ScrollableState
scrollableState
=
tester
.
firstState
(
find
.
byType
(
Scrollable
));
ScrollableState
scrollableState
=
tester
.
firstState
(
find
.
byType
(
Scrollable
));
expect
(
scrollableState
.
position
.
pixels
,
equals
(
0.0
));
expect
(
scrollableState
.
position
.
pixels
,
equals
(
0.0
));
...
@@ -1392,8 +1387,7 @@ void main() {
...
@@ -1392,8 +1387,7 @@ void main() {
// scrolls to make the caret visible.
// scrolls to make the caret visible.
controller
.
selection
=
new
TextSelection
.
collapsed
(
offset:
longText
.
length
);
controller
.
selection
=
new
TextSelection
.
collapsed
(
offset:
longText
.
length
);
await
tester
.
pumpWidget
(
builder
());
await
tester
.
pumpWidget
(
builder
());
// skip past scrolling animation
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
scrollableState
=
tester
.
firstState
(
find
.
byType
(
Scrollable
));
scrollableState
=
tester
.
firstState
(
find
.
byType
(
Scrollable
));
expect
(
scrollableState
.
position
.
pixels
,
isNot
(
equals
(
0.0
)));
expect
(
scrollableState
.
position
.
pixels
,
isNot
(
equals
(
0.0
)));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment