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

Reland [macOS] Make FlutterEngine support multiple views #39576

Merged
merged 2 commits into from
Feb 13, 2023
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
8 changes: 5 additions & 3 deletions shell/platform/darwin/macos/framework/Headers/FlutterEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ extern const uint64_t kFlutterDefaultViewId;

/**
* Coordinates a single instance of execution of a Flutter engine.
*
* A FlutterEngine can only be attached with one controller from the native
* code.
*/
FLUTTER_DARWIN_EXPORT
@interface FlutterEngine : NSObject <FlutterTextureRegistry, FlutterPluginRegistry>
Expand Down Expand Up @@ -76,10 +79,9 @@ FLUTTER_DARWIN_EXPORT
- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint;

/**
* The default `FlutterViewController` associated with this engine, if any.
* The `FlutterViewController` of this engine, if any.
*
* The default view always has ID kFlutterDefaultViewId, and is the view
* operated by the APIs that do not have a view ID specified.
* This view is used by legacy APIs that assume a single view.
*
* Setting this field from nil to a non-nil view controller also updates
* the view controller's engine and ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ FLUTTER_DARWIN_EXPORT
@property(nonnull, readonly) id<FlutterTextureRegistry> textures;

/**
* The view displaying Flutter content. May return |nil|, for instance in a headless environment.
* The default view displaying Flutter content.
*
* WARNING: If/when multiple Flutter views within the same application are supported (#30701), this
* API will change.
* This method may return |nil|, for instance in a headless environment.
*
* The default view is a special view operated by single-view APIs.
*/
@property(nullable, readonly) NSView* view;

/**
* The `NSView` associated with the given view ID, if any.
*/
- (nullable NSView*)viewForId:(uint64_t)viewId;

/**
* Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ FLUTTER_DARWIN_EXPORT
NS_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithCoder:(nonnull NSCoder*)nibNameOrNil NS_DESIGNATED_INITIALIZER;
/**
* Initializes this FlutterViewController with the specified `FlutterEngine`.
* Initializes this FlutterViewController with an existing `FlutterEngine`.
*
* The initialized view controller will add itself to the engine as part of this process.
*
* This initializer is suitable for both the first Flutter view controller and
* the following ones of the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// TODO(dkwingsmt): This class only supports single-view for now. As more
// classes are gradually converted to multi-view, it should get the view ID
// from somewhere.
FlutterView* view = [view_provider_ getView:kFlutterDefaultViewId];
FlutterView* view = [view_provider_ viewForId:kFlutterDefaultViewId];
if (!view) {
return false;
}
Expand All @@ -37,7 +37,7 @@
bool FlutterCompositor::Present(uint64_t view_id,
const FlutterLayer** layers,
size_t layers_count) {
FlutterView* view = [view_provider_ getView:view_id];
FlutterView* view = [view_provider_ viewForId:view_id];
if (!view) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
#import "flutter/testing/testing.h"

extern const uint64_t kFlutterDefaultViewId;

@interface FlutterViewMockProvider : NSObject <FlutterViewProvider> {
FlutterView* _defaultView;
}
Expand All @@ -30,7 +32,7 @@ - (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view {
return self;
}

- (nullable FlutterView*)getView:(uint64_t)viewId {
- (nullable FlutterView*)viewForId:(uint64_t)viewId {
if (viewId == kFlutterDefaultViewId) {
return _defaultView;
}
Expand Down
Loading