Skip to content

Commit

Permalink
[flutter_releases] Flutter stable 2.5.1 Framework Cherrypicks (#90281)
Browse files Browse the repository at this point in the history
* Fix KeyboardManager's synthesization  (#88967)

This PR fixes KeyboardManager's key event synthesization logic, which were dispatching events with incorrect keys, making subsequent key events crash the app.

* Revert clamping scroll simulation changes (#89885)

* Revert "Removed default page transitions for desktop and web platforms. (#82596)" (#89997)

This reverts commit 43e3197

* 'Update Engine revision to b3af521a050e6ef076778bcaf16e27b2521df8f8 for stable release 2.5.1'

* Update dds 2.0.3 -> 2.0.4

* renew cirrus key (#89988)

Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: Darren Austin <darrenaustin@google.com>
Co-authored-by: Christopher Fujino <christopherfujino@gmail.com>
Co-authored-by: keyonghan <54558023+keyonghan@users.noreply.github.com>
  • Loading branch information
6 people authored Sep 17, 2021
1 parent 4cc385b commit ffb2ece
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 381 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment:
# dependency on precisely how Cirrus is detected by our tools.
BOT: "true"

gcp_credentials: ENCRYPTED[!0e63b52bd7e4fda1cd7b7bf2b4fe515a27fadbeaced01f5ad8b699b81d3611ed64c5d3271bcd8426dd914ef41cba48a0!]
gcp_credentials: ENCRYPTED[!48cff44dd32e9cc412d4d381c7fe68d373ca04cf2639f8192d21cb1a9ab5e21129651423a1cf88f3fd7fe2125c1cabd9!]

# LINUX SHARDS
task:
Expand Down
2 changes: 1 addition & 1 deletion bin/internal/engine.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0826da7ef2d301eb8f4ead91aaf026aa2b52881
b3af521a050e6ef076778bcaf16e27b2521df8f8
61 changes: 0 additions & 61 deletions dev/tools/generate_android_spline_data.dart

This file was deleted.

29 changes: 11 additions & 18 deletions packages/flutter/lib/src/material/page_transitions_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,8 @@ class CupertinoPageTransitionsBuilder extends PageTransitionsBuilder {
/// current [PageTransitionsTheme] with `Theme.of(context).pageTransitionsTheme`
/// and delegates to [buildTransitions].
///
/// If a builder for the current [ThemeData.platform] is not found, then
/// no animated transition will occur. The new page will just be displayed
/// immediately.
/// If a builder with a matching platform is not found, then the
/// [FadeUpwardsPageTransitionsBuilder] is used.
///
/// See also:
///
Expand All @@ -564,23 +563,16 @@ class PageTransitionsTheme with Diagnosticable {
/// Constructs an object that selects a transition based on the platform.
///
/// By default the list of builders is: [FadeUpwardsPageTransitionsBuilder]
/// for [TargetPlatform.android] and [TargetPlatform.fuchsia],
/// [CupertinoPageTransitionsBuilder] for [TargetPlatform.iOS], and no
/// animated transition for other platforms or if the app is running on the
/// web.
const PageTransitionsTheme({
Map<TargetPlatform, PageTransitionsBuilder> builders = kIsWeb ? _defaultWebBuilders : _defaultBuilders,
}) : _builders = builders;
/// for [TargetPlatform.android], and [CupertinoPageTransitionsBuilder] for
/// [TargetPlatform.iOS] and [TargetPlatform.macOS].
const PageTransitionsTheme({ Map<TargetPlatform, PageTransitionsBuilder> builders = _defaultBuilders }) : _builders = builders;

static const Map<TargetPlatform, PageTransitionsBuilder> _defaultBuilders = <TargetPlatform, PageTransitionsBuilder>{
// Only have default transitions for mobile platforms
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.fuchsia: FadeUpwardsPageTransitionsBuilder(),
};

static const Map<TargetPlatform, PageTransitionsBuilder> _defaultWebBuilders = <TargetPlatform, PageTransitionsBuilder>{
// By default no page transitions for web apps.
TargetPlatform.linux: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.windows: FadeUpwardsPageTransitionsBuilder(),
};

/// The [PageTransitionsBuilder]s supported by this theme.
Expand All @@ -603,8 +595,9 @@ class PageTransitionsTheme with Diagnosticable {
if (CupertinoRouteTransitionMixin.isPopGestureInProgress(route))
platform = TargetPlatform.iOS;

final PageTransitionsBuilder? matchingBuilder = builders[platform];
return matchingBuilder?.buildTransitions<T>(route, context, animation, secondaryAnimation, child) ?? child;
final PageTransitionsBuilder matchingBuilder =
builders[platform] ?? const FadeUpwardsPageTransitionsBuilder();
return matchingBuilder.buildTransitions<T>(route, context, animation, secondaryAnimation, child);
}

// Just used to the builders Map to a list with one PageTransitionsBuilder per platform
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/services/hardware_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -881,15 +881,15 @@ class KeyEventManager {
for (final PhysicalKeyboardKey key in physicalKeysPressed.difference(_rawKeyboard.physicalKeysPressed)) {
_keyEventsSinceLastMessage.add(KeyUpEvent(
physicalKey: key,
logicalKey: _hardwareKeyboard.lookUpLayout(physicalKey)!,
logicalKey: _hardwareKeyboard.lookUpLayout(key)!,
timeStamp: timeStamp,
synthesized: true,
));
}
for (final PhysicalKeyboardKey key in _rawKeyboard.physicalKeysPressed.difference(physicalKeysPressed)) {
_keyEventsSinceLastMessage.add(KeyDownEvent(
physicalKey: key,
logicalKey: _rawKeyboard.lookUpLayout(physicalKey)!,
logicalKey: _rawKeyboard.lookUpLayout(key)!,
timeStamp: timeStamp,
synthesized: true,
));
Expand Down
208 changes: 41 additions & 167 deletions packages/flutter/lib/src/widgets/scroll_simulation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ class BouncingScrollSimulation extends Simulation {
}
}

const double _inflexion = 0.35;

/// An implementation of scroll physics that matches Android.
///
/// See also:
Expand All @@ -149,9 +147,10 @@ class ClampingScrollSimulation extends Simulation {
required this.velocity,
this.friction = 0.015,
Tolerance tolerance = Tolerance.defaultTolerance,
}) : super(tolerance: tolerance) {
_duration = _splineFlingDuration(velocity);
_distance = _splineFlingDistance(velocity);
}) : assert(_flingVelocityPenetration(0.0) == _initialVelocityPenetration),
super(tolerance: tolerance) {
_duration = _flingDuration(velocity);
_distance = (velocity * _duration / _initialVelocityPenetration).abs();
}

/// The position of the particle at the beginning of the simulation.
Expand All @@ -166,192 +165,67 @@ class ClampingScrollSimulation extends Simulation {
/// The more friction the particle experiences, the sooner it stops.
final double friction;

late int _duration;
late double _duration;
late double _distance;

// See DECELERATION_RATE.
static final double _kDecelerationRate = math.log(0.78) / math.log(0.9);

// See computeDeceleration().
static double _decelerationForFriction(double friction) {
return 9.80665 *
39.37 *
friction *
1.0 * // Flutter operates on logical pixels so the DPI should be 1.0.
160.0;
return friction * 61774.04968;
}

// See getSplineDeceleration().
double _splineDeceleration(double velocity) {
return math.log(_inflexion * velocity.abs() / (friction * _decelerationForFriction(0.84)));
// See getSplineFlingDuration(). Returns a value in seconds.
double _flingDuration(double velocity) {
// See mPhysicalCoeff
final double scaledFriction = friction * _decelerationForFriction(0.84);

// See getSplineDeceleration().
final double deceleration = math.log(0.35 * velocity.abs() / scaledFriction);

return math.exp(deceleration / (_kDecelerationRate - 1.0));
}

// See getSplineFlingDuration().
int _splineFlingDuration(double velocity) {
final double deceleration = _splineDeceleration(velocity);
return (1000 * math.exp(deceleration / (_kDecelerationRate - 1.0))).round();
// Based on a cubic curve fit to the Scroller.computeScrollOffset() values
// produced for an initial velocity of 4000. The value of Scroller.getDuration()
// and Scroller.getFinalY() were 686ms and 961 pixels respectively.
//
// Algebra courtesy of Wolfram Alpha.
//
// f(x) = scrollOffset, x is time in milliseconds
// f(x) = 3.60882×10^-6 x^3 - 0.00668009 x^2 + 4.29427 x - 3.15307
// f(x) = 3.60882×10^-6 x^3 - 0.00668009 x^2 + 4.29427 x, so f(0) is 0
// f(686ms) = 961 pixels
// Scale to f(0 <= t <= 1.0), x = t * 686
// f(t) = 1165.03 t^3 - 3143.62 t^2 + 2945.87 t
// Scale f(t) so that 0.0 <= f(t) <= 1.0
// f(t) = (1165.03 t^3 - 3143.62 t^2 + 2945.87 t) / 961.0
// = 1.2 t^3 - 3.27 t^2 + 3.065 t
static const double _initialVelocityPenetration = 3.065;
static double _flingDistancePenetration(double t) {
return (1.2 * t * t * t) - (3.27 * t * t) + (_initialVelocityPenetration * t);
}

// See getSplineFlingDistance().
double _splineFlingDistance(double velocity) {
final double l = _splineDeceleration(velocity);
final double decelMinusOne = _kDecelerationRate - 1.0;
return friction *
_decelerationForFriction(0.84) *
math.exp(_kDecelerationRate / decelMinusOne * l);
// The derivative of the _flingDistancePenetration() function.
static double _flingVelocityPenetration(double t) {
return (3.6 * t * t) - (6.54 * t) + _initialVelocityPenetration;
}

@override
double x(double time) {
if (time == 0) {
return position;
}
final _NBSample sample = _NBSample(time, _duration);
return position + (sample.distanceCoef * _distance) * velocity.sign;
final double t = (time / _duration).clamp(0.0, 1.0);
return position + _distance * _flingDistancePenetration(t) * velocity.sign;
}

@override
double dx(double time) {
if (time == 0) {
return velocity;
}
final _NBSample sample = _NBSample(time, _duration);
return sample.velocityCoef * _distance / _duration * velocity.sign * 1000.0;
final double t = (time / _duration).clamp(0.0, 1.0);
return _distance * _flingVelocityPenetration(t) * velocity.sign / _duration;
}

@override
bool isDone(double time) {
return time * 1000.0 >= _duration;
}
}

class _NBSample {
_NBSample(double time, int duration) {
// See computeScrollOffset().
final double t = time * 1000.0 / duration;
final int index = (_nbSamples * t).clamp(0, _nbSamples).round();
_distanceCoef = 1.0;
_velocityCoef = 0.0;
if (index < _nbSamples) {
final double tInf = index / _nbSamples;
final double tSup = (index + 1) / _nbSamples;
final double dInf = _splinePosition[index];
final double dSup = _splinePosition[index + 1];
_velocityCoef = (dSup - dInf) / (tSup - tInf);
_distanceCoef = dInf + (t - tInf) * _velocityCoef;
}
return time >= _duration;
}

late double _velocityCoef;
double get velocityCoef => _velocityCoef;

late double _distanceCoef;
double get distanceCoef => _distanceCoef;

static const int _nbSamples = 100;

// Generated from dev/tools/generate_android_spline_data.dart.
static final List<double> _splinePosition = <double>[
0.000022888183591973643,
0.028561000304762274,
0.05705195792956655,
0.08538917797618413,
0.11349556286812107,
0.14129881694635613,
0.16877157254923383,
0.19581093511175632,
0.22239649722992452,
0.24843841866631658,
0.2740024733220569,
0.298967680744136,
0.32333234658228116,
0.34709556909569184,
0.3702249257894571,
0.39272483400399893,
0.41456988647721615,
0.43582889025419114,
0.4564192786416,
0.476410299013587,
0.4957560715637827,
0.5145493169954743,
0.5327205670880077,
0.5502846891191615,
0.5673274324802855,
0.583810881323224,
0.5997478744397482,
0.615194045299478,
0.6301165005270208,
0.6445484042257972,
0.6585198219185201,
0.6720397744233084,
0.6850997688076114,
0.6977281404741683,
0.7099506591298411,
0.7217749311525871,
0.7331784038850426,
0.7442308394229518,
0.7549087205105974,
0.7652471277371271,
0.7752251637549381,
0.7848768260203478,
0.7942056937103814,
0.8032299679689082,
0.8119428702388629,
0.8203713516576219,
0.8285187880808974,
0.8363794492831295,
0.8439768562813565,
0.851322799855549,
0.8584111051351724,
0.8652534074722162,
0.8718525580962131,
0.8782333271742155,
0.8843892099362031,
0.8903155590440985,
0.8960465359221951,
0.9015574505919048,
0.9068736766459904,
0.9119951682409297,
0.9169321898723632,
0.9216747065581234,
0.9262420604674766,
0.9306331858366086,
0.9348476990715433,
0.9389007110754832,
0.9427903495057521,
0.9465220679845756,
0.9500943036519721,
0.9535176728088761,
0.9567898524767604,
0.959924306623116,
0.9629127700159108,
0.9657622101750765,
0.9684818726275105,
0.9710676079044347,
0.9735231939498,
0.9758514437576309,
0.9780599066560445,
0.9801485715370128,
0.9821149805689633,
0.9839677526782791,
0.9857085499421516,
0.9873347811966005,
0.9888547171706613,
0.9902689443512227,
0.9915771042095881,
0.9927840651641069,
0.9938913963715834,
0.9948987305580712,
0.9958114963810524,
0.9966274782266875,
0.997352148697352,
0.9979848677523623,
0.9985285021374979,
0.9989844084453229,
0.9993537595844986,
0.999638729860106,
0.9998403888004533,
0.9999602810470701,
1.0,
];
}
Loading

0 comments on commit ffb2ece

Please sign in to comment.