Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break dependency cycle of FlutterViewController <-> FlutterPlatformView #52271

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
#include <Metal/Metal.h>
#include <UIKit/UIKit.h>

#include <memory>

#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/shell/common/shell.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#include "fml/platform/darwin/cf_utils.h"

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"

/// UIViews that are used by |FlutterPlatformViews| to present Flutter
/// rendering on top of system compositor rendering (ex. a web view).
///
Expand Down
13 changes: 2 additions & 11 deletions shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
// found in the LICENSE file.

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h"

#include <CoreGraphics/CGColorSpace.h>
#include <Metal/Metal.h>

#include "flutter/common/settings.h"
#include "flutter/common/task_runners.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/rasterizer.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
#include "fml/platform/darwin/cf_utils.h"

// This is mostly a duplication of FlutterView.
// TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView.
Expand Down
20 changes: 6 additions & 14 deletions shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

#include <list>
#include <map>
#include <memory>
#include <string>
#include <Metal/Metal.h>

#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.h"

@implementation UIView (FirstResponder)
Expand Down Expand Up @@ -171,11 +163,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
}

void FlutterPlatformViewsController::SetFlutterViewController(
UIViewController* flutter_view_controller) {
UIViewController<FlutterViewResponder>* flutter_view_controller) {
flutter_view_controller_.reset([flutter_view_controller retain]);
}

UIViewController* FlutterPlatformViewsController::getFlutterViewController() {
UIViewController<FlutterViewResponder>* FlutterPlatformViewsController::getFlutterViewController() {
return flutter_view_controller_.get();
}

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

- (instancetype)initWithTarget:(id)target
Expand Down Expand Up @@ -1198,7 +1190,7 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
// Flutter needs all the cancelled touches to be "cancelled" change types in order to correctly
// handle gesture sequence.
// We always override the change type to "cancelled".
[((FlutterViewController*)_flutterViewController.get()) forceTouchesCancelled:touches];
[_flutterViewController.get() forceTouchesCancelled:touches];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Removing FlutterViewController here)

_currentTouchPointersCount -= touches.count;
if (_currentTouchPointersCount == 0) {
self.state = UIGestureRecognizerStateFailed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
#import "flutter/fml/thread.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTouchInterceptingView_Test.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"

FLUTTER_ASSERT_ARC
Expand Down Expand Up @@ -2158,7 +2157,7 @@ - (void)testSetFlutterViewControllerInTheMiddleOfTouchEventShouldStillAllowGestu
[forwardGectureRecognizer touchesBegan:touches1 withEvent:event1];
OCMVerify([mockFlutterViewContoller touchesBegan:touches1 withEvent:event1]);

UIViewController* mockFlutterViewContoller2 = OCMClassMock([UIViewController class]);
FlutterViewController* mockFlutterViewContoller2 = OCMClassMock([FlutterViewController class]);
flutterPlatformViewsController->SetFlutterViewController(mockFlutterViewContoller2);

// Touch events should still send to the old FlutterViewController if FlutterViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_

#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"

#include <Metal/Metal.h>
#include "flutter/flow/embedded_views.h"

#include "flutter/flow/surface.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/shell/common/shell.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
#include "flutter/fml/trace_event.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"

@class FlutterTouchInterceptingView;
Expand Down Expand Up @@ -210,9 +212,9 @@ class FlutterPlatformViewsController {

void SetFlutterView(UIView* flutter_view);

void SetFlutterViewController(UIViewController* flutter_view_controller);
void SetFlutterViewController(UIViewController<FlutterViewResponder>* flutter_view_controller);

UIViewController* getFlutterViewController();
UIViewController<FlutterViewResponder>* getFlutterViewController();

void RegisterViewFactory(
NSObject<FlutterPlatformViewFactory>* factory,
Expand Down Expand Up @@ -353,7 +355,7 @@ class FlutterPlatformViewsController {

fml::scoped_nsobject<FlutterMethodChannel> channel_;
fml::scoped_nsobject<UIView> flutter_view_;
fml::scoped_nsobject<UIViewController> flutter_view_controller_;
fml::scoped_nsobject<UIViewController<FlutterViewResponder>> flutter_view_controller_;
fml::scoped_nsobject<FlutterClippingMaskViewPool> mask_view_pool_;
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
std::map<int64_t, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
Expand Down
9 changes: 2 additions & 7 deletions shell/platform/darwin/ios/framework/Source/FlutterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEW_H_

#include <Metal/Metal.h>
#import <Metal/Metal.h>
#import <UIKit/UIKit.h>

#include <memory>

#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/rasterizer.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.h"

@protocol FlutterViewEngineDelegate <NSObject>

Expand Down
11 changes: 0 additions & 11 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,8 @@
// found in the LICENSE file.

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

#include "flutter/common/settings.h"
#include "flutter/common/task_runners.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/fml/platform/darwin/cf_utils.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/rasterizer.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h"

@implementation FlutterView {
id<FlutterViewEngineDelegate> _delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint);
- (fml::WeakNSObject<FlutterViewController>)getWeakNSObject;
- (std::shared_ptr<flutter::FlutterPlatformViewsController>&)platformViewsController;
- (FlutterRestorationPlugin*)restorationPlugin;
// Send touches to the Flutter Engine while forcing the change type to be cancelled.
// The `phase`s in `touches` are ignored.
- (void)forceTouchesCancelled:(NSSet*)touches;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to FlutterViewResponder.h


// Accepts keypress events, and then calls |nextAction| if the event was not
// handled.
Expand Down
29 changes: 29 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,45 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
* Protocol to send touch events, typically a `FlutterViewController`.
*/
@protocol FlutterViewResponder <NSObject>

@property(nonatomic, strong) UIView* view;

/**
* See `-[UIResponder touchesBegan:withEvent:]`
*/
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;

/**
* See `-[UIResponder touchesMoved:withEvent:]`
*/
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;

/**
* See `-[UIResponder touchesEnded:withEvent:]`
*/
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;

/**
* See `-[UIResponder touchesCancelled:withEvent:]`
*/
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;

/**
* See `-[UIResponder touchesEstimatedPropertiesUpdated:]`
*/
- (void)touchesEstimatedPropertiesUpdated:(NSSet*)touches;

/**
* Send touches to the Flutter Engine while forcing the change type to be cancelled.
* The `phase`s in `touches` are ignored.
*/
- (void)forceTouchesCancelled:(NSSet*)touches;

@end
NS_ASSUME_NONNULL_END

Expand Down
2 changes: 0 additions & 2 deletions shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#import <XCTest/XCTest.h>

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"

FLUTTER_ASSERT_ARC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
#import "flutter/fml/thread.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
Expand Down