Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6b532e8

Browse files
authored
Scribble method namespace (#36642)
Platform channel refactor with a yet-unmerged framework PR
1 parent 7cd0778 commit 6b532e8

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ @implementation FlutterEngine {
126126
fml::scoped_nsobject<FlutterMethodChannel> _platformViewsChannel;
127127
fml::scoped_nsobject<FlutterMethodChannel> _textInputChannel;
128128
fml::scoped_nsobject<FlutterMethodChannel> _undoManagerChannel;
129+
fml::scoped_nsobject<FlutterMethodChannel> _scribbleChannel;
129130
fml::scoped_nsobject<FlutterMethodChannel> _spellCheckChannel;
130131
fml::scoped_nsobject<FlutterBasicMessageChannel> _lifecycleChannel;
131132
fml::scoped_nsobject<FlutterBasicMessageChannel> _systemChannel;
@@ -471,6 +472,9 @@ - (FlutterMethodChannel*)textInputChannel {
471472
- (FlutterMethodChannel*)undoManagerChannel {
472473
return _undoManagerChannel.get();
473474
}
475+
- (FlutterMethodChannel*)scribbleChannel {
476+
return _scribbleChannel.get();
477+
}
474478
- (FlutterMethodChannel*)spellCheckChannel {
475479
return _spellCheckChannel.get();
476480
}
@@ -499,6 +503,7 @@ - (void)resetChannels {
499503
_platformViewsChannel.reset();
500504
_textInputChannel.reset();
501505
_undoManagerChannel.reset();
506+
_scribbleChannel.reset();
502507
_lifecycleChannel.reset();
503508
_systemChannel.reset();
504509
_settingsChannel.reset();
@@ -572,6 +577,11 @@ - (void)setupChannels {
572577
binaryMessenger:self.binaryMessenger
573578
codec:[FlutterJSONMethodCodec sharedInstance]]);
574579

580+
_scribbleChannel.reset([[FlutterMethodChannel alloc]
581+
initWithName:@"flutter/scribble"
582+
binaryMessenger:self.binaryMessenger
583+
codec:[FlutterJSONMethodCodec sharedInstance]]);
584+
575585
_spellCheckChannel.reset([[FlutterMethodChannel alloc]
576586
initWithName:@"flutter/spellcheck"
577587
binaryMessenger:self.binaryMessenger
@@ -965,48 +975,83 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
965975
#pragma mark - FlutterViewEngineDelegate
966976

967977
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView showToolbar:(int)client {
978+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
979+
// finished transitioning to using the Scribble channel.
980+
// https://github.com/flutter/flutter/pull/104128
968981
[_textInputChannel.get() invokeMethod:@"TextInputClient.showToolbar" arguments:@[ @(client) ]];
982+
[_scribbleChannel.get() invokeMethod:@"Scribble.showToolbar" arguments:@[ @(client) ]];
969983
}
970984

971985
- (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin
972986
focusElement:(UIScribbleElementIdentifier)elementIdentifier
973987
atPoint:(CGPoint)referencePoint
974988
result:(FlutterResult)callback {
989+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
990+
// finished transitioning to using the Scribble channel.
991+
// https://github.com/flutter/flutter/pull/104128
975992
[_textInputChannel.get()
976993
invokeMethod:@"TextInputClient.focusElement"
977994
arguments:@[ elementIdentifier, @(referencePoint.x), @(referencePoint.y) ]
978995
result:callback];
996+
[_scribbleChannel.get()
997+
invokeMethod:@"Scribble.focusElement"
998+
arguments:@[ elementIdentifier, @(referencePoint.x), @(referencePoint.y) ]
999+
result:callback];
9791000
}
9801001

9811002
- (void)flutterTextInputPlugin:(FlutterTextInputPlugin*)textInputPlugin
9821003
requestElementsInRect:(CGRect)rect
9831004
result:(FlutterResult)callback {
1005+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
1006+
// finished transitioning to using the Scribble channel.
1007+
// https://github.com/flutter/flutter/pull/104128
1008+
[_scribbleChannel.get()
1009+
invokeMethod:@"Scribble.requestElementsInRect"
1010+
arguments:@[ @(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height) ]
1011+
result:callback];
9841012
[_textInputChannel.get()
9851013
invokeMethod:@"TextInputClient.requestElementsInRect"
9861014
arguments:@[ @(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height) ]
9871015
result:callback];
9881016
}
9891017

9901018
- (void)flutterTextInputViewScribbleInteractionBegan:(FlutterTextInputView*)textInputView {
1019+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
1020+
// finished transitioning to using the Scribble channel.
1021+
// https://github.com/flutter/flutter/pull/104128
9911022
[_textInputChannel.get() invokeMethod:@"TextInputClient.scribbleInteractionBegan" arguments:nil];
1023+
[_scribbleChannel.get() invokeMethod:@"Scribble.scribbleInteractionBegan" arguments:nil];
9921024
}
9931025

9941026
- (void)flutterTextInputViewScribbleInteractionFinished:(FlutterTextInputView*)textInputView {
1027+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
1028+
// finished transitioning to using the Scribble channel.
1029+
// https://github.com/flutter/flutter/pull/104128
9951030
[_textInputChannel.get() invokeMethod:@"TextInputClient.scribbleInteractionFinished"
9961031
arguments:nil];
1032+
[_scribbleChannel.get() invokeMethod:@"Scribble.scribbleInteractionFinished" arguments:nil];
9971033
}
9981034

9991035
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
10001036
insertTextPlaceholderWithSize:(CGSize)size
10011037
withClient:(int)client {
1038+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
1039+
// finished transitioning to using the Scribble channel.
1040+
// https://github.com/flutter/flutter/pull/104128
10021041
[_textInputChannel.get() invokeMethod:@"TextInputClient.insertTextPlaceholder"
10031042
arguments:@[ @(client), @(size.width), @(size.height) ]];
1043+
[_scribbleChannel.get() invokeMethod:@"Scribble.insertTextPlaceholder"
1044+
arguments:@[ @(client), @(size.width), @(size.height) ]];
10041045
}
10051046

10061047
- (void)flutterTextInputView:(FlutterTextInputView*)textInputView
10071048
removeTextPlaceholder:(int)client {
1049+
// TODO(justinmc): Remove the TextInputClient usage when the framework has
1050+
// finished transitioning to using the Scribble channel.
1051+
// https://github.com/flutter/flutter/pull/104128
10081052
[_textInputChannel.get() invokeMethod:@"TextInputClient.removeTextPlaceholder"
10091053
arguments:@[ @(client) ]];
1054+
[_scribbleChannel.get() invokeMethod:@"Scribble.removeTextPlaceholder" arguments:@[ @(client) ]];
10101055
}
10111056

10121057
- (void)flutterTextInputViewDidResignFirstResponder:(FlutterTextInputView*)textInputView {

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848
@"TextInput.setEditableSizeAndTransform";
4949
static NSString* const kSetMarkedTextRectMethod = @"TextInput.setMarkedTextRect";
5050
static NSString* const kFinishAutofillContextMethod = @"TextInput.finishAutofillContext";
51-
static NSString* const kSetSelectionRectsMethod = @"TextInput.setSelectionRects";
51+
// TODO(justinmc): Remove the TextInput method constant when the framework has
52+
// finished transitioning to using the Scribble channel.
53+
// https://github.com/flutter/flutter/pull/104128
54+
static NSString* const kDeprecatedSetSelectionRectsMethod = @"TextInput.setSelectionRects";
55+
static NSString* const kSetSelectionRectsMethod = @"Scribble.setSelectionRects";
5256
static NSString* const kStartLiveTextInputMethod = @"TextInput.startLiveTextInput";
5357

5458
#pragma mark - TextInputConfiguration Field Names
@@ -2170,6 +2174,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
21702174
} else if ([method isEqualToString:kFinishAutofillContextMethod]) {
21712175
[self triggerAutofillSave:[args boolValue]];
21722176
result(nil);
2177+
// TODO(justinmc): Remove the TextInput method constant when the framework has
2178+
// finished transitioning to using the Scribble channel.
2179+
// https://github.com/flutter/flutter/pull/104128
2180+
} else if ([method isEqualToString:kDeprecatedSetSelectionRectsMethod]) {
2181+
[self setSelectionRects:args];
2182+
result(nil);
21732183
} else if ([method isEqualToString:kSetSelectionRectsMethod]) {
21742184
[self setSelectionRects:args];
21752185
result(nil);

shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,38 @@ - (void)testGarbageInputViewsAreNotRemovedImmediately {
18541854
[self commitAutofillContextAndVerify];
18551855
}
18561856

1857+
- (void)testScribbleSetSelectionRects {
1858+
NSMutableDictionary* regularField = self.mutableTemplateCopy;
1859+
NSDictionary* editingValue = @{
1860+
@"text" : @"REGULAR_TEXT_FIELD",
1861+
@"composingBase" : @0,
1862+
@"composingExtent" : @3,
1863+
@"selectionBase" : @1,
1864+
@"selectionExtent" : @4
1865+
};
1866+
[regularField setValue:@{
1867+
@"uniqueIdentifier" : @"field1",
1868+
@"hints" : @[ @"hint2" ],
1869+
@"editingValue" : editingValue,
1870+
}
1871+
forKey:@"autofill"];
1872+
[regularField addEntriesFromDictionary:editingValue];
1873+
[self setClientId:123 configuration:regularField];
1874+
XCTAssertEqual(self.installedInputViews.count, 1ul);
1875+
XCTAssertEqual([textInputPlugin.activeView.selectionRects count], 0u);
1876+
1877+
NSArray<NSNumber*>* selectionRect = [NSArray arrayWithObjects:@0, @0, @100, @100, @0, nil];
1878+
NSArray* selectionRects = [NSArray arrayWithObjects:selectionRect, nil];
1879+
FlutterMethodCall* methodCall =
1880+
[FlutterMethodCall methodCallWithMethodName:@"Scribble.setSelectionRects"
1881+
arguments:selectionRects];
1882+
[textInputPlugin handleMethodCall:methodCall
1883+
result:^(id _Nullable result){
1884+
}];
1885+
1886+
XCTAssertEqual([textInputPlugin.activeView.selectionRects count], 1u);
1887+
}
1888+
18571889
- (void)testDecommissionedViewAreNotReusedByAutofill {
18581890
// Regression test for https://github.com/flutter/flutter/issues/84407.
18591891
NSMutableDictionary* configuration = self.mutableTemplateCopy;

0 commit comments

Comments
 (0)