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

Commit bb4c58d

Browse files
authored
Break dependency cycle of FlutterViewController <-> FlutterPlatformView (#52271)
Trying to migrate the iOS embedder MRC to ARC, I'm attempting to break some dependency cycles so it's easier to migrate the "leaf" dependencies to ARC, working my way up. The cycle is: **`FlutterViewController`** -> `FlutterView` -> `FlutterPlatformView` -> (Before this PR)**`FlutterViewController`** `FlutterViewController` depends on many other large MRC classes, like FlutterEngine., so I'd like to pull that one out so `FlutterView`, `FlutterPlatformView`, and `FlutterOverlayView` can be migrated to ARC in a smaller PR. `FlutterPlatformView` only depends on `FlutterViewController` in this one place, casting a `UIViewController` and calling `-forceTouchesCancelled:`. https://github.com/flutter/engine/blob/55670b71eb00fbe80601b7227f68c1df4cae827b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm#L1201 Instead, move `-forceTouchesCancelled:` to the existing `FlutterViewResponder` protocol with the other touch events, which `FlutterViewController` already implements. The cast can then be removed, breaking the cycle. Clean up all the imports. Part of flutter/flutter#137801, though this doesn't actually migrate anything to ARC.
1 parent 219ec84 commit bb4c58d

11 files changed

+52
-69
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
#include <Metal/Metal.h>
99
#include <UIKit/UIKit.h>
1010

11-
#include <memory>
12-
13-
#include "flutter/fml/memory/weak_ptr.h"
14-
#include "flutter/shell/common/shell.h"
15-
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
16-
#include "fml/platform/darwin/cf_utils.h"
17-
18-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
19-
2011
/// UIViews that are used by |FlutterPlatformViews| to present Flutter
2112
/// rendering on top of system compositor rendering (ex. a web view).
2213
///

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,11 @@
33
// found in the LICENSE file.
44

55
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h"
6+
67
#include <CoreGraphics/CGColorSpace.h>
7-
#include <Metal/Metal.h>
88

9-
#include "flutter/common/settings.h"
10-
#include "flutter/common/task_runners.h"
11-
#include "flutter/flow/layers/layer_tree.h"
12-
#include "flutter/fml/platform/darwin/cf_utils.h"
13-
#include "flutter/fml/synchronization/waitable_event.h"
14-
#include "flutter/fml/trace_event.h"
15-
#include "flutter/shell/common/platform_view.h"
16-
#include "flutter/shell/common/rasterizer.h"
179
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
18-
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
19-
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
10+
#include "fml/platform/darwin/cf_utils.h"
2011

2112
// This is mostly a duplication of FlutterView.
2213
// TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView.

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include <Metal/Metal.h>
6-
#import <UIKit/UIGestureRecognizerSubclass.h>
5+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
76

8-
#include <list>
9-
#include <map>
10-
#include <memory>
11-
#include <string>
7+
#include <Metal/Metal.h>
128

13-
#include "flutter/common/graphics/persistent_cache.h"
149
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
15-
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
1610
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h"
17-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
1811
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
19-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
2012
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
2113

2214
@implementation UIView (FirstResponder)
@@ -171,11 +163,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
171163
}
172164

173165
void FlutterPlatformViewsController::SetFlutterViewController(
174-
UIViewController* flutter_view_controller) {
166+
UIViewController<FlutterViewResponder>* flutter_view_controller) {
175167
flutter_view_controller_.reset([flutter_view_controller retain]);
176168
}
177169

178-
UIViewController* FlutterPlatformViewsController::getFlutterViewController() {
170+
UIViewController<FlutterViewResponder>* FlutterPlatformViewsController::getFlutterViewController() {
179171
return flutter_view_controller_.get();
180172
}
181173

@@ -1147,7 +1139,7 @@ @implementation ForwardingGestureRecognizer {
11471139
// This gesture recognizer retains the `FlutterViewController` until the
11481140
// end of a gesture sequence, that is all the touches in touchesBegan are concluded
11491141
// with |touchesCancelled| or |touchesEnded|.
1150-
fml::scoped_nsobject<UIViewController> _flutterViewController;
1142+
fml::scoped_nsobject<UIViewController<FlutterViewResponder>> _flutterViewController;
11511143
}
11521144

11531145
- (instancetype)initWithTarget:(id)target
@@ -1198,7 +1190,7 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
11981190
// Flutter needs all the cancelled touches to be "cancelled" change types in order to correctly
11991191
// handle gesture sequence.
12001192
// We always override the change type to "cancelled".
1201-
[((FlutterViewController*)_flutterViewController.get()) forceTouchesCancelled:touches];
1193+
[_flutterViewController.get() forceTouchesCancelled:touches];
12021194
_currentTouchPointersCount -= touches.count;
12031195
if (_currentTouchPointersCount == 0) {
12041196
self.state = UIGestureRecognizerStateFailed;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
#import <UIKit/UIKit.h>
77
#import <XCTest/XCTest.h>
88

9-
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
9+
#import "flutter/fml/thread.h"
1010
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
1111
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
1212
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
1313
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
1414
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTouchInterceptingView_Test.h"
15-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
1615
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
1716

1817
FLUTTER_ASSERT_ARC
@@ -2158,7 +2157,7 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu
21582157
[forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
21592158
OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]);
21602159

2161-
UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]);
2160+
FlutterViewController* mockFlutterViewContoller2 = OCMClassMock([FlutterViewController class]);
21622161
flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2);
21632162

