From 08b39368ebe42d087a16cedae1dc4f0afd4435d4 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Wed, 7 Jun 2023 08:47:54 +0200 Subject: [PATCH] [iOS] Fix TextInputAction.continueAction sends wrong action to framework --- .../ios/framework/Source/FlutterEngine.mm | 2 +- .../ios/framework/Source/FlutterEngine_Test.h | 4 +++ .../Source/FlutterTextInputPluginTest.mm | 25 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index d8adc04c78abd..1bde46a6f9853 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -1009,7 +1009,7 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView actionString = @"TextInputAction.next"; break; case FlutterTextInputActionContinue: - actionString = @"TextInputAction.continue"; + actionString = @"TextInputAction.continueAction"; break; case FlutterTextInputActionJoin: actionString = @"TextInputAction.join"; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h index 7e4ebc62ae885..96ffe45f67994 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h @@ -4,6 +4,7 @@ #import "flutter/shell/common/shell.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h" #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #include "flutter/shell/platform/embedder/embedder.h" @@ -31,4 +32,7 @@ class ThreadHost; entrypointArgs:(/*nullable*/ NSArray*)entrypointArgs; - (const flutter::ThreadHost&)threadHost; - (void)updateDisplays; +- (void)flutterTextInputView:(FlutterTextInputView*)textInputView + performAction:(FlutterTextInputAction)action + withClient:(int)client; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index 04452ed9c3246..88f936ce23316 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h" #import @@ -308,7 +310,7 @@ - (void)testAutocorrectionPromptRectAppears { withClient:0]); } -- (void)testIngoresSelectionChangeIfSelectionIsDisabled { +- (void)testIgnoresSelectionChangeIfSelectionIsDisabled { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; __block int updateCount = 0; OCMStub([engine flutterTextInputView:inputView updateEditingClient:0 withState:[OCMArg isNotNil]]) @@ -678,6 +680,27 @@ - (void)testUpdateSecureTextEntry { XCTAssertFalse(inputView.isSecureTextEntry); } +- (void)testInputActionContinueAction { + id mockBinaryMessenger = OCMClassMock([FlutterBinaryMessengerRelay class]); + FlutterEngine* testEngine = [[FlutterEngine alloc] init]; + [testEngine setBinaryMessenger:mockBinaryMessenger]; + [testEngine runWithEntrypoint:FlutterDefaultDartEntrypoint initialRoute:@"test"]; + + FlutterTextInputPlugin* inputPlugin = + [[FlutterTextInputPlugin alloc] initWithDelegate:(id)testEngine]; + FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:inputPlugin]; + + [testEngine flutterTextInputView:inputView + performAction:FlutterTextInputActionContinue + withClient:123]; + + FlutterMethodCall* methodCall = + [FlutterMethodCall methodCallWithMethodName:@"TextInputClient.performAction" + arguments:@[ @(123), @"TextInputAction.continueAction" ]]; + NSData* encodedMethodCall = [[FlutterJSONMethodCodec sharedInstance] encodeMethodCall:methodCall]; + OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/textinput" message:encodedMethodCall]); +} + #pragma mark - TextEditingDelta tests - (void)testTextEditingDeltasAreGeneratedOnTextInput { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];