Unverified Commit b05741cb authored by Markus Aksli's avatar Markus Aksli Committed by GitHub

Hide the text selection toolbar on mobile when orientation changes (#103512)

parent 5a919673
......@@ -1646,6 +1646,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
AnimationController? _floatingCursorResetController;
Orientation? _lastOrientation;
@override
bool get wantKeepAlive => widget.focusNode.hasFocus;
......@@ -1850,6 +1852,26 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_cursorTimer = null;
}
}
if (defaultTargetPlatform != TargetPlatform.iOS && defaultTargetPlatform != TargetPlatform.android) {
return;
}
// Hide the text selection toolbar on mobile when orientation changes.
final Orientation orientation = MediaQuery.of(context).orientation;
if (_lastOrientation == null) {
_lastOrientation = orientation;
return;
}
if (orientation != _lastOrientation) {
_lastOrientation = orientation;
if (defaultTargetPlatform == TargetPlatform.iOS) {
hideToolbar(false);
}
if (defaultTargetPlatform == TargetPlatform.android) {
hideToolbar();
}
}
}
@override
......
......@@ -1503,6 +1503,54 @@ void main() {
expect(find.text('Paste'), findsNothing);
});
testWidgets('toolbar hidden on mobile when orientation changes', (WidgetTester tester) async {
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
await tester.pumpWidget(
MaterialApp(
home: EditableText(
backgroundCursorColor: Colors.grey,
controller: controller,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
selectionControls: materialTextSelectionControls,
),
),
);
final EditableTextState state =
tester.state<EditableTextState>(find.byType(EditableText));
// Show the toolbar
state.renderEditable.selectWordsInRange(
from: Offset.zero,
cause: SelectionChangedCause.tap,
);
await tester.pump();
expect(state.showToolbar(), true);
await tester.pumpAndSettle();
expect(find.text('Paste'), findsOneWidget);
// Hide the menu by changing orientation.
tester.binding.window.physicalSizeTestValue = const Size(1800.0, 2400.0);
await tester.pumpAndSettle();
expect(find.text('Paste'), findsNothing);
// Handles should be hidden as well on Android
expect(
find.descendant(
of: find.byType(CompositedTransformFollower),
matching: find.byType(Padding),
),
defaultTargetPlatform == TargetPlatform.android ? findsNothing : findsOneWidget,
);
// On web, we don't show the Flutter toolbar and instead rely on the browser
// toolbar. Until we change that, this test should remain skipped.
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android })); // [intended]
testWidgets('Paste is shown only when there is something to paste', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
......
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