diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn index fbe4a70c2450af0e1a398b7d52c5022a6ef01492..608eca76c76397e186fbd58299757e395a44f2f1 100644 --- a/shell/platform/darwin/ios/BUILD.gn +++ b/shell/platform/darwin/ios/BUILD.gn @@ -39,6 +39,8 @@ shared_library("flutter_framework_dylib") { "framework/Source/FlutterViewController.mm", "framework/Source/accessibility_bridge.h", "framework/Source/accessibility_bridge.mm", + "framework/Source/flutter_main_ios.h", + "framework/Source/flutter_main_ios.mm", "framework/Source/flutter_touch_mapper.h", "framework/Source/flutter_touch_mapper.mm", "framework/Source/platform_message_router.h", diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 78cfdf6900f5aa8eef6299d66decfdf8cebb733e..b0469bd999a7de349f5b5308cbdd2d8d4e6bf3db 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -9,6 +9,7 @@ #include "flutter/common/threads.h" #include "flutter/shell/common/switches.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartSource.h" +#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h" static NSURL* URLForSwitch(const char* name) { auto cmd = *base::CommandLine::ForCurrentProcess(); @@ -31,6 +32,12 @@ static NSURL* URLForSwitch(const char* name) { VMType _vmTypeRequirement; } ++ (void)initialize { + if (self == [FlutterDartProject class]) { + shell::FlutterMain(); + } +} + #pragma mark - Override base class designated initializers - (instancetype)init { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index bbf0965794990f1973cd4a0b3ebb4f554cf6215b..1d863b85c260b4a2f68c946406036b60468748bf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -18,6 +18,7 @@ #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h" +#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h" #include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h" #include "flutter/shell/platform/darwin/ios/platform_view_ios.h" #include "lib/ftl/functional/make_copyable.h" @@ -59,15 +60,6 @@ void FlutterInit(int argc, const char* argv[]) { // Deprecated. To be removed. } -static void FlutterInitShell() { - NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]]; - NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"]; - NSString* libraryName = - [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"]; - shell::PlatformMacMain(icuDataPath.UTF8String, - libraryName != nil ? libraryName.UTF8String : ""); -} - @implementation FlutterViewController { base::scoped_nsprotocol _dartProject; UIInterfaceOrientationMask _orientationPreferences; @@ -81,13 +73,17 @@ static void FlutterInitShell() { BOOL _initialized; } ++ (void)initialize { + if (self == [FlutterViewController class]) { + shell::FlutterMain(); + } +} + #pragma mark - Manage and override all designated initializers - (instancetype)initWithProject:(FlutterDartProject*)project nibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil { - FlutterInitShell(); - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { @@ -508,7 +504,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( // Standard iOS status bar height in pixels. constexpr CGFloat kStandardStatusBarHeight = 20.0; -- (void)handleStatusBarTouches:(UIEvent *)event { +- (void)handleStatusBarTouches:(UIEvent*)event { // If the status bar is double-height, don't handle status bar taps. iOS // should open the app associated with the status bar. CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; @@ -517,12 +513,12 @@ constexpr CGFloat kStandardStatusBarHeight = 20.0; } // If we detect a touch in the status bar, synthesize a fake touch begin/end. - for (UITouch *touch in event.allTouches) { + for (UITouch* touch in event.allTouches) { if (touch.phase == UITouchPhaseBegan && touch.tapCount > 0) { CGPoint windowLoc = [touch locationInView:nil]; CGPoint screenLoc = [touch.window convertPoint:windowLoc toWindow:nil]; if (CGRectContainsPoint(statusBarFrame, screenLoc)) { - NSSet *statusbarTouches = [NSSet setWithObject:touch]; + NSSet* statusbarTouches = [NSSet setWithObject:touch]; [self dispatchTouches:statusbarTouches phase:UITouchPhaseBegan]; [self dispatchTouches:statusbarTouches phase:UITouchPhaseEnded]; return; diff --git a/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h b/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h new file mode 100644 index 0000000000000000000000000000000000000000..0f8e1bebd0536f68ee509110b4b0953bf3eaa4f2 --- /dev/null +++ b/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h @@ -0,0 +1,18 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTER_MAIN_IOS_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTER_MAIN_IOS_H_ + +#include "lib/ftl/macros.h" + +namespace shell { + +/// Initializes the Flutter shell. This must be called before interacting with +/// the engine in any way. It is safe to call this method multiple times. +void FlutterMain(); + +} // namespace shell + +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTER_MAIN_IOS_H_ diff --git a/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm b/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm new file mode 100644 index 0000000000000000000000000000000000000000..44eb279f2d97df4c150e545a5b9842ba04a1d7f2 --- /dev/null +++ b/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm @@ -0,0 +1,20 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h" +#include "flutter/shell/platform/darwin/common/platform_mac.h" +#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" + +namespace shell { + +void FlutterMain() { + NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]]; + NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"]; + NSString* libraryName = + [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"]; + shell::PlatformMacMain(icuDataPath.UTF8String, + libraryName != nil ? libraryName.UTF8String : ""); +} + +} // namespace shell diff --git a/travis/licenses.golden b/travis/licenses.golden index 4957595167b65d2c1b5fa12114a9e3024f87a6ef..785d6d8f3cbaf87d7f53900152b31dcd4a6caa2e 100644 --- a/travis/licenses.golden +++ b/travis/licenses.golden @@ -21172,6 +21172,8 @@ FILE: ../../../flutter/content_handler/software_rasterizer.cc FILE: ../../../flutter/content_handler/software_rasterizer.h FILE: ../../../flutter/content_handler/vulkan_rasterizer.cc FILE: ../../../flutter/content_handler/vulkan_rasterizer.h +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm FILE: ../../../flutter/vulkan/vulkan_native_surface_magma.cc FILE: ../../../flutter/vulkan/vulkan_native_surface_magma.h ---------------------------------------------------------------------------------------------------- @@ -72164,4 +72166,4 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. ==================================================================================================== Total license count: 693 - 31677 of 31677 ██████████ 100% (0 missing licenses) Done. + 31679 of 31679 ██████████ 100% (0 missing licenses) Done.