Unverified Commit 014b441d authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Revert "iOS 16 context menu (#115805)" (#116312)

This reverts commit 1cb16a1e.
parent e9353274
...@@ -5,13 +5,11 @@ ...@@ -5,13 +5,11 @@
import 'dart:collection'; import 'dart:collection';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/foundation.dart' show Brightness, clampDouble; import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'colors.dart';
import 'text_selection_toolbar_button.dart'; import 'text_selection_toolbar_button.dart';
import 'theme.dart';
// Values extracted from https://developer.apple.com/design/resources/. // Values extracted from https://developer.apple.com/design/resources/.
// The height of the toolbar, including the arrow. // The height of the toolbar, including the arrow.
...@@ -31,27 +29,9 @@ const double _kArrowScreenPadding = 26.0; ...@@ -31,27 +29,9 @@ const double _kArrowScreenPadding = 26.0;
// Values extracted from https://developer.apple.com/design/resources/. // Values extracted from https://developer.apple.com/design/resources/.
const Radius _kToolbarBorderRadius = Radius.circular(8); const Radius _kToolbarBorderRadius = Radius.circular(8);
const CupertinoDynamicColor _kToolbarDividerColor = CupertinoDynamicColor.withBrightness( // Colors extracted from https://developer.apple.com/design/resources/.
// This value was extracted from a screenshot of iOS 16.0.3, as light mode // TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
// didn't appear in the Apple design resources assets linked below. const Color _kToolbarDividerColor = Color(0xFF808080);
color: Color(0xFFB6B6B6),
// Color extracted from https://developer.apple.com/design/resources/.
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
darkColor: Color(0xFF808080),
);
// These values were extracted from a screenshot of iOS 16.0.3, as light mode
// didn't appear in the Apple design resources assets linked above.
final BoxDecoration _kToolbarShadow = BoxDecoration(
borderRadius: const BorderRadius.all(_kToolbarBorderRadius),
boxShadow: <BoxShadow>[
BoxShadow(
color: CupertinoColors.black.withOpacity(0.1),
blurRadius: 16.0,
offset: Offset(0, _kToolbarArrowSize.height / 2),
),
],
);
/// The type for a Function that builds a toolbar's container with the given /// The type for a Function that builds a toolbar's container with the given
/// child. /// child.
...@@ -139,23 +119,14 @@ class CupertinoTextSelectionToolbar extends StatelessWidget { ...@@ -139,23 +119,14 @@ class CupertinoTextSelectionToolbar extends StatelessWidget {
// Builds a toolbar just like the default iOS toolbar, with the right color // Builds a toolbar just like the default iOS toolbar, with the right color
// background and a rounded cutout with an arrow. // background and a rounded cutout with an arrow.
static Widget _defaultToolbarBuilder(BuildContext context, Offset anchor, bool isAbove, Widget child) { static Widget _defaultToolbarBuilder(BuildContext context, Offset anchor, bool isAbove, Widget child) {
final Widget outputChild = _CupertinoTextSelectionToolbarShape( return _CupertinoTextSelectionToolbarShape(
anchor: anchor, anchor: anchor,
isAbove: isAbove, isAbove: isAbove,
child: DecoratedBox( child: DecoratedBox(
decoration: const BoxDecoration( decoration: const BoxDecoration(color: _kToolbarDividerColor),
color: _kToolbarDividerColor,
),
child: child, child: child,
), ),
); );
if (CupertinoTheme.brightnessOf(context) == Brightness.dark) {
return outputChild;
}
return DecoratedBox(
decoration: _kToolbarShadow,
child: outputChild,
);
} }
@override @override
...@@ -255,6 +226,7 @@ class _RenderCupertinoTextSelectionToolbarShape extends RenderShiftedBox { ...@@ -255,6 +226,7 @@ class _RenderCupertinoTextSelectionToolbarShape extends RenderShiftedBox {
super.child, super.child,
); );
@override @override
bool get isRepaintBoundary => true; bool get isRepaintBoundary => true;
...@@ -513,7 +485,7 @@ class _CupertinoTextSelectionToolbarContentState extends State<_CupertinoTextSel ...@@ -513,7 +485,7 @@ class _CupertinoTextSelectionToolbarContentState extends State<_CupertinoTextSel
onPressed: _handleNextPage, onPressed: _handleNextPage,
text: '▶', text: '▶',
), ),
nextButtonDisabled: const CupertinoTextSelectionToolbarButton.text( nextButtonDisabled: CupertinoTextSelectionToolbarButton.text(
text: '▶', text: '▶',
), ),
children: widget.children, children: widget.children,
......
...@@ -18,17 +18,7 @@ const TextStyle _kToolbarButtonFontStyle = TextStyle( ...@@ -18,17 +18,7 @@ const TextStyle _kToolbarButtonFontStyle = TextStyle(
// Colors extracted from https://developer.apple.com/design/resources/. // Colors extracted from https://developer.apple.com/design/resources/.
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507. // TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
const CupertinoDynamicColor _kToolbarBackgroundColor = CupertinoDynamicColor.withBrightness( const Color _kToolbarBackgroundColor = Color(0xEB202020);
// This value was extracted from a screenshot of iOS 16.0.3, as light mode
// didn't appear in the Apple design resources assets linked above.
color: Color(0xEB202020),
darkColor: Color(0xEBF7F7F7),
);
const CupertinoDynamicColor _kToolbarTextColor = CupertinoDynamicColor.withBrightness(
color: CupertinoColors.black,
darkColor: CupertinoColors.white,
);
// Eyeballed value. // Eyeballed value.
const EdgeInsets _kToolbarButtonPadding = EdgeInsets.symmetric(vertical: 16.0, horizontal: 18.0); const EdgeInsets _kToolbarButtonPadding = EdgeInsets.symmetric(vertical: 16.0, horizontal: 18.0);
...@@ -43,17 +33,22 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget { ...@@ -43,17 +33,22 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
this.onPressed, this.onPressed,
required Widget this.child, required Widget this.child,
}) : assert(child != null), }) : assert(child != null),
text = null,
buttonItem = null; buttonItem = null;
/// Create an instance of [CupertinoTextSelectionToolbarButton] whose child is /// Create an instance of [CupertinoTextSelectionToolbarButton] whose child is
/// a [Text] widget styled like the default iOS text selection toolbar button. /// a [Text] widget styled like the default iOS text selection toolbar button.
const CupertinoTextSelectionToolbarButton.text({ CupertinoTextSelectionToolbarButton.text({
super.key, super.key,
this.onPressed, this.onPressed,
required this.text, required String text,
}) : buttonItem = null, }) : buttonItem = null,
child = null; child = Text(
text,
overflow: TextOverflow.ellipsis,
style: _kToolbarButtonFontStyle.copyWith(
color: onPressed != null ? CupertinoColors.white : CupertinoColors.inactiveGray,
),
);
/// Create an instance of [CupertinoTextSelectionToolbarButton] from the given /// Create an instance of [CupertinoTextSelectionToolbarButton] from the given
/// [ContextMenuButtonItem]. /// [ContextMenuButtonItem].
...@@ -64,7 +59,6 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget { ...@@ -64,7 +59,6 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
required ContextMenuButtonItem this.buttonItem, required ContextMenuButtonItem this.buttonItem,
}) : assert(buttonItem != null), }) : assert(buttonItem != null),
child = null, child = null,
text = null,
onPressed = buttonItem.onPressed; onPressed = buttonItem.onPressed;
/// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.child} /// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.child}
...@@ -85,10 +79,6 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget { ...@@ -85,10 +79,6 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
/// {@endtemplate} /// {@endtemplate}
final ContextMenuButtonItem? buttonItem; final ContextMenuButtonItem? buttonItem;
/// The text used in the button's label when using
/// [CupertinoTextSelectionToolbarButton.text].
final String? text;
/// Returns the default button label String for the button of the given /// Returns the default button label String for the button of the given
/// [ContextMenuButtonItem]'s [ContextMenuButtonType]. /// [ContextMenuButtonItem]'s [ContextMenuButtonType].
static String getButtonLabel(BuildContext context, ContextMenuButtonItem buttonItem) { static String getButtonLabel(BuildContext context, ContextMenuButtonItem buttonItem) {
...@@ -115,15 +105,12 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget { ...@@ -115,15 +105,12 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget child = this.child ?? Text( final Widget child = this.child ?? Text(
text ?? getButtonLabel(context, buttonItem!), getButtonLabel(context, buttonItem!),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: _kToolbarButtonFontStyle.copyWith( style: _kToolbarButtonFontStyle.copyWith(
color: onPressed != null color: onPressed != null ? CupertinoColors.white : CupertinoColors.inactiveGray,
? _kToolbarTextColor ),
: CupertinoColors.inactiveGray, );
),
);
return CupertinoButton( return CupertinoButton(
borderRadius: null, borderRadius: null,
color: _kToolbarBackgroundColor, color: _kToolbarBackgroundColor,
......
...@@ -1523,11 +1523,7 @@ void main() { ...@@ -1523,11 +1523,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
Text text = tester.widget<Text>(find.text('Paste')); Text text = tester.widget<Text>(find.text('Paste'));
const CupertinoDynamicColor toolbarTextColor = CupertinoDynamicColor.withBrightness( expect(text.style!.color, CupertinoColors.white);
color: CupertinoColors.black,
darkColor: CupertinoColors.white,
);
expect(text.style!.color, toolbarTextColor);
expect(text.style!.fontSize, 14); expect(text.style!.fontSize, 14);
expect(text.style!.letterSpacing, -0.15); expect(text.style!.letterSpacing, -0.15);
expect(text.style!.fontWeight, FontWeight.w400); expect(text.style!.fontWeight, FontWeight.w400);
...@@ -1559,7 +1555,7 @@ void main() { ...@@ -1559,7 +1555,7 @@ void main() {
text = tester.widget<Text>(find.text('Paste')); text = tester.widget<Text>(find.text('Paste'));
// The toolbar buttons' text are still the same style. // The toolbar buttons' text are still the same style.
expect(text.style!.color, toolbarTextColor); expect(text.style!.color, CupertinoColors.white);
expect(text.style!.fontSize, 14); expect(text.style!.fontSize, 14);
expect(text.style!.letterSpacing, -0.15); expect(text.style!.letterSpacing, -0.15);
expect(text.style!.fontWeight, FontWeight.w400); expect(text.style!.fontWeight, FontWeight.w400);
......
...@@ -60,11 +60,6 @@ class TestBox extends SizedBox { ...@@ -60,11 +60,6 @@ class TestBox extends SizedBox {
static const double itemWidth = 100.0; static const double itemWidth = 100.0;
} }
const CupertinoDynamicColor _kToolbarBackgroundColor = CupertinoDynamicColor.withBrightness(
color: Color(0xEB202020),
darkColor: Color(0xEBF7F7F7),
);
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
...@@ -267,40 +262,4 @@ void main() { ...@@ -267,40 +262,4 @@ void main() {
expect(find.text('Paste'), findsNothing); expect(find.text('Paste'), findsNothing);
expect(find.text('Select all'), findsNothing); expect(find.text('Select all'), findsNothing);
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web. }, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
testWidgets('draws dark buttons in dark mode and light button in light mode', (WidgetTester tester) async {
for (final Brightness brightness in Brightness.values) {
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
child: CupertinoTextSelectionToolbar(
anchorAbove: const Offset(100.0, 0.0),
anchorBelow: const Offset(100.0, 0.0),
children: <Widget>[
CupertinoTextSelectionToolbarButton.text(
onPressed: () {},
text: 'Button',
),
],
),
);
},
),
),
),
);
final Finder buttonFinder = find.byType(CupertinoButton);
expect(find.byType(CupertinoButton), findsOneWidget);
final CupertinoButton button = tester.widget(buttonFinder);
expect(
button.color,
_kToolbarBackgroundColor,
);
}
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
} }
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