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

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

* Licenses
This commit is contained in:
Chinmay Garde
2017-02-01 13:53:15 -08:00
committed by GitHub
parent a2da5d57ec
commit cfa2e89fba
5 changed files with 57 additions and 14 deletions

View File

@@ -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",

View File

@@ -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 {

View File

@@ -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<FlutterDartProject*> _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;

View File

@@ -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_

View File

@@ -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