Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bd165dc

Browse files
authored
Revert "iOS: Migrate PlatformViewsController to Objective-C (#56790)" (#56817)
This is a combination of 3 reverts, required to get back to the revert that caused `ios_platform_view_tests` to start failing in the framework repo. In reverse chronological order, this reverts two trivial commits plus the non-trivial commit that likely caused the breakage: * Revert "iOS: Eliminate global in platformviews controller (#56805)" This reverts commit 752e2d7. * Revert "iOS: Delete FlutterPlatformViewsController.layerPoolSize (#56806)" This reverts commit 21c655c. * Revert "iOS: Migrate PlatformViewsController to Objective-C (#56790)" This reverts commit fb64399. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 95b5e5e commit bd165dc

24 files changed

+1974
-2280
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44564,8 +44564,6 @@ ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatf
4456444564
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm + ../../../flutter/LICENSE
4456544565
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm + ../../../flutter/LICENSE
4456644566
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm + ../../../flutter/LICENSE
44567-
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.h + ../../../flutter/LICENSE
44568-
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm + ../../../flutter/LICENSE
4456944567
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm + ../../../flutter/LICENSE
4457044568
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h + ../../../flutter/LICENSE
4457144569
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm + ../../../flutter/LICENSE
@@ -44627,6 +44625,8 @@ ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/overlay_laye
4462744625
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm + ../../../flutter/LICENSE
4462844626
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h + ../../../flutter/LICENSE
4462944627
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm + ../../../flutter/LICENSE
44628+
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_views_controller.h + ../../../flutter/LICENSE
44629+
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_views_controller.mm + ../../../flutter/LICENSE
4463044630
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h + ../../../flutter/LICENSE
4463144631
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm + ../../../flutter/LICENSE
4463244632
ORIGIN: ../../../flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h + ../../../flutter/LICENSE
@@ -47500,8 +47500,6 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatfor
4750047500
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
4750147501
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm
4750247502
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
47503-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.h
47504-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm
4750547503
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm
4750647504
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h
4750747505
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm
@@ -47563,6 +47561,8 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_
4756347561
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.mm
4756447562
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h
4756547563
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm
47564+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_views_controller.h
47565+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_views_controller.mm
4756647566
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h
4756747567
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm
4756847568
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h

shell/platform/darwin/ios/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ source_set("flutter_framework_source") {
8080
"framework/Source/FlutterPlatformPlugin.h",
8181
"framework/Source/FlutterPlatformPlugin.mm",
8282
"framework/Source/FlutterPlatformViews.mm",
83-
"framework/Source/FlutterPlatformViewsController.h",
84-
"framework/Source/FlutterPlatformViewsController.mm",
8583
"framework/Source/FlutterPlatformViews_Internal.h",
8684
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
8785
"framework/Source/FlutterRestorationPlugin.h",
@@ -122,6 +120,8 @@ source_set("flutter_framework_source") {
122120
"framework/Source/overlay_layer_pool.mm",
123121
"framework/Source/platform_message_response_darwin.h",
124122
"framework/Source/platform_message_response_darwin.mm",
123+
"framework/Source/platform_views_controller.h",
124+
"framework/Source/platform_views_controller.mm",
125125
"framework/Source/profiler_metrics_ios.h",
126126
"framework/Source/profiler_metrics_ios.mm",
127127
"framework/Source/vsync_waiter_ios.h",

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ @interface FlutterEngine () <FlutterIndirectScribbleDelegate,
105105
@property(nonatomic, readonly, assign) BOOL allowHeadlessExecution;
106106
@property(nonatomic, readonly, assign) BOOL restorationEnabled;
107107

108-
@property(nonatomic, strong) FlutterPlatformViewsController* platformViewsController;
109-
110108
// Maintains a dictionary of plugin names that have registered with the engine. Used by
111109
// FlutterEngineRegistrar to implement a FlutterPluginRegistrar.
112110
@property(nonatomic, readonly) NSMutableDictionary* pluginPublications;
@@ -152,6 +150,7 @@ @implementation FlutterEngine {
152150
std::shared_ptr<flutter::ThreadHost> _threadHost;
153151
std::unique_ptr<flutter::Shell> _shell;
154152

153+
std::shared_ptr<flutter::PlatformViewsController> _platformViewsController;
155154
flutter::IOSRenderingAPI _renderingApi;
156155
std::shared_ptr<flutter::SamplingProfiler> _profiler;
157156

@@ -212,7 +211,7 @@ - (instancetype)initWithName:(NSString*)labelPrefix
212211

213212
_pluginPublications = [[NSMutableDictionary alloc] init];
214213
_registrars = [[NSMutableDictionary alloc] init];
215-
[self recreatePlatformViewsController];
214+
[self recreatePlatformViewController];
216215
_binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self];
217216
_textureRegistry = [[FlutterTextureRegistryRelay alloc] initWithParent:self];
218217
_connections.reset(new flutter::ConnectionCollection());
@@ -263,9 +262,9 @@ - (void)setUpApplicationLifecycleNotifications:(NSNotificationCenter*)center {
263262
object:nil];
264263
}
265264

266-
- (void)recreatePlatformViewsController {
265+
- (void)recreatePlatformViewController {
267266
_renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering);
268-
_platformViewsController = [[FlutterPlatformViewsController alloc] init];
267+
_platformViewsController.reset(new flutter::PlatformViewsController());
269268
}
270269

271270
- (flutter::IOSRenderingAPI)platformViewsRenderingAPI {
@@ -453,7 +452,11 @@ - (void)destroyContext {
453452
_shell.reset();
454453
_profiler.reset();
455454
_threadHost.reset();
456-
_platformViewsController = nil;
455+
_platformViewsController.reset();
456+
}
457+
458+
- (std::shared_ptr<flutter::PlatformViewsController>&)platformViewsController {
459+
return _platformViewsController;
457460
}
458461

459462
- (NSURL*)observatoryUrl {
@@ -632,7 +635,7 @@ - (void)maybeSetupPlatformViewChannels {
632635
[self.platformViewsChannel
633636
setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
634637
if (weakSelf) {
635-
[weakSelf.platformViewsController onMethodCall:call result:result];
638+
weakSelf.platformViewsController->OnMethodCall(call, result);
636639
}
637640
}];
638641

@@ -774,11 +777,11 @@ - (BOOL)createShell:(NSString*)entrypoint
774777
if (!strongSelf) {
775778
return std::unique_ptr<flutter::PlatformViewIOS>();
776779
}
777-
[strongSelf recreatePlatformViewsController];
778-
strongSelf.platformViewsController.taskRunner =
779-
shell.GetTaskRunners().GetPlatformTaskRunner();
780+
[strongSelf recreatePlatformViewController];
781+
strongSelf->_platformViewsController->SetTaskRunner(
782+
shell.GetTaskRunners().GetPlatformTaskRunner());
780783
return std::make_unique<flutter::PlatformViewIOS>(
781-
shell, strongSelf->_renderingApi, strongSelf.platformViewsController,
784+
shell, strongSelf->_renderingApi, strongSelf->_platformViewsController,
782785
shell.GetTaskRunners(), shell.GetConcurrentWorkerTaskRunner(),
783786
shell.GetIsGpuDisabledSyncSwitch());
784787
};
@@ -1100,7 +1103,7 @@ - (void)flutterTextInputView:(FlutterTextInputView*)textInputView
11001103
// Have to check in the next run loop, because iOS requests the previous first responder to
11011104
// resign before requesting the next view to become first responder.
11021105
dispatch_async(dispatch_get_main_queue(), ^(void) {
1103-
long platform_view_id = [self.platformViewsController firstResponderPlatformViewId];
1106+
long platform_view_id = self.platformViewsController->FindFirstResponderPlatformViewId();
11041107
if (platform_view_id == -1) {
11051108
return;
11061109
}
@@ -1397,10 +1400,11 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint
13971400
// create call is synchronous.
13981401
flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
13991402
[result, context](flutter::Shell& shell) {
1400-
[result recreatePlatformViewsController];
1401-
result.platformViewsController.taskRunner = shell.GetTaskRunners().GetPlatformTaskRunner();
1403+
[result recreatePlatformViewController];
1404+
result->_platformViewsController->SetTaskRunner(
1405+
shell.GetTaskRunners().GetPlatformTaskRunner());
14021406
return std::make_unique<flutter::PlatformViewIOS>(
1403-
shell, context, result.platformViewsController, shell.GetTaskRunners());
1407+
shell, context, result->_platformViewsController, shell.GetTaskRunners());
14041408
};
14051409

14061410
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
@@ -1495,9 +1499,8 @@ - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
14951499
withId:(NSString*)factoryId
14961500
gestureRecognizersBlockingPolicy:
14971501
(FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizersBlockingPolicy {
1498-
[_flutterEngine.platformViewsController registerViewFactory:factory
1499-
withId:factoryId
1500-
gestureRecognizersBlockingPolicy:gestureRecognizersBlockingPolicy];
1502+
[_flutterEngine platformViewsController]->RegisterViewFactory(factory, factoryId,
1503+
gestureRecognizersBlockingPolicy);
15011504
}
15021505

15031506
@end

shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
4646
base64Encode:(bool)base64Encode;
4747

4848
- (FlutterPlatformPlugin*)platformPlugin;
49+
- (std::shared_ptr<flutter::PlatformViewsController>&)platformViewsController;
4950
- (FlutterTextInputPlugin*)textInputPlugin;
5051
- (FlutterRestorationPlugin*)restorationPlugin;
5152
- (void)launchEngine:(nullable NSString*)entrypoint
@@ -80,7 +81,6 @@ NS_ASSUME_NONNULL_BEGIN
8081
userData:(nullable void*)userData;
8182

8283
@property(nonatomic, readonly) FlutterDartProject* project;
83-
8484
@end
8585

8686
NS_ASSUME_NONNULL_END

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ @interface FlutterTouchInterceptingView ()
518518

519519
@implementation FlutterTouchInterceptingView
520520
- (instancetype)initWithEmbeddedView:(UIView*)embeddedView
521-
platformViewsController:(FlutterPlatformViewsController*)platformViewsController
521+
platformViewsController:
522+
(fml::WeakPtr<flutter::PlatformViewsController>)platformViewsController
522523
gestureRecognizersBlockingPolicy:
523524
(FlutterPlatformViewGestureRecognizersBlockingPolicy)blockingPolicy {
524525
self = [super initWithFrame:embeddedView.frame];
@@ -666,7 +667,7 @@ @implementation ForwardingGestureRecognizer {
666667
// outlives the FlutterViewController. And ForwardingGestureRecognizer is owned by a subview of
667668
// FlutterView, so the ForwardingGestureRecognizer never out lives FlutterViewController.
668669
// Therefore, `_platformViewsController` should never be nullptr.
669-
__weak FlutterPlatformViewsController* _platformViewsController;
670+
fml::WeakPtr<flutter::PlatformViewsController> _platformViewsController;
670671
// Counting the pointers that has started in one touch sequence.
671672
NSInteger _currentTouchPointersCount;
672673
// We can't dispatch events to the framework without this back pointer.
@@ -677,20 +678,21 @@ @implementation ForwardingGestureRecognizer {
677678
}
678679

679680
- (instancetype)initWithTarget:(id)target
680-
platformViewsController:(FlutterPlatformViewsController*)platformViewsController {
681+
platformViewsController:
682+
(fml::WeakPtr<flutter::PlatformViewsController>)platformViewsController {
681683
self = [super initWithTarget:target action:nil];
682684
if (self) {
683685
self.delegate = self;
684-
FML_DCHECK(platformViewsController);
685-
_platformViewsController = platformViewsController;
686+
FML_DCHECK(platformViewsController.get() != nullptr);
687+
_platformViewsController = std::move(platformViewsController);
686688
_currentTouchPointersCount = 0;
687689
}
688690
return self;
689691
}
690692

691693
- (ForwardingGestureRecognizer*)recreateRecognizerWithTarget:(id)target {
692694
return [[ForwardingGestureRecognizer alloc] initWithTarget:target
693-
platformViewsController:_platformViewsController];
695+
platformViewsController:std::move(_platformViewsController)];
694696
}
695697

696698
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
@@ -699,7 +701,7 @@ - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
699701
// At the start of each gesture sequence, we reset the `_flutterViewController`,
700702
// so that all the touch events in the same sequence are forwarded to the same
701703
// `_flutterViewController`.
702-
_flutterViewController = _platformViewsController.flutterViewController;
704+
_flutterViewController = _platformViewsController->GetFlutterViewController();
703705
}
704706
[_flutterViewController touchesBegan:touches withEvent:event];
705707
_currentTouchPointersCount += touches.count;

0 commit comments

Comments
 (0)