Skip to content

Commit 45e80fd

Browse files
Reverts "Reland Native ios context menu (#143002) (#148238)" (#148254)
Reverts: flutter/flutter#148238 Initiated by: zanderso Reason for reverting: Failures in post submit https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8748025189669617649/+/u/run_test.dart_for_web_canvaskit_tests_shard_and_subshard_3/stdout Original PR Author: justinmc Reviewed By: {hellohuanlin} This change reverts the following previous change: Reland of flutter/flutter#143002, which was reverted in flutter/flutter#148237 due to unresolved docs references. Not sure why those weren't caught in presubmit. ``` dartdoc:stdout: Generating docs for package flutter... dartdoc:stderr: error: unresolved doc reference [TextInput.showSystemContextMenu] dartdoc:stderr: from widgets.MediaQueryData.supportsShowingSystemContextMenu: (file:///b/s/w/ir/x/w/flutter/packages/flutter/lib/src/widgets/media_query.dart:579:14) dartdoc:stderr: in documentation inherited from widgets.MediaQueryData.supportsShowingSystemContextMenu: (file:///b/s/w/ir/x/w/flutter/packages/flutter/lib/src/widgets/media_query.dart:579:14) dartdoc:stderr: error: unresolved doc reference [showSystemContextMenu] dartdoc:stderr: from services.SystemContextMenuController.hide: (file:///b/s/w/ir/x/w/flutter/packages/flutter/lib/src/services/text_input.dart:2554:16) dartdoc:stderr: error: unresolved doc reference [hideSystemContextMenu] dartdoc:stderr: from services.SystemContextMenuController.show: (file:///b/s/w/ir/x/w/flutter/packages/flutter/lib/src/services/text_input.dart:2509:16) ```
1 parent 42b3d9e commit 45e80fd

File tree

13 files changed

+43
-1322
lines changed

13 files changed

+43
-1322
lines changed

examples/api/lib/widgets/system_context_menu/system_context_menu.0.dart

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/api/test/widgets/system_context_menu/system_context_menu.0_test.dart

Lines changed: 0 additions & 67 deletions
This file was deleted.

packages/flutter/lib/src/services/binding.dart

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,15 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
357357

358358
Future<dynamic> _handlePlatformMessage(MethodCall methodCall) async {
359359
final String method = methodCall.method;
360+
assert(method == 'SystemChrome.systemUIChange' || method == 'System.requestAppExit');
360361
switch (method) {
361-
// Called when the system dismisses the system context menu, such as when
362-
// the user taps outside the menu. Not called when Flutter shows a new
363-
// system context menu while an old one is still visible.
364-
case 'ContextMenu.onDismissSystemContextMenu':
365-
for (final SystemContextMenuClient client in _systemContextMenuClients) {
366-
client.handleSystemHide();
367-
}
368362
case 'SystemChrome.systemUIChange':
369363
final List<dynamic> args = methodCall.arguments as List<dynamic>;
370364
if (_systemUiChangeCallback != null) {
371365
await _systemUiChangeCallback!(args[0] as bool);
372366
}
373367
case 'System.requestAppExit':
374368
return <String, dynamic>{'response': (await handleRequestAppExit()).name};
375-
default:
376-
throw AssertionError('Method "$method" not handled.');
377369
}
378370
}
379371

@@ -518,19 +510,6 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
518510
Future<void> initializationComplete() async {
519511
await SystemChannels.platform.invokeMethod('System.initializationComplete');
520512
}
521-
522-
final Set<SystemContextMenuClient> _systemContextMenuClients = <SystemContextMenuClient>{};
523-
524-
/// Registers a [SystemContextMenuClient] that will receive system context
525-
/// menu calls from the engine.
526-
static void registerSystemContextMenuClient(SystemContextMenuClient client) {
527-
instance._systemContextMenuClients.add(client);
528-
}
529-
530-
/// Unregisters a [SystemContextMenuClient] so that it is no longer called.
531-
static void unregisterSystemContextMenuClient(SystemContextMenuClient client) {
532-
instance._systemContextMenuClients.remove(client);
533-
}
534513
}
535514