21642163
// Touch events should still send to the old FlutterViewController if FlutterViewController

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
66
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
77

8+
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
9+
810
#include <Metal/Metal.h>
9-
#include "flutter/flow/embedded_views.h"
11+
12+
#include "flutter/flow/surface.h"
13+
#include "flutter/fml/memory/weak_ptr.h"
1014
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
11-
#include "flutter/shell/common/shell.h"
12-
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
15+
#include "flutter/fml/trace_event.h"
1316
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
14-
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
1517
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h"
16-
#import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h"
18+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h"
1719
#import "flutter/shell/platform/darwin/ios/ios_context.h"
1820

1921
@class FlutterTouchInterceptingView;
@@ -210,9 +212,9 @@ class FlutterPlatformViewsController {
210212

211213
void SetFlutterView(UIView* flutter_view);
212214

213-
void SetFlutterViewController(UIViewController* flutter_view_controller);
215+
void SetFlutterViewController(UIViewController<FlutterViewResponder>* flutter_view_controller);
214216

215-
UIViewController* getFlutterViewController();
217+
UIViewController<FlutterViewResponder>* getFlutterViewController();
216218

217219
void RegisterViewFactory(
218220
NSObject<FlutterPlatformViewFactory>* factory,
@@ -353,7 +355,7 @@ class FlutterPlatformViewsController {
353355

354356
fml::scoped_nsobject<FlutterMethodChannel> channel_;
355357
fml::scoped_nsobject<UIView> flutter_view_;
356-
fml::scoped_nsobject<UIViewController> flutter_view_controller_;
358+
fml::scoped_nsobject<UIViewController<FlutterViewResponder>> flutter_view_controller_;
357359
fml::scoped_nsobject<FlutterClippingMaskViewPool> mask_view_pool_;
358360
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
359361
std::map<int64_t, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_
66
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_
77

8-
#include <Metal/Metal.h>
8+
#import <Metal/Metal.h>
99
#import <UIKit/UIKit.h>
1010

11-
#include <memory>
12-
13-
#include "flutter/fml/memory/weak_ptr.h"
14-
#include "flutter/shell/common/shell.h"
11+
#include "flutter/shell/common/rasterizer.h"
1512
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
16-
#import "flutter/shell/platform/darwin/ios/ios_context.h"
17-
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
1813

1914
@protocol FlutterViewEngineDelegate <NSObject>
2015

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,8 @@
33
// found in the LICENSE file.
44

55
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
6-
#include <Metal/Metal.h>
76

8-
#include "flutter/common/settings.h"
9-
#include "flutter/common/task_runners.h"
10-
#include "flutter/flow/layers/layer_tree.h"
117
#include "flutter/fml/platform/darwin/cf_utils.h"
12-
#include "flutter/fml/synchronization/waitable_event.h"
13-
#include "flutter/fml/trace_event.h"
14-
#include "flutter/shell/common/platform_view.h"
15-
#include "flutter/shell/common/rasterizer.h"
16-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
17-
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
18-
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
198

209
@implementation FlutterView {
2110
id<FlutterViewEngineDelegate> _delegate;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint);
6060
- (fml::WeakNSObject<FlutterViewController>)getWeakNSObject;
6161
- (std::shared_ptr<flutter::FlutterPlatformViewsController>&)platformViewsController;
6262
- (FlutterRestorationPlugin*)restorationPlugin;
63-
// Send touches to the Flutter Engine while forcing the change type to be cancelled.
64-
// The `phase`s in `touches` are ignored.
65-
- (void)forceTouchesCancelled:(NSSet*)touches;
6663

6764
// Accepts keypress events, and then calls |nextAction| if the event was not
6865
// handled.

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,45 @@
88
#import <Foundation/Foundation.h>
99

1010
NS_ASSUME_NONNULL_BEGIN
11+
12+
/**
13+
* Protocol to send touch events, typically a `FlutterViewController`.
14+
*/
1115
@protocol FlutterViewResponder <NSObject>
1216

1317
@property(nonatomic, strong) UIView* view;
1418

19+
/**
20+
* See `-[UIResponder touchesBegan:withEvent:]`
21+
*/
1522
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
23+
24+
/**
25+
* See `-[UIResponder touchesMoved:withEvent:]`
26+
*/
1627
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
28+
29+
/**
30+
* See `-[UIResponder touchesEnded:withEvent:]`
31+
*/
1732
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
33+
34+
/**
35+
* See `-[UIResponder touchesCancelled:withEvent:]`
36+
*/
1837
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;
38+
39+
/**
40+
* See `-[UIResponder touchesEstimatedPropertiesUpdated:]`
41+
*/
1942
- (void)touchesEstimatedPropertiesUpdated:(NSSet*)touches;
2043

44+
/**
45+
* Send touches to the Flutter Engine while forcing the change type to be cancelled.
46+
* The `phase`s in `touches` are ignored.
47+
*/
48+
- (void)forceTouchesCancelled:(NSSet*)touches;
49+
2150
@end
2251
NS_ASSUME_NONNULL_END
2352

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#import <XCTest/XCTest.h>
66

7-
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
8-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
97
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
108

119
FLUTTER_ASSERT_ARC

0 commit comments

Comments
 (0)