Update Highlight mode initial value calculation. (#52990)
This commit is contained in:
parent
14f3a36aba
commit
a2e6c30b44
@ -3,7 +3,6 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -1368,7 +1367,34 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
|
|||||||
/// the [WidgetsBinding] instance.
|
/// the [WidgetsBinding] instance.
|
||||||
static FocusManager get instance => WidgetsBinding.instance.focusManager;
|
static FocusManager get instance => WidgetsBinding.instance.focusManager;
|
||||||
|
|
||||||
bool _lastInteractionWasTouch = true;
|
bool get _lastInteractionWasTouch {
|
||||||
|
// Assume that if we're on one of these mobile platforms, or if there's no
|
||||||
|
// mouse connected, that the initial interaction will be touch-based, and
|
||||||
|
// that it's traditional mouse and keyboard on all others.
|
||||||
|
//
|
||||||
|
// This only affects the initial value: the ongoing value is updated to a
|
||||||
|
// known correct value as soon as any pointer events are received.
|
||||||
|
if (_lastInteractionWasTouchValue == null) {
|
||||||
|
switch (defaultTargetPlatform) {
|
||||||
|
case TargetPlatform.android:
|
||||||
|
case TargetPlatform.fuchsia:
|
||||||
|
case TargetPlatform.iOS:
|
||||||
|
_lastInteractionWasTouchValue = !WidgetsBinding.instance.mouseTracker.mouseIsConnected;
|
||||||
|
break;
|
||||||
|
case TargetPlatform.linux:
|
||||||
|
case TargetPlatform.macOS:
|
||||||
|
case TargetPlatform.windows:
|
||||||
|
_lastInteractionWasTouchValue = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _lastInteractionWasTouchValue;
|
||||||
|
}
|
||||||
|
bool _lastInteractionWasTouchValue;
|
||||||
|
set _lastInteractionWasTouch(bool value) {
|
||||||
|
_lastInteractionWasTouchValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Sets the strategy by which [highlightMode] is determined.
|
/// Sets the strategy by which [highlightMode] is determined.
|
||||||
///
|
///
|
||||||
@ -1418,13 +1444,6 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
|
|||||||
// Update function to be called whenever the state relating to highlightMode
|
// Update function to be called whenever the state relating to highlightMode
|
||||||
// changes.
|
// changes.
|
||||||
void _updateHighlightMode() {
|
void _updateHighlightMode() {
|
||||||
// Assume that if we're on one of these mobile platforms, or if there's no
|
|
||||||
// mouse connected, that the initial interaction will be touch-based, and
|
|
||||||
// that it's traditional mouse and keyboard on all others.
|
|
||||||
//
|
|
||||||
// This only affects the initial value: the ongoing value is updated as soon
|
|
||||||
// as any input events are received.
|
|
||||||
_lastInteractionWasTouch ??= Platform.isAndroid || Platform.isIOS || !WidgetsBinding.instance.mouseTracker.mouseIsConnected;
|
|
||||||
FocusHighlightMode newMode;
|
FocusHighlightMode newMode;
|
||||||
switch (highlightStrategy) {
|
switch (highlightStrategy) {
|
||||||
case FocusHighlightStrategy.automatic:
|
case FocusHighlightStrategy.automatic:
|
||||||
|
@ -828,6 +828,21 @@ void main() {
|
|||||||
// receive it.
|
// receive it.
|
||||||
expect(receivedAnEvent, isEmpty);
|
expect(receivedAnEvent, isEmpty);
|
||||||
});
|
});
|
||||||
|
testWidgets('Initial highlight mode guesses correctly.', (WidgetTester tester) async {
|
||||||
|
FocusManager.instance.highlightStrategy = FocusHighlightStrategy.automatic;
|
||||||
|
switch (defaultTargetPlatform) {
|
||||||
|
case TargetPlatform.fuchsia:
|
||||||
|
case TargetPlatform.android:
|
||||||
|
case TargetPlatform.iOS:
|
||||||
|
expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.touch));
|
||||||
|
break;
|
||||||
|
case TargetPlatform.linux:
|
||||||
|
case TargetPlatform.macOS:
|
||||||
|
case TargetPlatform.windows:
|
||||||
|
expect(FocusManager.instance.highlightMode, equals(FocusHighlightMode.traditional));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, variant: TargetPlatformVariant.all());
|
||||||
testWidgets('Events change focus highlight mode.', (WidgetTester tester) async {
|
testWidgets('Events change focus highlight mode.', (WidgetTester tester) async {
|
||||||
await setupWidget(tester);
|
await setupWidget(tester);
|
||||||
int callCount = 0;
|
int callCount = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user