536515
/// Signature for listening to changes in the [SystemUiMode].
@@ -609,23 +588,3 @@ class _DefaultBinaryMessenger extends BinaryMessenger {
609588
}
610589
}
611590
}
612-
613-
/// An interface to receive calls related to the system context menu from the
614-
/// engine.
615-
///
616-
/// Currently this is only supported on iOS 16+.
617-
///
618-
/// See also:
619-
/// * [SystemContextMenuController], which uses this to provide a fully
620-
/// featured way to control the system context menu.
621-
/// * [MediaQuery.maybeSupportsShowingSystemContextMenu], which indicates
622-
/// whether the system context menu is supported.
623-
/// * [SystemContextMenu], which provides a widget interface for displaying the
624-
/// system context menu.
625-
mixin SystemContextMenuClient {
626-
/// Handles the system hiding a context menu.
627-
///
628-
/// This is called for all instances of [SystemContextMenuController], so it's
629-
/// not guaranteed that this instance was the one that was hidden.
630-
void handleSystemHide();
631-
}

packages/flutter/lib/src/services/text_input.dart

Lines changed: 1 addition & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import 'package:flutter/foundation.dart';
1717
import 'package:vector_math/vector_math_64.dart' show Matrix4;
1818

1919
import 'autofill.dart';
20-
import 'binding.dart';
2120
import 'clipboard.dart' show Clipboard;
2221
import 'keyboard_inserted_content.dart';
2322
import 'message_codec.dart';
@@ -1809,7 +1808,7 @@ class TextInput {
18091808

18101809
Future<dynamic> _handleTextInputInvocation(MethodCall methodCall) async {
18111810
final String method = methodCall.method;
1812-
switch (method) {
1811+
switch (methodCall.method) {
18131812
case 'TextInputClient.focusElement':
18141813
final List<dynamic> args = methodCall.arguments as List<dynamic>;
18151814
_scribbleClients[args[0]]?.onScribbleFocus(Offset((args[1] as num).toDouble(), (args[2] as num).toDouble()));
@@ -2404,178 +2403,3 @@ class _PlatformTextInputControl with TextInputControl {
24042403
);
24052404
}
24062405
}
2407-
2408-
/// Allows access to the system context menu.
2409-
///
2410-
/// The context menu is the menu that appears, for example, when doing text
2411-
/// selection. Flutter typically draws this menu itself, but this class deals
2412-
/// with the platform-rendered context menu.
2413-
///
2414-
/// Only one instance can be visible at a time. Calling [show] while the system
2415-
/// context menu is already visible will hide it and show it again at the new
2416-
/// [Rect]. An instance that is hidden is informed via [onSystemHide].
2417-
///
2418-
/// Currently this system context menu is bound to text input. The buttons that
2419-
/// are shown and the actions they perform are dependent on the currently
2420-
/// active [TextInputConnection]. Using this without an active
2421-
/// [TextInputConnection] is a noop.
2422-
///
2423-
/// Call [dispose] when no longer needed.
2424-
///
2425-
/// See also:
2426-
///
2427-
/// * [ContextMenuController], which controls Flutter-drawn context menus.
2428-
/// * [SystemContextMenu], which wraps this functionality in a widget.
2429-
/// * [MediaQuery.maybeSupportsShowingSystemContextMenu], which indicates
2430-
/// whether the system context menu is supported.
2431-
class SystemContextMenuController with SystemContextMenuClient {
2432-
/// Creates an instance of [SystemContextMenuController].
2433-
///
2434-
/// Not shown until [show] is called.
2435-
SystemContextMenuController({
2436-
this.onSystemHide,
2437-
}) {
2438-
ServicesBinding.registerSystemContextMenuClient(this);
2439-
}
2440-
2441-
/// Called when the system has hidden the context menu.
2442-
///
2443-
/// For example, tapping outside of the context menu typically causes the
2444-
/// system to hide it directly. Flutter is made aware that the context menu is
2445-
/// no longer visible through this callback.
2446-
///
2447-
/// This is not called when [show]ing a new system context menu causes another
2448-
/// to be hidden.
2449-
final VoidCallback? onSystemHide;
2450-
2451-
static const MethodChannel _channel = SystemChannels.platform;
2452-
2453-
static SystemContextMenuController? _lastShown;
2454-
2455-
/// The target [Rect] that was last given to [show].
2456-
///
2457-
/// Null if [show] has not been called.
2458-
Rect? _lastTargetRect;
2459-
2460-
/// True when the instance most recently [show]n has been hidden by the
2461-
/// system.
2462-
bool _hiddenBySystem = false;
2463-
2464-
bool get _isVisible => this == _lastShown && !_hiddenBySystem;
2465-
2466-
/// After calling [dispose], this instance can no longer be used.
2467-
bool _isDisposed = false;
2468-
2469-
// Begin SystemContextMenuClient.
2470-
2471-
@override
2472-
void handleSystemHide() {
2473-
assert(!_isDisposed);
2474-
// If this instance wasn't being shown, then it wasn't the instance that was
2475-
// hidden.
2476-
if (!_isVisible) {
2477-
return;
2478-
}
2479-
if (_lastShown == this) {
2480-
_lastShown = null;
2481-
}
2482-
_hiddenBySystem = true;
2483-
onSystemHide?.call();
2484-
}
2485-
2486-
// End SystemContextMenuClient.
2487-
2488-
/// Shows the system context menu anchored on the given [Rect].
2489-
///
2490-
/// The [Rect] represents what the context menu is pointing to. For example,
2491-
/// for some text selection, this would be the selection [Rect].
2492-
///
2493-
/// There can only be one system context menu visible at a time. Calling this
2494-
/// while another system context menu is already visible will remove the old
2495-
/// menu before showing the new menu.
2496-
///
2497-
/// Currently this system context menu is bound to text input. The buttons
2498-
/// that are shown and the actions they perform are dependent on the
2499-
/// currently active [TextInputConnection]. Using this without an active
2500-
/// [TextInputConnection] will be a noop.
2501-
///
2502-
/// This is only supported on iOS 16.0 and later.
2503-
///
2504-
/// See also:
2505-
///
2506-
/// * [hide], which hides the menu shown by this method.
2507-
/// * [MediaQuery.supportsShowingSystemContextMenu], which indicates whether
2508-
/// this method is supported on the current platform.
2509-
Future<void> show(Rect targetRect) {
2510-
assert(!_isDisposed);
2511-
assert(
2512-
TextInput._instance._currentConnection != null,
2513-
'Currently, the system context menu can only be shown for an active text input connection',
2514-
);
2515-
2516-
// Don't show the same thing that's already being shown.
2517-
if (_lastShown != null && _lastShown!._isVisible && _lastShown!._lastTargetRect == targetRect) {
2518-
return Future<void>.value();
2519-
}
2520-
2521-
assert(
2522-
_lastShown == null || _lastShown == this || !_lastShown!._isVisible,
2523-
'Attempted to show while another instance was still visible.',
2524-
);
2525-
2526-
_lastTargetRect = targetRect;
2527-
_lastShown = this;
2528-
_hiddenBySystem = false;
2529-
return _channel.invokeMethod<Map<String, dynamic>>(
2530-
'ContextMenu.showSystemContextMenu',
2531-
<String, dynamic>{
2532-
'targetRect': <String, double>{
2533-
'x': targetRect.left,
2534-
'y': targetRect.top,
2535-
'width': targetRect.width,
2536-
'height': targetRect.height,
2537-
},
2538-
},
2539-
);
2540-
}
2541-
2542-
/// Hides this system context menu.
2543-
///
2544-
/// If this hasn't been shown, or if another instance has hidden this menu,
2545-
/// does nothing.
2546-
///
2547-
/// Currently this is only supported on iOS 16.0 and later.
2548-
///
2549-
/// See also:
2550-
///
2551-
/// * [show], which shows the menu hidden by this method.
2552-
/// * [MediaQuery.supportsShowingSystemContextMenu], which indicates whether
2553-
/// the system context menu is supported on the current platform.
2554-
Future<void> hide() async {
2555-
assert(!_isDisposed);
2556-
// This check prevents a given instance from accidentally hiding some other
2557-
// instance, since only one can be visible at a time.
2558-
if (this != _lastShown) {
2559-
return;
2560-
}
2561-
_lastShown = null;
2562-
// This may be called unnecessarily in the case where the user has already
2563-
// hidden the menu (for example by tapping the screen).
2564-
return _channel.invokeMethod<void>(
2565-
'ContextMenu.hideSystemContextMenu',
2566-
);
2567-
}
2568-
2569-
@override
2570-
String toString() {
2571-
return 'SystemContextMenuController(onSystemHide=$onSystemHide, _hiddenBySystem=$_hiddenBySystem, _isVisible=$_isVisible, _isDiposed=$_isDisposed)';
2572-
}
2573-
2574-
/// Used to release resources when this instance will never be used again.
2575-
void dispose() {
2576-
assert(!_isDisposed);
2577-
hide();
2578-
ServicesBinding.unregisterSystemContextMenuClient(this);
2579-
_isDisposed = true;
2580-
}
2581-
}

0 commit comments

Comments
 (0)