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

Commit 8e669bf

Browse files
committed
Fix issue viewdidload call while init FlutterViewController
1 parent 7ef88f8 commit 8e669bf

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ - (void)setViewController:(FlutterViewController*)viewController {
204204
}
205205
}
206206

207+
- (void)attachView {
208+
self.iosPlatformView->attachView();
209+
}
210+
207211
- (void)setFlutterViewControllerWillDeallocObserver:(id<NSObject>)observer {
208212
if (observer != _flutterViewControllerWillDeallocObserver) {
209213
if (_flutterViewControllerWillDeallocObserver) {

shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- (FlutterTextInputPlugin*)textInputPlugin;
4545
- (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
4646
- (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil;
47+
- (void)attachView;
4748

4849
@end
4950

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ @implementation FlutterViewController {
6363
BOOL _initialized;
6464
BOOL _viewOpaque;
6565
BOOL _engineNeedsLaunch;
66+
BOOL _needInjectPlatformView;
6667
NSMutableSet<NSNumber*>* _ongoingTouches;
6768
}
6869

@@ -78,10 +79,13 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine
7879
if (self) {
7980
_viewOpaque = YES;
8081
_engine.reset([engine retain]);
82+
8183
_engineNeedsLaunch = NO;
84+
_needInjectPlatformView = YES;
8285
_flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]);
8386
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self);
8487
_ongoingTouches = [[NSMutableSet alloc] init];
88+
8589

8690
[self performCommonViewControllerInitialization];
8791
[engine setViewController:self];
@@ -450,6 +454,11 @@ - (void)viewWillAppear:(BOOL)animated {
450454
_engineNeedsLaunch = NO;
451455
}
452456

457+
if (_needInjectPlatformView) {
458+
[_engine.get() attachView];
459+
_needInjectPlatformView = NO;
460+
}
461+
453462
// Send platform settings to Flutter, e.g., platform brightness.
454463
[self onUserSettingsChanged:nil];
455464

shell/platform/darwin/ios/platform_view_ios.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class PlatformViewIOS final : public PlatformView {
3434

3535
fml::WeakPtr<FlutterViewController> GetOwnerViewController() const;
3636
void SetOwnerViewController(fml::WeakPtr<FlutterViewController> owner_controller);
37+
void attachView();
3738

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

shell/platform/darwin/ios/platform_view_ios.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,19 @@
6464
owner_controller_.reset();
6565
}] retain]);
6666

67+
68+
}
69+
70+
void PlatformViewIOS::attachView() {
6771
if (owner_controller_) {
6872
ios_surface_ =
69-
[static_cast<FlutterView*>(owner_controller.get().view) createSurface:gl_context_];
73+
[static_cast<FlutterView*>(owner_controller_.get().view) createSurface:gl_context_];
7074
FML_DCHECK(ios_surface_ != nullptr);
7175

7276
if (accessibility_bridge_) {
7377
accessibility_bridge_.reset(
7478
new AccessibilityBridge(static_cast<FlutterView*>(owner_controller_.get().view), this,
75-
[owner_controller.get() platformViewsController]));
79+
[owner_controller_.get() platformViewsController]));
7680
}
7781
// Do not call `NotifyCreated()` here - let FlutterViewController take care
7882
// of that when its Viewport is sized. If `NotifyCreated()` is called here,

0 commit comments

Comments
 (0)