Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
#define FLUTTER_FLOW_EMBEDDED_VIEWS_H_

#include "flutter/fml/memory/ref_counted.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkSize.h"

namespace flow {

class EmbeddedViewParams {
Copy link
Member

Choose a reason for hiding this comment

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

Lets add an equality check for the embedded view params and ask the view embedder to composite the same only if the equality check from the last frame changed.

It is fine to do this in a later patch with a TODO added here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a TODO in FlutterPlatformViews.mm (to make sure we don't do anything if the params didn't change)

public:
SkPoint offsetPixels;
SkSize sizePoints;
};

// This is only used on iOS when running in a non headless mode,
Expand Down
4 changes: 4 additions & 0 deletions flow/layers/platform_view_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ void PlatformViewLayer::Paint(PaintContext& context) const {
return;
}
EmbeddedViewParams params;
SkMatrix transform = context.canvas.getTotalMatrix();
params.offsetPixels = SkPoint::Make(transform.getTranslateX(), transform.getTranslateY());
params.sizePoints = size_;

context.view_embedder->CompositeEmbeddedView(view_id_, params);
}
} // namespace flow
19 changes: 17 additions & 2 deletions shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
namespace shell {

FlutterPlatformViewsController::FlutterPlatformViewsController(
NSObject<FlutterBinaryMessenger>* messenger) {
NSObject<FlutterBinaryMessenger>* messenger,
FlutterView* flutter_view)
: flutter_view_([flutter_view retain]) {
channel_.reset([[FlutterMethodChannel alloc]
initWithName:@"flutter/platform_views"
binaryMessenger:messenger
Expand Down Expand Up @@ -58,6 +60,9 @@
views_[viewId] = fml::scoped_nsobject<UIView>([[factory createWithFrame:CGRectZero
viewIdentifier:viewId
arguments:nil] retain]);

FlutterView* flutter_view = flutter_view_.get();
[flutter_view addSubview:views_[viewId].get()];
result(nil);
}

Expand All @@ -72,6 +77,8 @@
return;
}

UIView* view = views_[viewId].get();
[view removeFromSuperview];
views_.erase(viewId);
result(nil);
}
Expand All @@ -87,7 +94,15 @@

void FlutterPlatformViewsController::CompositeEmbeddedView(int view_id,
const flow::EmbeddedViewParams& params) {
// TODO(amirh): implement this.
// TODO(amirh): assert that this is running on the platform thread once we support the iOS
// embedded views thread configuration.
CGFloat screenScale = [[UIScreen mainScreen] scale];
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a threading assertion here that will trip if the threads are not the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a TODO, as for as long as we don't support the thread configuration it will make development a little annoying.

CGRect rect =
CGRectMake(params.offsetPixels.x() / screenScale, params.offsetPixels.y() / screenScale,
params.sizePoints.width(), params.sizePoints.height());

UIView* view = views_[view_id];
[view setFrame:rect];
}

} // namespace shell
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_

#include "FlutterView.h"
#include "flutter/flow/embedded_views.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/shell/common/shell.h"
Expand All @@ -16,14 +17,16 @@ namespace shell {

class FlutterPlatformViewsController : public flow::ExternalViewEmbedder {
public:
FlutterPlatformViewsController(NSObject<FlutterBinaryMessenger>* messenger);
FlutterPlatformViewsController(NSObject<FlutterBinaryMessenger>* messenger,
FlutterView* flutter_view);

void RegisterViewFactory(NSObject<FlutterPlatformViewFactory>* factory, NSString* factoryId);

void CompositeEmbeddedView(int view_id, const flow::EmbeddedViewParams& params);

private:
fml::scoped_nsobject<FlutterMethodChannel> channel_;
fml::scoped_nsobject<FlutterView> flutter_view_;
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
std::map<int64_t, fml::scoped_nsobject<UIView>> views_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ - (void)performCommonViewControllerInitialization {
_statusBarStyle = UIStatusBarStyleDefault;

[self setupNotificationCenterObservers];
_platformViewsController.reset(new shell::FlutterPlatformViewsController(_engine.get()));
_platformViewsController.reset(new shell::FlutterPlatformViewsController(_engine.get(), _flutterView.get()));
}

- (fml::scoped_nsobject<FlutterEngine>)engine {
Expand Down