Unverified Commit 5024e1ea authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Inform the engine when read-only flag is flipped (#65499)

parent 8cb09cf4
...@@ -880,6 +880,13 @@ class TextInputConnection { ...@@ -880,6 +880,13 @@ class TextInputConnection {
TextInput._instance._requestAutofill(); TextInput._instance._requestAutofill();
} }
/// Requests that the text input control update itself according to the new
/// [TextInputConfiguration].
void updateConfig(TextInputConfiguration configuration) {
assert(attached);
TextInput._instance._updateConfig(configuration);
}
/// Requests that the text input control change its internal state to match the given state. /// Requests that the text input control change its internal state to match the given state.
void setEditingState(TextEditingValue value) { void setEditingState(TextEditingValue value) {
assert(attached); assert(attached);
...@@ -1211,6 +1218,14 @@ class TextInput { ...@@ -1211,6 +1218,14 @@ class TextInput {
_scheduleHide(); _scheduleHide();
} }
void _updateConfig(TextInputConfiguration configuration) {
assert(configuration != null);
_channel.invokeMethod<void>(
'TextInput.updateConfig',
configuration.toJson(),
);
}
void _setEditingState(TextEditingValue value) { void _setEditingState(TextEditingValue value) {
assert(value != null); assert(value != null);
_channel.invokeMethod<void>( _channel.invokeMethod<void>(
......
...@@ -1561,15 +1561,22 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -1561,15 +1561,22 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if (!_shouldCreateInputConnection) { if (!_shouldCreateInputConnection) {
_closeInputConnectionIfNeeded(); _closeInputConnectionIfNeeded();
} else { } else {
if (oldWidget.readOnly && _hasFocus) if (oldWidget.readOnly && _hasFocus) {
_openInputConnection(); _openInputConnection();
}
}
if (kIsWeb && _hasInputConnection) {
if (oldWidget.readOnly != widget.readOnly) {
_textInputConnection!.updateConfig(textInputConfiguration);
}
} }
if (widget.style != oldWidget.style) { if (widget.style != oldWidget.style) {
final TextStyle style = widget.style; final TextStyle style = widget.style;
// The _textInputConnection will pick up the new style when it attaches in // The _textInputConnection will pick up the new style when it attaches in
// _openInputConnection. // _openInputConnection.
if (_textInputConnection != null && _textInputConnection!.attached) { if (_hasInputConnection) {
_textInputConnection!.setStyle( _textInputConnection!.setStyle(
fontFamily: style.fontFamily, fontFamily: style.fontFamily,
fontSize: style.fontSize, fontSize: style.fontSize,
......
...@@ -1436,6 +1436,44 @@ void main() { ...@@ -1436,6 +1436,44 @@ void main() {
} }
}); });
testWidgets('Sends "updateConfig" when read-only flag is flipped', (WidgetTester tester) async {
bool readOnly = true;
StateSetter setState;
final TextEditingController controller = TextEditingController(text: 'Lorem ipsum dolor sit amet');
await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(builder: (BuildContext context, StateSetter stateSetter) {
setState = stateSetter;
return EditableText(
readOnly: readOnly,
controller: controller,
backgroundCursorColor: Colors.grey,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
);
}),
),
);
// Interact with the field to establish the input connection.
final Offset topLeft = tester.getTopLeft(find.byType(EditableText));
await tester.tapAt(topLeft + const Offset(0.0, 5.0));
await tester.pump();
expect(tester.testTextInput.hasAnyClients, kIsWeb ? isTrue : isFalse);
if (kIsWeb) {
expect(tester.testTextInput.setClientArgs['readOnly'], isTrue);
}
setState(() { readOnly = false; });
await tester.pump();
expect(tester.testTextInput.hasAnyClients, isTrue);
expect(tester.testTextInput.setClientArgs['readOnly'], isFalse);
});
testWidgets('Fires onChanged when text changes via TextSelectionOverlay', (WidgetTester tester) async { testWidgets('Fires onChanged when text changes via TextSelectionOverlay', (WidgetTester tester) async {
String changedValue; String changedValue;
final Widget widget = MaterialApp( final Widget widget = MaterialApp(
......
...@@ -98,6 +98,9 @@ class TestTextInput { ...@@ -98,6 +98,9 @@ class TestTextInput {
_client = methodCall.arguments[0] as int; _client = methodCall.arguments[0] as int;
setClientArgs = methodCall.arguments[1] as Map<String, dynamic>; setClientArgs = methodCall.arguments[1] as Map<String, dynamic>;
break; break;
case 'TextInput.updateConfig':
setClientArgs = methodCall.arguments as Map<String, dynamic>;
break;
case 'TextInput.clearClient': case 'TextInput.clearClient':
_client = 0; _client = 0;
_isVisible = false; _isVisible = false;
......
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