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

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented Oct 4, 2024

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

  • 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 the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • We're about one patch away from vanquishing our ARCh enemy... MRC.
  • 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.

@flutter-dashboard
Copy link

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.


- (fml::WeakNSObject<FlutterViewController>)getWeakNSObject {
return _weakFactory->GetWeakNSObject();
}
Copy link
Member Author

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.

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!

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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];
}
Copy link
Contributor

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...)

// keyboard.
//
// We define separate superPresses* overrides to avoid implicitly capturing self in the blocks
// passed to the presses* methods below.
Copy link
Contributor

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.

@stuartmorgan-g
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be copy?

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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.

@cbracken cbracken mentioned this pull request Oct 21, 2024
9 tasks
scrollView.contentOffset = CGPointMake(kScrollViewContentSize, kScrollViewContentSize);

[self.view addSubview:self.scrollView];
[self.view addSubview:scrollView];
Copy link
Member Author

Choose a reason for hiding this comment

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

And that's really the most important part of creating the scrollView – the adding it as a subview.

image

@jmagman
Copy link
Member

jmagman commented Oct 25, 2024

I'm going to convert this to a draft, @cbracken can you mark it as ready when you'd like us to review?

@flutter-dashboard
Copy link

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.

@cbracken cbracken marked this pull request as ready for review October 26, 2024 00:09
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;
Copy link
Member Author

@cbracken cbracken Oct 26, 2024

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.

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 26, 2024
@auto-submit auto-submit bot merged commit 3162aaa into flutter:main Oct 26, 2024
30 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 26, 2024
@cbracken cbracken deleted the arc-viewcontroller branch November 28, 2024 16:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-ios platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants