[iOS] Make FlutterInit redundant and deprecate the same. (flutter/engine#3377)

This commit is contained in:
Chinmay Garde
2017-01-31 12:56:55 -08:00
committed by GitHub
parent 9ca3d938f7
commit ea73356841
5 changed files with 42 additions and 23 deletions

View File

@@ -9,9 +9,7 @@
namespace shell {
void PlatformMacMain(int argc,
const char* argv[],
std::string icu_data_path,
void PlatformMacMain(std::string icu_data_path,
std::string application_library_path);
bool AttemptLaunchFromCommandLineSwitches(Engine* engine);

View File

@@ -50,11 +50,22 @@ static void RedirectIOConnectionsToSyslog() {
#endif
}
static void InitializeCommandLine() {
base::mac::ScopedNSAutoreleasePool pool;
base::CommandLine::StringVector vector;
for (NSString* arg in [NSProcessInfo processInfo].arguments) {
vector.emplace_back(arg.UTF8String);
}
base::CommandLine::Init(0, nullptr);
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
command_line.InitFromArgv(vector);
}
class EmbedderState {
public:
EmbedderState(int argc,
const char* argv[],
std::string icu_data_path,
EmbedderState(std::string icu_data_path,
std::string application_library_path) {
#if TARGET_OS_IPHONE
// This calls crashes on MacOS because we haven't run Dart_Initialize yet.
@@ -64,7 +75,7 @@ class EmbedderState {
CHECK([NSThread isMainThread])
<< "Embedder initialization must occur on the main platform thread";
base::CommandLine::Init(argc, argv);
InitializeCommandLine();
RedirectIOConnectionsToSyslog();
@@ -109,16 +120,14 @@ class EmbedderState {
FTL_DISALLOW_COPY_AND_ASSIGN(EmbedderState);
};
void PlatformMacMain(int argc,
const char* argv[],
std::string icu_data_path,
void PlatformMacMain(std::string icu_data_path,
std::string application_library_path) {
static std::unique_ptr<EmbedderState> g_embedder;
static std::once_flag once_main;
std::call_once(once_main, [&]() {
g_embedder = WTF::MakeUnique<EmbedderState>(argc, argv, icu_data_path,
application_library_path);
g_embedder =
WTF::MakeUnique<EmbedderState>(icu_data_path, application_library_path);
});
}

View File

@@ -32,7 +32,7 @@ void AttachMessageLoopToMainRunLoop(void) {
int main(int argc, const char* argv[]) {
[FlutterApplication sharedApplication];
shell::PlatformMacMain(argc, argv, "", "");
shell::PlatformMacMain("", "");
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(shell::FlagForSwitch(shell::Switch::Help))) {

View File

@@ -5,8 +5,8 @@
#ifndef FLUTTER_FLUTTERVIEWCONTROLLER_H_
#define FLUTTER_FLUTTERVIEWCONTROLLER_H_
#include <sys/cdefs.h>
#import <UIKit/UIKit.h>
#include <sys/cdefs.h>
#include "FlutterAsyncMessageListener.h"
#include "FlutterDartProject.h"
@@ -24,23 +24,27 @@ FLUTTER_EXPORT
- (void)sendString:(NSString*)message withMessageName:(NSString*)messageName;
- (void)sendString:(NSString*)message
withMessageName:(NSString*)messageName
callback:(void (^)(NSString*))callback;
withMessageName:(NSString*)messageName
callback:(void (^)(NSString*))callback;
- (void)addMessageListener:(NSObject<FlutterMessageListener>*)listener;
- (void)removeMessageListener:(NSObject<FlutterMessageListener>*)listener;
- (void)addAsyncMessageListener:(NSObject<FlutterAsyncMessageListener>*)listener;
- (void)addAsyncMessageListener:
(NSObject<FlutterAsyncMessageListener>*)listener;
- (void)removeAsyncMessageListener:(NSObject<FlutterAsyncMessageListener>*)listener;
- (void)removeAsyncMessageListener:
(NSObject<FlutterAsyncMessageListener>*)listener;
@end
__BEGIN_DECLS
// Initializes Flutter for this process. Need only be called once per process.
FLUTTER_EXPORT void FlutterInit(int argc, const char* argv[]);
FLUTTER_EXPORT void FlutterInit(int argc, const char* argv[])
__attribute__((deprecated("This call is no longer necessary and will be "
"removed in an upcoming release.")));
__END_DECLS

View File

@@ -56,11 +56,15 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
@end
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(argc, argv, icuDataPath.UTF8String,
shell::PlatformMacMain(icuDataPath.UTF8String,
libraryName != nil ? libraryName.UTF8String : "");
}
@@ -82,6 +86,8 @@ void FlutterInit(int argc, const char* argv[]) {
- (instancetype)initWithProject:(FlutterDartProject*)project
nibName:(NSString*)nibNameOrNil
bundle:(NSBundle*)nibBundleOrNil {
FlutterInitShell();
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
@@ -111,6 +117,7 @@ void FlutterInit(int argc, const char* argv[]) {
- (void)performCommonViewControllerInitialization {
if (_initialized)
return;
_initialized = YES;
_orientationPreferences = UIInterfaceOrientationMaskAll;
@@ -342,7 +349,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
}
- (bool)isWindowFullscreen {
UIWindow *window = self.view.window;
UIWindow* window = self.view.window;
return CGRectEqualToRect(window.frame, window.screen.bounds);
}
@@ -357,11 +364,12 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
return 0.0;
}
UIScreen *screen = self.view.window.screen;
UIScreen* screen = self.view.window.screen;
CGRect statusFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect viewFrame = [self.view convertRect:self.view.bounds
toCoordinateSpace:screen.coordinateSpace];
CGFloat padding = statusFrame.origin.y + statusFrame.size.height - viewFrame.origin.y;
CGFloat padding =
statusFrame.origin.y + statusFrame.size.height - viewFrame.origin.y;
return MAX(padding, 0.0);
}