Skip to content

Commit 014b441

Browse files
authored
Revert "iOS 16 context menu (#115805)" (#116312)
This reverts commit 1cb16a1.
1 parent e935327 commit 014b441

File tree

4 files changed

+26
-112
lines changed

4 files changed

+26
-112
lines changed

packages/flutter/lib/src/cupertino/text_selection_toolbar.dart

+8-36
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import 'dart:collection';
66
import 'dart:ui' as ui;
77

8-
import 'package:flutter/foundation.dart' show Brightness, clampDouble;
8+
import 'package:flutter/foundation.dart' show clampDouble;
99
import 'package:flutter/rendering.dart';
1010
import 'package:flutter/widgets.dart';
1111

12-
import 'colors.dart';
1312
import 'text_selection_toolbar_button.dart';
14-
import 'theme.dart';
1513

1614
// Values extracted from https://developer.apple.com/design/resources/.
1715
// The height of the toolbar, including the arrow.
@@ -31,27 +29,9 @@ const double _kArrowScreenPadding = 26.0;
3129
// Values extracted from https://developer.apple.com/design/resources/.
3230
const Radius _kToolbarBorderRadius = Radius.circular(8);
3331

34-
const CupertinoDynamicColor _kToolbarDividerColor = CupertinoDynamicColor.withBrightness(
35-
// This value was extracted from a screenshot of iOS 16.0.3, as light mode
36-
// didn't appear in the Apple design resources assets linked below.
37-
color: Color(0xFFB6B6B6),
38-
// Color extracted from https://developer.apple.com/design/resources/.
39-
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
40-
darkColor: Color(0xFF808080),
41-
);
42-
43-
// These values were extracted from a screenshot of iOS 16.0.3, as light mode
44-
// didn't appear in the Apple design resources assets linked above.
45-
final BoxDecoration _kToolbarShadow = BoxDecoration(
46-
borderRadius: const BorderRadius.all(_kToolbarBorderRadius),
47-
boxShadow: <BoxShadow>[
48-
BoxShadow(
49-
color: CupertinoColors.black.withOpacity(0.1),
50-
blurRadius: 16.0,
51-
offset: Offset(0, _kToolbarArrowSize.height / 2),
52-
),
53-
],
54-
);
32+
// Colors extracted from https://developer.apple.com/design/resources/.
33+
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
34+
const Color _kToolbarDividerColor = Color(0xFF808080);
5535

5636
/// The type for a Function that builds a toolbar's container with the given
5737
/// child.
@@ -139,23 +119,14 @@ class CupertinoTextSelectionToolbar extends StatelessWidget {
139119
// Builds a toolbar just like the default iOS toolbar, with the right color
140120
// background and a rounded cutout with an arrow.
141121
static Widget _defaultToolbarBuilder(BuildContext context, Offset anchor, bool isAbove, Widget child) {
142-
final Widget outputChild = _CupertinoTextSelectionToolbarShape(
122+
return _CupertinoTextSelectionToolbarShape(
143123
anchor: anchor,
144124
isAbove: isAbove,
145125
child: DecoratedBox(
146-
decoration: const BoxDecoration(
147-
color: _kToolbarDividerColor,
148-
),
126+
decoration: const BoxDecoration(color: _kToolbarDividerColor),
149127
child: child,
150128
),
151129
);
152-
if (CupertinoTheme.brightnessOf(context) == Brightness.dark) {
153-
return outputChild;
154-
}
155-
return DecoratedBox(
156-
decoration: _kToolbarShadow,
157-
child: outputChild,
158-
);
159130
}
160131

161132
@override
@@ -255,6 +226,7 @@ class _RenderCupertinoTextSelectionToolbarShape extends RenderShiftedBox {
255226
super.child,
256227
);
257228

229+
258230
@override
259231
bool get isRepaintBoundary => true;
260232

@@ -513,7 +485,7 @@ class _CupertinoTextSelectionToolbarContentState extends State<_CupertinoTextSel
513485
onPressed: _handleNextPage,
514486
text: '▶',
515487
),
516-
nextButtonDisabled: const CupertinoTextSelectionToolbarButton.text(
488+
nextButtonDisabled: CupertinoTextSelectionToolbarButton.text(
517489
text: '▶',
518490
),
519491
children: widget.children,

packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart

+16-29
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,7 @@ const TextStyle _kToolbarButtonFontStyle = TextStyle(
1818

1919
// Colors extracted from https://developer.apple.com/design/resources/.
2020
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
21-
const CupertinoDynamicColor _kToolbarBackgroundColor = CupertinoDynamicColor.withBrightness(
22-
// This value was extracted from a screenshot of iOS 16.0.3, as light mode
23-
// didn't appear in the Apple design resources assets linked above.
24-
color: Color(0xEB202020),
25-
darkColor: Color(0xEBF7F7F7),
26-
);
27-
28-
const CupertinoDynamicColor _kToolbarTextColor = CupertinoDynamicColor.withBrightness(
29-
color: CupertinoColors.black,
30-
darkColor: CupertinoColors.white,
31-
);
21+
const Color _kToolbarBackgroundColor = Color(0xEB202020);
3222

3323
// Eyeballed value.
3424
const EdgeInsets _kToolbarButtonPadding = EdgeInsets.symmetric(vertical: 16.0, horizontal: 18.0);
@@ -43,17 +33,22 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
4333
this.onPressed,
4434
required Widget this.child,
4535
}) : assert(child != null),
46-
text = null,
4736
buttonItem = null;
4837

4938
/// Create an instance of [CupertinoTextSelectionToolbarButton] whose child is
5039
/// a [Text] widget styled like the default iOS text selection toolbar button.
51-
const CupertinoTextSelectionToolbarButton.text({
40+
CupertinoTextSelectionToolbarButton.text({
5241
super.key,
5342
this.onPressed,
54-
required this.text,
43+
required String text,
5544
}) : buttonItem = null,
56-
child = null;
45+
child = Text(
46+
text,
47+
overflow: TextOverflow.ellipsis,
48+
style: _kToolbarButtonFontStyle.copyWith(
49+
color: onPressed != null ? CupertinoColors.white : CupertinoColors.inactiveGray,
50+
),
51+
);
5752

5853
/// Create an instance of [CupertinoTextSelectionToolbarButton] from the given
5954
/// [ContextMenuButtonItem].
@@ -64,7 +59,6 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
6459
required ContextMenuButtonItem this.buttonItem,
6560
}) : assert(buttonItem != null),
6661
child = null,
67-
text = null,
6862
onPressed = buttonItem.onPressed;
6963

7064
/// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.child}
@@ -85,10 +79,6 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
8579
/// {@endtemplate}
8680
final ContextMenuButtonItem? buttonItem;
8781

88-
/// The text used in the button's label when using
89-
/// [CupertinoTextSelectionToolbarButton.text].
90-
final String? text;
91-
9282
/// Returns the default button label String for the button of the given
9383
/// [ContextMenuButtonItem]'s [ContextMenuButtonType].
9484
static String getButtonLabel(BuildContext context, ContextMenuButtonItem buttonItem) {
@@ -115,15 +105,12 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
115105
@override
116106
Widget build(BuildContext context) {
117107
final Widget child = this.child ?? Text(
118-
text ?? getButtonLabel(context, buttonItem!),
119-
overflow: TextOverflow.ellipsis,
120-
style: _kToolbarButtonFontStyle.copyWith(
121-
color: onPressed != null
122-
? _kToolbarTextColor
123-
: CupertinoColors.inactiveGray,
124-
),
125-
);
126-
108+
getButtonLabel(context, buttonItem!),
109+
overflow: TextOverflow.ellipsis,
110+
style: _kToolbarButtonFontStyle.copyWith(
111+
color: onPressed != null ? CupertinoColors.white : CupertinoColors.inactiveGray,
112+
),
113+
);
127114
return CupertinoButton(
128115
borderRadius: null,
129116
color: _kToolbarBackgroundColor,

packages/flutter/test/cupertino/text_field_test.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -1523,11 +1523,7 @@ void main() {
15231523
await tester.pump(const Duration(milliseconds: 200));
15241524

15251525
Text text = tester.widget<Text>(find.text('Paste'));
1526-
const CupertinoDynamicColor toolbarTextColor = CupertinoDynamicColor.withBrightness(
1527-
color: CupertinoColors.black,
1528-
darkColor: CupertinoColors.white,
1529-
);
1530-
expect(text.style!.color, toolbarTextColor);
1526+
expect(text.style!.color, CupertinoColors.white);
15311527
expect(text.style!.fontSize, 14);
15321528
expect(text.style!.letterSpacing, -0.15);
15331529
expect(text.style!.fontWeight, FontWeight.w400);
@@ -1559,7 +1555,7 @@ void main() {
15591555

15601556
text = tester.widget<Text>(find.text('Paste'));
15611557
// The toolbar buttons' text are still the same style.
1562-
expect(text.style!.color, toolbarTextColor);
1558+
expect(text.style!.color, CupertinoColors.white);
15631559
expect(text.style!.fontSize, 14);
15641560
expect(text.style!.letterSpacing, -0.15);
15651561
expect(text.style!.fontWeight, FontWeight.w400);

packages/flutter/test/cupertino/text_selection_toolbar_test.dart

-41
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class TestBox extends SizedBox {
6060
static const double itemWidth = 100.0;
6161
}
6262

63-
const CupertinoDynamicColor _kToolbarBackgroundColor = CupertinoDynamicColor.withBrightness(
64-
color: Color(0xEB202020),
65-
darkColor: Color(0xEBF7F7F7),
66-
);
67-
6863
void main() {
6964
TestWidgetsFlutterBinding.ensureInitialized();
7065

@@ -267,40 +262,4 @@ void main() {
267262
expect(find.text('Paste'), findsNothing);
268263
expect(find.text('Select all'), findsNothing);
269264
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
270-
271-
testWidgets('draws dark buttons in dark mode and light button in light mode', (WidgetTester tester) async {
272-
for (final Brightness brightness in Brightness.values) {
273-
await tester.pumpWidget(
274-
CupertinoApp(
275-
home: Center(
276-
child: Builder(
277-
builder: (BuildContext context) {
278-
return MediaQuery(
279-
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
280-
child: CupertinoTextSelectionToolbar(
281-
anchorAbove: const Offset(100.0, 0.0),
282-
anchorBelow: const Offset(100.0, 0.0),
283-
children: <Widget>[
284-
CupertinoTextSelectionToolbarButton.text(
285-
onPressed: () {},
286-
text: 'Button',
287-
),
288-
],
289-
),
290-
);
291-
},
292-
),
293-
),
294-
),
295-
);
296-
297-
final Finder buttonFinder = find.byType(CupertinoButton);
298-
expect(find.byType(CupertinoButton), findsOneWidget);
299-
final CupertinoButton button = tester.widget(buttonFinder);
300-
expect(
301-
button.color,
302-
_kToolbarBackgroundColor,
303-
);
304-
}
305-
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
306265
}

0 commit comments

Comments
 (0)