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

Commit b9073d1

Browse files
[macOS] Make FlutterEngine support multiple views (#37976)
* Rebase all * Do not remove views on hot restart * Remove log, fix doc * Apply suggestions from code review Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> * getDefaultView * postpone deprecation. Add TODO * Apply suggestions from code review Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> * Change to single * Update FlutterEngine.h * Update FlutterEngine_Internal.h --------- Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
1 parent 081b9fc commit b9073d1

15 files changed

+329
-95
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ 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.
44+
*/
45+
- (nullable NSView*)view;
46+
47+
/**
48+
* The `NSView` associated with the given view ID, if any.
4349
*/
44-
@property(nullable, readonly) NSView* view;
50+
- (nullable NSView*)viewForId:(uint64_t)viewId;
4551

4652
/**
4753
* Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|.

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)