iOS: Migrate FlutterPlatformPlugin to ARC (flutter/engine#55571)

Migrates from manual reference counting to automatic reference counting. Migrates ivars to property syntax. Makes a minor update to a doc comment.

No semantic changes, therefore not changes to tests.

Issue: https://github.com/flutter/flutter/issues/137801

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Chris Bracken
2024-10-01 16:23:57 -07:00
committed by GitHub
parent 0f379d1523
commit 67060c415c
2 changed files with 25 additions and 29 deletions

View File

@@ -80,6 +80,8 @@ source_set("flutter_framework_source_arc") {
"framework/Source/FlutterMetalLayer.mm",
"framework/Source/FlutterOverlayView.h",
"framework/Source/FlutterOverlayView.mm",
"framework/Source/FlutterPlatformPlugin.h",
"framework/Source/FlutterPlatformPlugin.mm",
"framework/Source/FlutterPlatformViews_Internal.h",
"framework/Source/FlutterPlatformViews_Internal.mm",
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
@@ -184,8 +186,6 @@ source_set("flutter_framework_source") {
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
"framework/Source/FlutterEngine.mm",
"framework/Source/FlutterEngine_Internal.h",
"framework/Source/FlutterPlatformPlugin.h",
"framework/Source/FlutterPlatformPlugin.mm",
"framework/Source/FlutterViewController.mm",
"framework/Source/FlutterViewController_Internal.h",
"framework/Source/accessibility_bridge.h",

View File

@@ -15,6 +15,8 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h"
FLUTTER_ASSERT_ARC
namespace {
constexpr char kTextPlainFormat[] = "text/plain";
@@ -70,14 +72,15 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
* info.plist makes this value to be false.
*/
@property(nonatomic, assign) BOOL enableViewControllerBasedStatusBarAppearance;
@property(nonatomic, weak) FlutterEngine* engine;
/**
* @brief Used to detect whether or not this device supports live text input from the camera.
*/
@property(nonatomic, strong) UITextField* textField;
@end
@implementation FlutterPlatformPlugin {
fml::WeakNSObject<FlutterEngine> _engine;
// Used to detect whether this device has live text input ability or not.
UITextField* _textField;
}
@implementation FlutterPlatformPlugin
- (instancetype)initWithEngine:(fml::WeakNSObject<FlutterEngine>)engine {
FML_DCHECK(engine) << "engine must be set";
@@ -162,7 +165,7 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
- (void)showSystemContextMenu:(NSDictionary*)args {
if (@available(iOS 16.0, *)) {
FlutterTextInputPlugin* textInputPlugin = [_engine.get() textInputPlugin];
FlutterTextInputPlugin* textInputPlugin = [self.engine textInputPlugin];
BOOL shownEditMenu = [textInputPlugin showEditMenu:args];
if (!shownEditMenu) {
FML_LOG(ERROR) << "Only text input supports system context menu for now. Ensure the system "
@@ -174,23 +177,23 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
- (void)hideSystemContextMenu {
if (@available(iOS 16.0, *)) {
FlutterTextInputPlugin* textInputPlugin = [_engine.get() textInputPlugin];
FlutterTextInputPlugin* textInputPlugin = [self.engine textInputPlugin];
[textInputPlugin hideEditMenu];
}
}
- (void)showShareViewController:(NSString*)content {
UIViewController* engineViewController = [_engine.get() viewController];
UIViewController* engineViewController = [self.engine viewController];
NSArray* itemsToShare = @[ content ?: [NSNull null] ];
UIActivityViewController* activityViewController =
[[[UIActivityViewController alloc] initWithActivityItems:itemsToShare
applicationActivities:nil] autorelease];
[[UIActivityViewController alloc] initWithActivityItems:itemsToShare
applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// On iPad, the share screen is presented in a popover view, and requires a
// sourceView and sourceRect
FlutterTextInputPlugin* _textInputPlugin = [_engine.get() textInputPlugin];
FlutterTextInputPlugin* _textInputPlugin = [self.engine textInputPlugin];
UITextRange* range = _textInputPlugin.textInputView.selectedTextRange;
// firstRectForRange cannot be used here as it's current implementation does
@@ -246,16 +249,13 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
}
if ([@"HapticFeedbackType.lightImpact" isEqualToString:feedbackType]) {
[[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight] autorelease]
impactOccurred];
[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight] impactOccurred];
} else if ([@"HapticFeedbackType.mediumImpact" isEqualToString:feedbackType]) {
[[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium] autorelease]
impactOccurred];
[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium] impactOccurred];
} else if ([@"HapticFeedbackType.heavyImpact" isEqualToString:feedbackType]) {
[[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy] autorelease]
impactOccurred];
[[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy] impactOccurred];
} else if ([@"HapticFeedbackType.selectionClick" isEqualToString:feedbackType]) {
[[[[UISelectionFeedbackGenerator alloc] init] autorelease] selectionChanged];
[[[UISelectionFeedbackGenerator alloc] init] selectionChanged];
}
}
@@ -303,7 +303,7 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
object:nil];
}
if (self.enableViewControllerBasedStatusBarAppearance) {
[_engine.get() viewController].prefersStatusBarHidden = statusBarShouldBeHidden;
[self.engine viewController].prefersStatusBarHidden = statusBarShouldBeHidden;
} else {
// Checks if the top status bar should be visible. This platform ignores all
// other overlays
@@ -318,7 +318,7 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
- (void)setSystemChromeEnabledSystemUIMode:(NSString*)mode {
BOOL edgeToEdge = [mode isEqualToString:@"SystemUiMode.edgeToEdge"];
if (self.enableViewControllerBasedStatusBarAppearance) {
[_engine.get() viewController].prefersStatusBarHidden = !edgeToEdge;
[self.engine viewController].prefersStatusBarHidden = !edgeToEdge;
} else {
// Checks if the top status bar should be visible, reflected by edge to edge setting. This
// platform ignores all other system ui modes.
@@ -375,7 +375,7 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
// It's also possible in an Add2App scenario that the FlutterViewController was presented
// outside the context of a UINavigationController, and still wants to be popped.
FlutterViewController* engineViewController = [_engine.get() viewController];
FlutterViewController* engineViewController = [self.engine viewController];
UINavigationController* navigationController = [engineViewController navigationController];
if (navigationController) {
[navigationController popViewControllerAnimated:isAnimated];
@@ -427,9 +427,9 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
}
- (void)showLookUpViewController:(NSString*)term {
UIViewController* engineViewController = [_engine.get() viewController];
UIViewController* engineViewController = [self.engine viewController];
UIReferenceLibraryViewController* referenceLibraryViewController =
[[[UIReferenceLibraryViewController alloc] initWithTerm:term] autorelease];
[[UIReferenceLibraryViewController alloc] initWithTerm:term];
[engineViewController presentViewController:referenceLibraryViewController
animated:YES
completion:nil];
@@ -442,8 +442,4 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
return _textField;
}
- (void)dealloc {
[_textField release];
[super dealloc];
}
@end