Unverified Commit 33e9fd89 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

ImageDecoration.lerp (#130533) (#131349)

This primarily implements DecorationImage.lerp().

It also makes some minor tweaks, the main one of which is defering to dart:ui for `clampDouble` instead of duplicating it in package:foundation.

Fixes https://github.com/flutter/flutter/issues/12452

This was first landed in https://github.com/flutter/flutter/pull/130533 and reverted in https://github.com/flutter/flutter/pull/131347.
parent bb0c3172
......@@ -50,7 +50,7 @@ linter:
- avoid_field_initializers_in_const_classes
# - avoid_final_parameters # incompatible with prefer_final_parameters
- avoid_function_literals_in_foreach_calls
- avoid_implementing_value_types
# - avoid_implementing_value_types # see https://github.com/dart-lang/linter/issues/4558
- avoid_init_to_null
- avoid_js_rounded_ints
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
......
......@@ -34,7 +34,6 @@ export 'src/foundation/diagnostics.dart';
export 'src/foundation/isolates.dart';
export 'src/foundation/key.dart';
export 'src/foundation/licenses.dart';
export 'src/foundation/math.dart';
export 'src/foundation/memory_allocations.dart';
export 'src/foundation/node.dart';
export 'src/foundation/object.dart';
......
......@@ -3,9 +3,9 @@ nothing but core Dart packages. They can't depend on `dart:ui`, they
can't depend on any `package:`, and they can't depend on anything
outside this directory.
Currently they do depend on dart:ui, but only for `VoidCallback` (and
maybe one day `lerpDouble`), which are all intended to be moved out
of `dart:ui` and into `dart:core`.
Currently they do depend on dart:ui, but only for `VoidCallback` and
`clampDouble` (and maybe one day `lerpDouble`), which are all intended
to be moved out of `dart:ui` and into `dart:core`.
There is currently also an unfortunate dependency on the platform
dispatcher logic (SingletonFlutterWindow, Brightness,
......@@ -14,5 +14,4 @@ PlatformDispatcher, window), though that should probably move to the
See also:
* https://github.com/dart-lang/sdk/issues/27791 (`VoidCallback`)
* https://github.com/dart-lang/sdk/issues/25217 (`hashValues`, `hashList`, and `lerpDouble`)
* https://github.com/dart-lang/sdk/issues/25217
......@@ -22,7 +22,7 @@ import 'print.dart';
import 'service_extensions.dart';
import 'timeline.dart';
export 'dart:ui' show PlatformDispatcher, SingletonFlutterWindow; // ignore: deprecated_member_use
export 'dart:ui' show PlatformDispatcher, SingletonFlutterWindow, clampDouble; // ignore: deprecated_member_use
export 'basic_types.dart' show AsyncCallback, AsyncValueGetter, AsyncValueSetter;
......
......@@ -3,13 +3,13 @@
// found in the LICENSE file.
import 'dart:math' as math;
import 'dart:ui' show clampDouble;
import 'package:meta/meta.dart';
import 'assertions.dart';
import 'constants.dart';
import 'debug.dart';
import 'math.dart' show clampDouble;
import 'object.dart';
// Examples can assume:
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Same as [num.clamp] but optimized for non-null [double].
///
/// This is faster because it avoids polymorphism, boxing, and special cases for
/// floating point numbers.
//
// See also: //dev/benchmarks/microbenchmarks/lib/foundation/clamp.dart
double clampDouble(double x, double min, double max) {
assert(min <= max && !max.isNaN && !min.isNaN);
if (x < min) {
return min;
}
if (x > max) {
return max;
}
if (x.isNaN) {
return max;
}
return x;
}
......@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui';
import 'dart:ui' show clampDouble, lerpDouble;
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show clampDouble;
import 'color_scheme.dart';
import 'colors.dart';
......
......@@ -232,7 +232,7 @@ class BoxDecoration extends Decoration {
BoxDecoration scale(double factor) {
return BoxDecoration(
color: Color.lerp(null, color, factor),
image: image, // TODO(ianh): fade the image from transparent
image: DecorationImage.lerp(null, image, factor),
border: BoxBorder.lerp(null, border, factor),
borderRadius: BorderRadiusGeometry.lerp(null, borderRadius, factor),
boxShadow: BoxShadow.lerpList(null, boxShadow, factor),
......@@ -307,7 +307,7 @@ class BoxDecoration extends Decoration {
}
return BoxDecoration(
color: Color.lerp(a.color, b.color, t),
image: t < 0.5 ? a.image : b.image, // TODO(ianh): cross-fade the image
image: DecorationImage.lerp(a.image, b.image, t),
border: BoxBorder.lerp(a.border, b.border, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, b.borderRadius, t),
boxShadow: BoxShadow.lerpList(a.boxShadow, b.boxShadow, t),
......
......@@ -237,7 +237,7 @@ class ShapeDecoration extends Decoration {
return ShapeDecoration(
color: Color.lerp(a?.color, b?.color, t),
gradient: Gradient.lerp(a?.gradient, b?.gradient, t),
image: t < 0.5 ? a?.image : b?.image, // TODO(ianh): cross-fade the image
image: DecorationImage.lerp(a?.image, b?.image, t),
shadows: BoxShadow.lerpList(a?.shadows, b?.shadows, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, t)!,
);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment