alibaba / alibaba/flutter_boost

FLBFlutterViewContainer 重写- (void)dismissViewControllerAnimated: completion:逻辑错误,使Flutter页面错误释放,导致APP卡死

Open
#878 1 comment 0 reactions 0 assignees View on GitHub
iOS
Dominant language
Dart
Stars
7.2k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

问题描述:
1. Flutter、Native混编场景
2. 各VC以 `presentViewController:animated:completion:`方式弹出

Flutter页面:A
Native页面:B、C

页面层级:
A->B->C

出错场景:
当想从C回到A,需调用 [A dismissViewControllerAnimated:completion:],此时原生页面正常,Flutter页面A提前释放

错误代码定位:
FLBFlutterViewContainer.m 182行
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
方法重写时未考虑执行dismissViewControllerAnimated的视图控制器不是最上层视图控制器的情况

修改方案:
```
//大致思路:
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
__weak __typeof__(self) weakSelf = self;
__block FLBFlutterViewContainer *presentedViewController = self.presentedViewController;

[super dismissViewControllerAnimated:flag completion:^(){
__strong __typeof__(weakSelf) self = weakSelf;
if (completion) {
completion();
}
//当VC被dismiss时,就通知flutter层销毁page
if (!presentedViewController) {
presentedViewController = self;
}else{
if (![presentedViewController isKindOfClass:FLBFlutterViewContainer.class]) {
return;
}
}
[presentedViewController notifyWillDealloc];
presentedViewController.deallocNotified = YES;
}];
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at FLBFlutterViewContainer.m around line 182 and inspect the overridden dismissViewControllerAnimated:completion: behavior for a container that is not the topmost view controller. Reproduce the A→B→C dismissal scenario, then verify that returning from C to A does not release the Flutter page early or leave the app stuck.

Written by the indexing model from the issue text.

Assessment

Tech stack
flutter, ios, objective-c
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.