-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate FlutterViewController to ARC #55669
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
|
||
- (fml::WeakNSObject<FlutterViewController>)getWeakNSObject { | ||
return _weakFactory->GetWeakNSObject(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needed by FlutterEngine, which calls this, and puts it into a field in a C++ class in platform_view_ios.h, which I'll migrate in the next patch.
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
self.engineNeedsLaunch = NO; | ||
} else if (self.engine.viewController == self) { | ||
[self.engine attachView]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Definitely not in scope for this PR, but it sure feels like this method and the last method could use some refactoring into engine methods given that they mostly walls of self.engine
calls...)
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
// keyboard. | ||
// | ||
// We define separate superPresses* overrides to avoid implicitly capturing self in the blocks | ||
// passed to the presses* methods below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an interesting (but maybe theoretical) question here: if handling a press both caused self
to be released, but also claimed not to have handled the event (I'm not sure why that would happen, but I suspect you could write Dart code that would do it if you really wanted to), isn't the right thing to still forward the press to super
?
If so, we actually would want the implicit capture. Since these are fire-once callbacks, capture isn't necessarily a problem. I did look at the usage though, and I can imagine a case where for some reason we never get the callback for some press due to an engine bug, and suddenly we have a leak that would be extremely hard to find.
This conversion makes sense in the context of the PR since the old code wasn't a strong ref, but since this structure and comment is making the non-retaining nature much more explicit I wanted to flag it as something the team may want to think about later.
test-exempt: code refactor with no semantic change |
// We keep a separate reference to this and create it ahead of time because we want to be able to | ||
// set up a shell along with its platform view before the view has to appear. | ||
@property(nonatomic, strong) FlutterView* flutterView; | ||
@property(nonatomic, strong) void (^flutterViewRenderedCallback)(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: copy
(tho same behavior as strong in ARC)
@property(nonatomic, assign) BOOL isHomeIndicatorHidden; | ||
@property(nonatomic, assign) BOOL isPresentingViewControllerAnimating; | ||
|
||
@property(nonatomic, strong) NSMutableSet<NSNumber*>* ongoingTouches; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be copy?
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM with one nit.
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
scrollView.contentOffset = CGPointMake(kScrollViewContentSize, kScrollViewContentSize); | ||
|
||
[self.view addSubview:self.scrollView]; | ||
[self.view addSubview:scrollView]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to convert this to a draft, @cbracken can you mark it as ready when you'd like us to review? |
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. |
Commit crime... then immediately cover my tracks so it looks like the scrollView is set. I mean it is... it's just never added to the view hierarchy, which is really the most important part.
Previously we held a scoped_nsobject<FlutterEngine> as a strong reference ivar. This restores that behaviour.
fml::ScopedBlock<void (^)(void)> _flutterViewRenderedCallback; | ||
UIInterfaceOrientationMask _orientationPreferences; | ||
UIStatusBarStyle _statusBarStyle; | ||
FlutterEngine* _engine; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that previously we held _engine
as a strong ref (the fml::scoped_nsobject
above) but that the header declares it as a weak property:
@property(weak, nonatomic, readonly) FlutterEngine* engine; |
Meanwhile, the engine owns FlutterViewController weakly:
fml::WeakNSObject<FlutterViewController> _viewController; |
To preserve existing semantics, I'm adding back a strong ref here. We need the getter too so that the compiler doesn't complain that the ivar should be declared as __weak FlutterEngine* _engine
.
We should probably update the header to be a strong property, but it's a public header and I don't think that ARC migration is the right spot to change semantics in our public APIs.
Migrates
FlutterViewController
from manual reference counting to ARC. Eliminates use of scoped_nsobject and scoped_nsprotocol, and migrates ivars to property syntax where possible.No semantic changes, therefore no changes to tests.
Issue: flutter/flutter#137801
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.