-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Fix text field label animation duration and curve #105966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0775536
090efa4
4cdb0cc
95e9693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ import 'theme_data.dart'; | |
// Examples can assume: | ||
// late Widget _myIcon; | ||
|
||
const Duration _kTransitionDuration = Duration(milliseconds: 200); | ||
// The duration value extracted from: | ||
// https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/TextInputLayout.java | ||
const Duration _kTransitionDuration = Duration(milliseconds: 167); | ||
const Curve _kTransitionCurve = Curves.fastOutSlowIn; | ||
const double _kFinalLabelScale = 0.75; | ||
|
||
|
@@ -192,6 +194,7 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS | |
_borderAnimation = CurvedAnimation( | ||
parent: _controller, | ||
curve: _kTransitionCurve, | ||
reverseCurve: _kTransitionCurve.flipped, | ||
); | ||
_border = _InputBorderTween( | ||
begin: widget.border, | ||
|
@@ -1866,8 +1869,9 @@ class InputDecorator extends StatefulWidget { | |
} | ||
|
||
class _InputDecoratorState extends State<InputDecorator> with TickerProviderStateMixin { | ||
late AnimationController _floatingLabelController; | ||
late AnimationController _shakingLabelController; | ||
late final AnimationController _floatingLabelController; | ||
late final Animation<double> _floatingLabelAnimation; | ||
late final AnimationController _shakingLabelController; | ||
final _InputBorderGap _borderGap = _InputBorderGap(); | ||
|
||
@override | ||
|
@@ -1884,6 +1888,11 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat | |
value: labelIsInitiallyFloating ? 1.0 : 0.0, | ||
); | ||
_floatingLabelController.addListener(_handleChange); | ||
_floatingLabelAnimation = CurvedAnimation( | ||
parent: _floatingLabelController, | ||
curve: _kTransitionCurve, | ||
reverseCurve: _kTransitionCurve.flipped, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super familiar with Android, but from https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/TextInputLayout.java#L4150-L4168, it seems the curve is always Same question for the change made to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the flipped curve is not used for the reverse, the curve actually reversed on unfocus, something like slowOutFastIn. |
||
); | ||
|
||
_shakingLabelController = AnimationController( | ||
duration: _kTransitionDuration, | ||
|
@@ -2161,7 +2170,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat | |
final Widget container = _BorderContainer( | ||
border: border, | ||
gap: _borderGap, | ||
gapAnimation: _floatingLabelController.view, | ||
gapAnimation: _floatingLabelAnimation, | ||
fillColor: _getFillColor(themeData, defaults), | ||
hoverColor: _getHoverColor(themeData), | ||
isHovering: isHovering, | ||
|
@@ -2341,7 +2350,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat | |
isCollapsed: decoration.isCollapsed, | ||
floatingLabelHeight: floatingLabelHeight, | ||
floatingLabelAlignment: decoration.floatingLabelAlignment!, | ||
floatingLabelProgress: _floatingLabelController.value, | ||
floatingLabelProgress: _floatingLabelAnimation.value, | ||
border: border, | ||
borderGap: _borderGap, | ||
alignLabelWithHint: decoration.alignLabelWithHint ?? false, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2380,6 +2380,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec | |
if (!_isDoubleTap) { | ||
widget.onSingleTapUp?.call(details); | ||
_lastTapOffset = details.globalPosition; | ||
_doubleTapTimer?.cancel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change here doesn't seem to be related? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without canceling the old timer, the
Due to reducing the |
||
_doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout); | ||
} | ||
_isDoubleTap = false; | ||
|
Uh oh!
There was an error while loading. Please reload this page.