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

Commit 97dcf3e

Browse files
authored
Reland [macOS] Make FlutterEngine support multiple views (#39576)
1 parent a7c9cc5 commit 97dcf3e

15 files changed

+330
-94
lines changed

shell/platform/darwin/macos/framework/Headers/FlutterEngine.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ extern const uint64_t kFlutterDefaultViewId;
3232

3333
/**
3434
* Coordinates a single instance of execution of a Flutter engine.
35+
*
36+
* A FlutterEngine can only be attached with one controller from the native
37+
* code.
3538
*/
3639
FLUTTER_DARWIN_EXPORT
3740
@interface FlutterEngine : NSObject <FlutterTextureRegistry, FlutterPluginRegistry>
@@ -76,10 +79,9 @@ FLUTTER_DARWIN_EXPORT
7679
- (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint;
7780

7881
/**
79-
* The default `FlutterViewController` associated with this engine, if any.
82+
* The `FlutterViewController` of this engine, if any.
8083
*
81-
* The default view always has ID kFlutterDefaultViewId, and is the view
82-
* operated by the APIs that do not have a view ID specified.
84+
* This view is used by legacy APIs that assume a single view.
8385
*
8486
* Setting this field from nil to a non-nil view controller also updates
8587
* the view controller's engine and ID.

shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ FLUTTER_DARWIN_EXPORT
3636
@property(nonnull, readonly) id<FlutterTextureRegistry> textures;
3737

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

47+
/**
48+
* The `NSView` associated with the given view ID, if any.
49+
*/
50+
- (nullable NSView*)viewForId:(uint64_t)viewId;
51+
4652
/**
4753
* Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|.
4854
*/

shell/platform/darwin/macos/framework/Headers/FlutterViewController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ FLUTTER_DARWIN_EXPORT
8989
NS_DESIGNATED_INITIALIZER;
9090
- (nonnull instancetype)initWithCoder:(nonnull NSCoder*)nibNameOrNil NS_DESIGNATED_INITIALIZER;
9191
/**
92-
* Initializes this FlutterViewController with the specified `FlutterEngine`.
92+
* Initializes this FlutterViewController with an existing `FlutterEngine`.
93+
*
94+
* The initialized view controller will add itself to the engine as part of this process.
9395
*
9496
* This initializer is suitable for both the first Flutter view controller and
9597
* the following ones of the app.

shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TODO(dkwingsmt): This class only supports single-view for now. As more
2020
// classes are gradually converted to multi-view, it should get the view ID
2121
// from somewhere.
22-
FlutterView* view = [view_provider_ getView:kFlutterDefaultViewId];
22+
FlutterView* view = [view_provider_ viewForId:kFlutterDefaultViewId];
2323
if (!view) {
2424
return false;
2525
}
@@ -37,7 +37,7 @@
3737
bool FlutterCompositor::Present(uint64_t view_id,
3838
const FlutterLayer** layers,
3939
size_t layers_count) {
40-
FlutterView* view = [view_provider_ getView:view_id];
40+
FlutterView* view = [view_provider_ viewForId:view_id];
4141
if (!view) {
4242
return false;
4343
}

shell/platform/darwin/macos/framework/Source/FlutterCompositorTest.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
1212
#import "flutter/testing/testing.h"
1313

14+
extern const uint64_t kFlutterDefaultViewId;
15+
1416
@interface FlutterViewMockProvider : NSObject <FlutterViewProvider> {
1517
FlutterView* _defaultView;
1618
}
@@ -30,7 +32,7 @@ - (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view {
3032
return self;
3133
}
3234

33-
- (nullable FlutterView*)getView:(uint64_t)viewId {
35+
- (nullable FlutterView*)viewForId:(uint64_t)viewId {
3436
if (viewId == kFlutterDefaultViewId) {
3537
return _defaultView;
3638
}

0 commit comments

Comments
 (0)