提交 01afda49 编写于 作者: C Chinmay Garde 提交者: GitHub

[iOS] Ensure FlutterMain is called before interacting with the engine in any way. (#3383)

* [iOS] Ensure FlutterMain is called before interacting with the engine in any way.

* Licenses
上级 20bdd2f4
...@@ -39,6 +39,8 @@ shared_library("flutter_framework_dylib") { ...@@ -39,6 +39,8 @@ shared_library("flutter_framework_dylib") {
"framework/Source/FlutterViewController.mm", "framework/Source/FlutterViewController.mm",
"framework/Source/accessibility_bridge.h", "framework/Source/accessibility_bridge.h",
"framework/Source/accessibility_bridge.mm", "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.h",
"framework/Source/flutter_touch_mapper.mm", "framework/Source/flutter_touch_mapper.mm",
"framework/Source/platform_message_router.h", "framework/Source/platform_message_router.h",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "flutter/common/threads.h" #include "flutter/common/threads.h"
#include "flutter/shell/common/switches.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/FlutterDartSource.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h"
static NSURL* URLForSwitch(const char* name) { static NSURL* URLForSwitch(const char* name) {
auto cmd = *base::CommandLine::ForCurrentProcess(); auto cmd = *base::CommandLine::ForCurrentProcess();
...@@ -31,6 +32,12 @@ static NSURL* URLForSwitch(const char* name) { ...@@ -31,6 +32,12 @@ static NSURL* URLForSwitch(const char* name) {
VMType _vmTypeRequirement; VMType _vmTypeRequirement;
} }
+ (void)initialize {
if (self == [FlutterDartProject class]) {
shell::FlutterMain();
}
}
#pragma mark - Override base class designated initializers #pragma mark - Override base class designated initializers
- (instancetype)init { - (instancetype)init {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h" #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/FlutterTextInputDelegate.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.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/framework/Source/flutter_touch_mapper.h"
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h" #include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
#include "lib/ftl/functional/make_copyable.h" #include "lib/ftl/functional/make_copyable.h"
...@@ -59,15 +60,6 @@ void FlutterInit(int argc, const char* argv[]) { ...@@ -59,15 +60,6 @@ void FlutterInit(int argc, const char* argv[]) {
// Deprecated. To be removed. // 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 { @implementation FlutterViewController {
base::scoped_nsprotocol<FlutterDartProject*> _dartProject; base::scoped_nsprotocol<FlutterDartProject*> _dartProject;
UIInterfaceOrientationMask _orientationPreferences; UIInterfaceOrientationMask _orientationPreferences;
...@@ -81,13 +73,17 @@ static void FlutterInitShell() { ...@@ -81,13 +73,17 @@ static void FlutterInitShell() {
BOOL _initialized; BOOL _initialized;
} }
+ (void)initialize {
if (self == [FlutterViewController class]) {
shell::FlutterMain();
}
}
#pragma mark - Manage and override all designated initializers #pragma mark - Manage and override all designated initializers
- (instancetype)initWithProject:(FlutterDartProject*)project - (instancetype)initWithProject:(FlutterDartProject*)project
nibName:(NSString*)nibNameOrNil nibName:(NSString*)nibNameOrNil
bundle:(NSBundle*)nibBundleOrNil { bundle:(NSBundle*)nibBundleOrNil {
FlutterInitShell();
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { if (self) {
...@@ -508,7 +504,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( ...@@ -508,7 +504,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
// Standard iOS status bar height in pixels. // Standard iOS status bar height in pixels.
constexpr CGFloat kStandardStatusBarHeight = 20.0; 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 // If the status bar is double-height, don't handle status bar taps. iOS
// should open the app associated with the status bar. // should open the app associated with the status bar.
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
...@@ -517,12 +513,12 @@ constexpr CGFloat kStandardStatusBarHeight = 20.0; ...@@ -517,12 +513,12 @@ constexpr CGFloat kStandardStatusBarHeight = 20.0;
} }
// If we detect a touch in the status bar, synthesize a fake touch begin/end. // 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) { if (touch.phase == UITouchPhaseBegan && touch.tapCount > 0) {
CGPoint windowLoc = [touch locationInView:nil]; CGPoint windowLoc = [touch locationInView:nil];
CGPoint screenLoc = [touch.window convertPoint:windowLoc toWindow:nil]; CGPoint screenLoc = [touch.window convertPoint:windowLoc toWindow:nil];
if (CGRectContainsPoint(statusBarFrame, screenLoc)) { if (CGRectContainsPoint(statusBarFrame, screenLoc)) {
NSSet *statusbarTouches = [NSSet setWithObject:touch]; NSSet* statusbarTouches = [NSSet setWithObject:touch];
[self dispatchTouches:statusbarTouches phase:UITouchPhaseBegan]; [self dispatchTouches:statusbarTouches phase:UITouchPhaseBegan];
[self dispatchTouches:statusbarTouches phase:UITouchPhaseEnded]; [self dispatchTouches:statusbarTouches phase:UITouchPhaseEnded];
return; return;
......
// 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_
// 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
...@@ -21172,6 +21172,8 @@ FILE: ../../../flutter/content_handler/software_rasterizer.cc ...@@ -21172,6 +21172,8 @@ FILE: ../../../flutter/content_handler/software_rasterizer.cc
FILE: ../../../flutter/content_handler/software_rasterizer.h FILE: ../../../flutter/content_handler/software_rasterizer.h
FILE: ../../../flutter/content_handler/vulkan_rasterizer.cc FILE: ../../../flutter/content_handler/vulkan_rasterizer.cc
FILE: ../../../flutter/content_handler/vulkan_rasterizer.h 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.cc
FILE: ../../../flutter/vulkan/vulkan_native_surface_magma.h FILE: ../../../flutter/vulkan/vulkan_native_surface_magma.h
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
...@@ -72164,4 +72166,4 @@ freely, subject to the following restrictions: ...@@ -72164,4 +72166,4 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
==================================================================================================== ====================================================================================================
Total license count: 693 Total license count: 693
31677 of 31677 ██████████ 100% (0 missing licenses) Done. 31679 of 31679 ██████████ 100% (0 missing licenses) Done.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册