From 24fd333ce6a069b56444e8511ce792502a1b1569 Mon Sep 17 00:00:00 2001 From: xiaoxiaowesley <44207000+xiaoxiaowesley@users.noreply.github.com> Date: Fri, 18 Mar 2022 22:10:09 +0800 Subject: [PATCH] Fix iOS keyboard physical keyboard doesn't work in add to app (flutter/engine#32098) --- .../ios/framework/Source/FlutterViewController.mm | 6 +++--- .../ios/framework/Source/FlutterViewControllerTest.mm | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 304de7a21a..25d94fddc2 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -656,14 +656,14 @@ static void SendFakeTouchEvent(FlutterEngine* engine, TRACE_EVENT0("flutter", "viewDidLoad"); if (_engine && _engineNeedsLaunch) { - // Register internal plugins before starting the engine. - [self addInternalPlugins]; - [_engine.get() launchEngine:nil libraryURI:nil entrypointArgs:nil]; [_engine.get() setViewController:self]; _engineNeedsLaunch = NO; } + // Register internal plugins. + [self addInternalPlugins]; + if ([_engine.get() viewController] == self) { [_engine.get() attachView]; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index 8d838d72d0..0ce51bdd9d 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -420,6 +420,17 @@ typedef enum UIAccessibilityContrast : NSInteger { } } +// Regression test for https://github.com/flutter/engine/pull/32098. +- (void)testInternalPluginsInvokeInViewDidLoad { + FlutterEngine* mockEngine = OCMPartialMock([[FlutterEngine alloc] init]); + [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil]; + FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:mockEngine + nibName:nil + bundle:nil]; + [viewController viewDidLoad]; + OCMVerify([viewController addInternalPlugins]); +} + - (void)testBinaryMessenger { FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil