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 1 commit
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 shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ - (void)setViewController:(FlutterViewController*)viewController {
}
}

- (void)attachView {
self.iosPlatformView->attachView();
}

- (void)setFlutterViewControllerWillDeallocObserver:(id<NSObject>)observer {
if (observer != _flutterViewControllerWillDeallocObserver) {
if (_flutterViewControllerWillDeallocObserver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- (FlutterTextInputPlugin*)textInputPlugin;
- (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
- (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
- (void)attachView;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ @implementation FlutterViewController {
BOOL _initialized;
BOOL _viewOpaque;
BOOL _engineNeedsLaunch;
BOOL _isAttchedView;
NSMutableSet<NSNumber*>* _ongoingTouches;
}

Expand Down Expand Up @@ -450,6 +451,13 @@ - (void)viewWillAppear:(BOOL)animated {
_engineNeedsLaunch = NO;
}

if (!_isAttchedView) {
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be more appropriate in loadView? Wouldn't that timing more match how it was previously and you wouldn't have to keep an extra bool _isViewAttached?

Copy link
Contributor

Choose a reason for hiding this comment

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

Will loadView ever get called more than once in the lifecycle of a UIViewController?

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked offline - the answer should be no

Copy link
Member

Choose a reason for hiding this comment

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

It should only be called once. We should actually use viewDidLoad since it's a bit safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So need also call setViewController in viewDidLoad. Is that right?

FML_DCHECK([_engine.get() viewController] != nil)
<< "FlutterViewController::viewWillAppear:AttachView ViewController was nil";
[_engine.get() attachView];
_isAttchedView = YES;
}

// Send platform settings to Flutter, e.g., platform brightness.
[self onUserSettingsChanged:nil];

Expand Down
1 change: 1 addition & 0 deletions shell/platform/darwin/ios/platform_view_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PlatformViewIOS final : public PlatformView {

fml::WeakPtr<FlutterViewController> GetOwnerViewController() const;
void SetOwnerViewController(fml::WeakPtr<FlutterViewController> owner_controller);
void attachView();

void RegisterExternalTexture(int64_t id, NSObject<FlutterTexture>* texture);

Expand Down
15 changes: 9 additions & 6 deletions shell/platform/darwin/ios/platform_view_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,24 @@
accessibility_bridge_.reset();
owner_controller_.reset();
}] retain]);

// Do not call `NotifyCreated()` here - let FlutterViewController take care
// of that when its Viewport is sized. If `NotifyCreated()` is called here,
// it can occasionally get invoked before the viewport is sized resulting in
// a framebuffer that will not be able to completely attach.
}

void PlatformViewIOS::attachView() {
if (owner_controller_) {
ios_surface_ =
[static_cast<FlutterView*>(owner_controller.get().view) createSurface:gl_context_];
[static_cast<FlutterView*>(owner_controller_.get().view) createSurface:gl_context_];
FML_DCHECK(ios_surface_ != nullptr);

if (accessibility_bridge_) {
accessibility_bridge_.reset(
new AccessibilityBridge(static_cast<FlutterView*>(owner_controller_.get().view), this,
[owner_controller.get() platformViewsController]));
[owner_controller_.get() platformViewsController]));
}
// Do not call `NotifyCreated()` here - let FlutterViewController take care
// of that when its Viewport is sized. If `NotifyCreated()` is called here,
// it can occasionally get invoked before the viewport is sized resulting in
// a framebuffer that will not be able to completely attach.
}
}

Expand Down