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
ca8dbe90
Commit
ca8dbe90
authored
Mar 17, 2016
by
Matt Perry
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2763 from mpcomplete/tabs
Material: Fix selected tab indicator animation.
parents
7e2df440
b20113ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
7 deletions
+29
-7
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+29
-7
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
ca8dbe90
...
@@ -32,6 +32,10 @@ const EdgeInsets _kTabLabelPadding = const EdgeInsets.symmetric(horizontal: 12.0
...
@@ -32,6 +32,10 @@ const EdgeInsets _kTabLabelPadding = const EdgeInsets.symmetric(horizontal: 12.0
const
double
_kTabBarScrollDrag
=
0.025
;
const
double
_kTabBarScrollDrag
=
0.025
;
const
Duration
_kTabBarScroll
=
const
Duration
(
milliseconds:
300
);
const
Duration
_kTabBarScroll
=
const
Duration
(
milliseconds:
300
);
// Curves for the leading and trailing edge of the selected tab indicator.
const
Curve
_kTabIndicatorLeadingCurve
=
const
Interval
(
0.0
,
0.6
,
curve:
Curves
.
easeOut
);
const
Curve
_kTabIndicatorTrailingCurve
=
const
Interval
(
0.3
,
1.0
,
curve:
Curves
.
easeIn
);
// The scrollOffset (velocity) provided to fling() is pixels/ms, and the
// The scrollOffset (velocity) provided to fling() is pixels/ms, and the
// tolerance velocity is pixels/sec.
// tolerance velocity is pixels/sec.
final
double
_kMinFlingVelocity
=
kPixelScrollTolerance
.
velocity
/
2000.0
;
final
double
_kMinFlingVelocity
=
kPixelScrollTolerance
.
velocity
/
2000.0
;
...
@@ -589,9 +593,9 @@ class TabBar<T> extends Scrollable {
...
@@ -589,9 +593,9 @@ class TabBar<T> extends Scrollable {
}
}
class
_TabBarState
<
T
>
extends
ScrollableState
<
TabBar
<
T
>>
implements
TabBarSelectionAnimationListener
{
class
_TabBarState
<
T
>
extends
ScrollableState
<
TabBar
<
T
>>
implements
TabBarSelectionAnimationListener
{
TabBarSelectionState
<
T
>
_selection
;
TabBarSelectionState
<
T
>
_selection
;
bool
_valueIsChanging
=
false
;
bool
_valueIsChanging
=
false
;
int
_lastSelectedIndex
=
-
1
;
void
_initSelection
(
TabBarSelectionState
<
T
>
selection
)
{
void
_initSelection
(
TabBarSelectionState
<
T
>
selection
)
{
_selection
?.
unregisterAnimationListener
(
this
);
_selection
?.
unregisterAnimationListener
(
this
);
...
@@ -645,13 +649,15 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
...
@@ -645,13 +649,15 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
if
(
config
.
labels
.
length
==
0
||
_selection
==
null
)
if
(
config
.
labels
.
length
==
0
||
_selection
==
null
)
return
;
return
;
if
(!
_valueIsChanging
&&
_selection
.
valueIsChanging
)
{
if
(
_lastSelectedIndex
!=
_selection
.
index
)
{
// Initialize our indicator animation when we change selected tabs.
if
(
config
.
isScrollable
)
if
(
config
.
isScrollable
)
scrollTo
(
_centeredTabScrollOffset
(
_selection
.
index
),
duration:
_kTabBarScroll
);
scrollTo
(
_centeredTabScrollOffset
(
_selection
.
index
),
duration:
_kTabBarScroll
);
_indicatorTween
_indicatorTween
..
begin
=
_indicatorRect
??
_tabIndicatorRect
(
_selection
.
previousIndex
)
..
begin
=
_indicatorRect
??
_tabIndicatorRect
(
_selection
.
previousIndex
)
..
end
=
_tabIndicatorRect
(
_selection
.
index
);
..
end
=
_tabIndicatorRect
(
_selection
.
index
);
_valueIsChanging
=
true
;
_valueIsChanging
=
true
;
_lastSelectedIndex
=
_selection
.
index
;
}
}
Rect
oldRect
=
_indicatorRect
;
Rect
oldRect
=
_indicatorRect
;
double
t
=
_selection
.
animation
.
value
;
double
t
=
_selection
.
animation
.
value
;
...
@@ -660,13 +666,29 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
...
@@ -660,13 +666,29 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
// want to curve the animation. When _valueIsChanging is false, we're
// want to curve the animation. When _valueIsChanging is false, we're
// animating based on a pointer event and want linear feedback. It's
// animating based on a pointer event and want linear feedback. It's
// possible we should move this curve into the selection animation.
// possible we should move this curve into the selection animation.
t
=
Curves
.
ease
.
transform
(
t
);
// We animate the leading and trailing edges of the rect differently.
// The easiest way to do this is to lerp 2 rects, and piece them together
// into 1.
Rect
leftRect
,
rightRect
;
if
(
_selection
.
index
>
_selection
.
previousIndex
)
{
// Moving to the right - right edge is leading.
rightRect
=
_indicatorTween
.
lerp
(
_kTabIndicatorLeadingCurve
.
transform
(
t
));
leftRect
=
_indicatorTween
.
lerp
(
_kTabIndicatorTrailingCurve
.
transform
(
t
));
}
else
{
// Moving to the left - left edge is leading.
leftRect
=
_indicatorTween
.
lerp
(
_kTabIndicatorLeadingCurve
.
transform
(
t
));
rightRect
=
_indicatorTween
.
lerp
(
_kTabIndicatorTrailingCurve
.
transform
(
t
));
}
_indicatorRect
=
new
Rect
.
fromLTRB
(
leftRect
.
left
,
leftRect
.
top
,
rightRect
.
right
,
rightRect
.
bottom
);
}
else
{
// TODO(abarth): If we've never gone through handleStatusChange before, we
// might not have set up our _indicatorTween yet.
_indicatorRect
=
_indicatorTween
.
lerp
(
t
);
}
}
// TODO(abarth): If we've never gone through handleStatusChange before, we
// might not have set up our _indicatorTween yet.
_indicatorRect
=
_indicatorTween
.
lerp
(
t
);
if
(
oldRect
!=
_indicatorRect
)
if
(
oldRect
!=
_indicatorRect
)
setState
(()
{
});
setState
(()
{
/* The indicator rect has changed. */
});
}
}
Size
_viewportSize
=
Size
.
zero
;
Size
_viewportSize
=
Size
.
zero
;
...
...
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