From f5e5d81eed80051f28126be910f143b2a386ccc2 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 9 Nov 2018 11:24:14 -0800 Subject: [PATCH] Move the embedded view preview flag check to a common function. (#6813) --- .../platform/darwin/ios/framework/Source/FlutterEngine.mm | 4 +--- shell/platform/darwin/ios/ios_surface.h | 5 +++-- shell/platform/darwin/ios/ios_surface.mm | 7 +++++++ shell/platform/darwin/ios/ios_surface_gl.mm | 2 +- shell/platform/darwin/ios/ios_surface_software.mm | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index ed501e59f..c5f3b8d9a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -296,8 +296,6 @@ threadLabel.UTF8String, // label shell::ThreadHost::Type::UI | shell::ThreadHost::Type::GPU | shell::ThreadHost::Type::IO}; - bool embedded_views_preview_enabled = [[[NSBundle mainBundle] - objectForInfoDictionaryKey:@(shell::kEmbeddedViewsPreview)] boolValue]; // Lambda captures by pointers to ObjC objects are fine here because the // create call is // synchronous. @@ -310,7 +308,7 @@ return std::make_unique(shell.GetTaskRunners()); }; - if (embedded_views_preview_enabled) { + if (shell::IsIosEmbeddedViewsPreviewEnabled()) { // Embedded views requires the gpu and the platform views to be the same. // The plan is to eventually dynamically merge the threads when there's a // platform view in the layer tree. diff --git a/shell/platform/darwin/ios/ios_surface.h b/shell/platform/darwin/ios/ios_surface.h index 660844d31..1fc6a4218 100644 --- a/shell/platform/darwin/ios/ios_surface.h +++ b/shell/platform/darwin/ios/ios_surface.h @@ -15,8 +15,9 @@ namespace shell { -// The name of the Info.plist flag to enable the embedded iOS views preview. -const char* const kEmbeddedViewsPreview = "io.flutter.embedded_views_preview"; +// Returns true if the app explicitly specified to use the iOS view embedding +// mechanism which is still in a release preview. +bool IsIosEmbeddedViewsPreviewEnabled(); class IOSSurface { public: diff --git a/shell/platform/darwin/ios/ios_surface.mm b/shell/platform/darwin/ios/ios_surface.mm index e4f795765..f9d2d4cfb 100644 --- a/shell/platform/darwin/ios/ios_surface.mm +++ b/shell/platform/darwin/ios/ios_surface.mm @@ -11,6 +11,13 @@ namespace shell { +// The name of the Info.plist flag to enable the embedded iOS views preview. +const char* const kEmbeddedViewsPreview = "io.flutter.embedded_views_preview"; + +bool IsIosEmbeddedViewsPreviewEnabled() { + return [[[NSBundle mainBundle] objectForInfoDictionaryKey:@(kEmbeddedViewsPreview)] boolValue]; +} + IOSSurface::IOSSurface(FlutterPlatformViewsController* platform_views_controller) : platform_views_controller_(platform_views_controller) {} diff --git a/shell/platform/darwin/ios/ios_surface_gl.mm b/shell/platform/darwin/ios/ios_surface_gl.mm index 3a5315a26..236b05dac 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/shell/platform/darwin/ios/ios_surface_gl.mm @@ -75,7 +75,7 @@ bool IOSSurfaceGL::GLContextPresent() { } flow::ExternalViewEmbedder* IOSSurfaceGL::GetExternalViewEmbedder() { - if ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@(kEmbeddedViewsPreview)] boolValue]) { + if (IsIosEmbeddedViewsPreviewEnabled()) { return this; } else { return nullptr; diff --git a/shell/platform/darwin/ios/ios_surface_software.mm b/shell/platform/darwin/ios/ios_surface_software.mm index 3252b3e1c..a1017439c 100644 --- a/shell/platform/darwin/ios/ios_surface_software.mm +++ b/shell/platform/darwin/ios/ios_surface_software.mm @@ -127,7 +127,7 @@ bool IOSSurfaceSoftware::PresentBackingStore(sk_sp backing_store) { } flow::ExternalViewEmbedder* IOSSurfaceSoftware::GetExternalViewEmbedder() { - if ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@(kEmbeddedViewsPreview)] boolValue]) { + if (IsIosEmbeddedViewsPreviewEnabled()) { return this; } else { return nullptr;