Unverified Commit f818fbe0 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Update CupertinoActivityIndicator colors and gradient (#42032)

parent c64b236f
fc0d93237ae0c7d27c1b8a07927a35434f1cf4e4
7efcec3e8b0bbb6748a992b23a0a89300aa323c7
......@@ -9,10 +9,11 @@ import 'package:flutter/widgets.dart';
import 'colors.dart';
const double _kDefaultIndicatorRadius = 10.0;
// Extracted from the large activity indicators in https://developer.apple.com/design/resources/.
// Extracted from iOS 13.2 Beta.
const Color _kActiveTickColor = CupertinoDynamicColor.withBrightness(
color: Color(0x99606067),
darkColor: Color(0x99EBEBF5),
color: Color(0xFF3C3C44),
darkColor: Color(0xFFEBEBF5),
);
/// An iOS-style activity indicator that spins clockwise.
......@@ -96,7 +97,10 @@ class _CupertinoActivityIndicatorState extends State<CupertinoActivityIndicator>
const double _kTwoPI = math.pi * 2.0;
const int _kTickCount = 12;
const int _kHalfTickCount = _kTickCount ~/ 2;
// Alpha values extracted from the native component (for both dark and light mode).
// The list has a length of 12.
const List<int> _alphaValues = <int>[147, 131, 114, 97, 81, 64, 47, 47, 47, 47, 47, 47];
class _CupertinoActivityIndicatorPainter extends CustomPainter {
_CupertinoActivityIndicatorPainter({
......@@ -127,8 +131,8 @@ class _CupertinoActivityIndicatorPainter extends CustomPainter {
final int activeTick = (_kTickCount * position.value).floor();
for (int i = 0; i < _kTickCount; ++ i) {
final double t = (((i + activeTick) % _kTickCount) / _kHalfTickCount).clamp(0.0, 1.0);
paint.color = activeColor.withOpacity((t * activeColor.opacity).clamp(0, 1));
final int t = (i + activeTick) % _kTickCount;
paint.color = activeColor.withAlpha(_alphaValues[t]);
canvas.drawRRect(tickFundamentalRRect, paint);
canvas.rotate(-_kTwoPI / _kTickCount);
}
......
......@@ -27,23 +27,46 @@ void main() {
});
testWidgets('Activity indicator dark mode', (WidgetTester tester) async {
final Key key = UniqueKey();
await tester.pumpWidget(
const MediaQuery(
data: MediaQueryData(platformBrightness: Brightness.light),
child: CupertinoActivityIndicator(),
Center(
child: MediaQuery(
data: const MediaQueryData(platformBrightness: Brightness.light),
child: RepaintBoundary(
key: key,
child: Container(
color: CupertinoColors.white,
child: const CupertinoActivityIndicator(animating: false, radius: 35),
),
),
),
),
);
expect(find.byType(CupertinoActivityIndicator), paints..rrect(color: const Color(0x99606067)));
await expectLater(
find.byKey(key),
matchesGoldenFile('activityIndicator.paused.light.png', version: 0),
);
await tester.pumpWidget(
const MediaQuery(
data: MediaQueryData(platformBrightness: Brightness.dark),
child: CupertinoActivityIndicator(),
Center(
child: MediaQuery(
data: const MediaQueryData(platformBrightness: Brightness.dark),
child: RepaintBoundary(
key: key,
child: Container(
color: CupertinoColors.black,
child: const CupertinoActivityIndicator(animating: false, radius: 35),
),
),
),
),
);
expect(find.byType(CupertinoActivityIndicator), paints..rrect(color: const Color(0x99EBEBF5)));
await expectLater(
find.byKey(key),
matchesGoldenFile('activityIndicator.paused.dark.png', version: 0),
);
});
// Regression test for https://github.com/flutter/flutter/issues/41345.
......
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