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

[iOS] Fixes SplashScreenView crash when remove from view hierarchy #34496

Merged
merged 2 commits into from
Jul 29, 2022

Conversation

zhongwuzw
Copy link
Member

Fixes flutter/flutter#37818 , flutter/flutter#105423. There are some cases that we remove the splashScreenView from superview before add it to view hierarchy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman
Copy link
Member

jmagman commented Jul 13, 2022

cc @cyanglaz

@cyanglaz cyanglaz self-requested a review July 13, 2022 21:12
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM % nits.

@gaaclarke Do you mind taking a secondary review?

Comment on lines 439 to 440
UIView* nilView = nil;
[flutterViewController setSplashScreenView:nilView];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
UIView* nilView = nil;
[flutterViewController setSplashScreenView:nilView];
[flutterViewController setSplashScreenView:nil];

Copy link
Member Author

Choose a reason for hiding this comment

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

@cyanglaz Emm, setSplashScreenView:nil would build error because splashScreenView declare nonnull and we treat build warning as error. Actually we have the case that let user pass the nil to remove the splash screen view, see

- (void)setSplashScreenView:(UIView*)view {
if (!view) {
// Special case: user wants to remove the splash screen view.
if (_splashScreenView) {
[self removeSplashScreenView:nil];
}
return;
}
.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this wrong that we make the view paramter nonnull and still checking nullability in the implementation? Maybe we should update the method syntax to make the parameter nonnull.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like setSplashScreenView should allow nil #6834, probably an oversight from adding NS_ASSUME_NONNULL_BEGIN. Can you instead make the API nullable?

- @property(strong, nonatomic) UIView* splashScreenView;
+ @property(strong, nonatomic, nullable) UIView* splashScreenView;

and add a comment to the header like:

* Set to nil to remove the splash screen view.

Copy link
Member Author

@zhongwuzw zhongwuzw Jul 16, 2022

Choose a reason for hiding this comment

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

@cyanglaz We support view nullable to remove the view from view hierarchy, but we use NS_ASSUME_NONNULL_BEGIN to declare view nonnull.

@jmagman We can make the API nullable, but it may lead to an API-breaking change for Swift users, if Swift users use the getter of splashScreenView, the return type changed from UIView to UIView?.
But I agree that we should make it nullable, should we need to make a new PR as a breaking change to add nullable keyword?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't make this API nullable, it means this feature is not supported on swift, right?
So I think we should introduce the swift breaking change and make the API nullable.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't make this API nullable, it means this feature is not supported on swift, right? So I think we should introduce the swift breaking change and make the API nullable.

@cyanglaz I create another PR to introduce API breaking change. Please review it #34743.

Copy link
Member

Choose a reason for hiding this comment

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

#34743 has merged, apologies for that taking so long. Can you rebase on your change and make this nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jmagman Done. :)

@zhongwuzw zhongwuzw force-pushed the fix_splash_view_crash branch from d4bf336 to 57a4ea3 Compare July 28, 2022 02:39
@zhongwuzw zhongwuzw requested a review from jmagman July 28, 2022 06:54
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to disable splash screen fade on FlutterViewController
3 participants