Skip to content

Commit

Permalink
Migrate FlutterCallbackCache and FlutterKeyboardManager to ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman committed Apr 9, 2024
1 parent 6dc91bf commit ed4e0e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
8 changes: 4 additions & 4 deletions shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ source_set("flutter_framework_source_arc") {
public_configs = [ "//flutter:config" ]

sources = [
"framework/Source/FlutterCallbackCache.mm",
"framework/Source/FlutterCallbackCache_Internal.h",
"framework/Source/FlutterKeyboardManager.h",
"framework/Source/FlutterKeyboardManager.mm",
"framework/Source/FlutterMetalLayer.h",
"framework/Source/FlutterMetalLayer.mm",
"framework/Source/FlutterTextInputDelegate.h",
Expand All @@ -84,8 +88,6 @@ source_set("flutter_framework_source") {
# New files are highly encouraged to be in ARC.
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
"framework/Source/FlutterAppDelegate.mm",
"framework/Source/FlutterCallbackCache.mm",
"framework/Source/FlutterCallbackCache_Internal.h",
"framework/Source/FlutterChannelKeyResponder.h",
"framework/Source/FlutterChannelKeyResponder.mm",
"framework/Source/FlutterDartProject.mm",
Expand All @@ -100,8 +102,6 @@ source_set("flutter_framework_source") {
"framework/Source/FlutterHeadlessDartRunner.mm",
"framework/Source/FlutterKeyPrimaryResponder.h",
"framework/Source/FlutterKeySecondaryResponder.h",
"framework/Source/FlutterKeyboardManager.h",
"framework/Source/FlutterKeyboardManager.mm",
"framework/Source/FlutterOverlayView.h",
"framework/Source/FlutterOverlayView.mm",
"framework/Source/FlutterPlatformPlugin.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
#include "flutter/fml/logging.h"
#include "flutter/lib/ui/plugins/callback_cache.h"

@implementation FlutterCallbackInformation

- (void)dealloc {
[_callbackName release];
[_callbackClassName release];
[_callbackLibraryPath release];
[super dealloc];
}
FLUTTER_ASSERT_ARC

@implementation FlutterCallbackInformation
@end

@implementation FlutterCallbackCache
Expand All @@ -25,7 +19,7 @@ + (FlutterCallbackInformation*)lookupCallbackInformation:(int64_t)handle {
if (info == nullptr) {
return nil;
}
FlutterCallbackInformation* new_info = [[[FlutterCallbackInformation alloc] init] autorelease];
FlutterCallbackInformation* new_info = [[FlutterCallbackInformation alloc] init];
new_info.callbackName = [NSString stringWithUTF8String:info->name.c_str()];
new_info.callbackClassName = [NSString stringWithUTF8String:info->class_name.c_str()];
new_info.callbackLibraryPath = [NSString stringWithUTF8String:info->library_path.c_str()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// found in the LICENSE file.

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.h"

#include "flutter/fml/platform/darwin/message_loop_darwin.h"
#include "flutter/fml/platform/darwin/weak_nsobject.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"

FLUTTER_ASSERT_ARC

static constexpr CFTimeInterval kDistantFuture = 1.0e10;

Expand All @@ -28,16 +31,13 @@ - (void)dispatchToSecondaryResponders:(nonnull FlutterUIPressProxy*)press

@end

@implementation FlutterKeyboardManager {
std::unique_ptr<fml::WeakNSObjectFactory<FlutterKeyboardManager>> _weakFactory;
}
@implementation FlutterKeyboardManager

- (nonnull instancetype)init {
self = [super init];
if (self != nil) {
_primaryResponders = [[NSMutableArray alloc] init];
_secondaryResponders = [[NSMutableArray alloc] init];
_weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterKeyboardManager>>(self);
}
return self;
}
Expand All @@ -51,21 +51,8 @@ - (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responde
}

- (void)dealloc {
// It will be destroyed and invalidate its weak pointers
// before any other members are destroyed.
_weakFactory.reset();

[_primaryResponders removeAllObjects];
[_secondaryResponders removeAllObjects];
[_primaryResponders release];
[_secondaryResponders release];
_primaryResponders = nil;
_secondaryResponders = nil;
[super dealloc];
}

- (fml::WeakNSObject<FlutterKeyboardManager>)getWeakNSObject {
return _weakFactory->GetWeakNSObject();
}

- (void)handlePress:(nonnull FlutterUIPressProxy*)press
Expand All @@ -89,7 +76,7 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
// encounter.
NSAssert([_primaryResponders count] >= 0, @"At least one primary responder must be added.");

__block auto weakSelf = [self getWeakNSObject];
__block __weak __typeof(self) weakSelf = self;
__block NSUInteger unreplied = [self.primaryResponders count];
__block BOOL anyHandled = false;
FlutterAsyncKeyCallback replyCallback = ^(BOOL handled) {
Expand All @@ -98,7 +85,7 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
anyHandled = anyHandled || handled;
if (unreplied == 0) {
if (!anyHandled && weakSelf) {
[weakSelf.get() dispatchToSecondaryResponders:press complete:completeCallback];
[weakSelf dispatchToSecondaryResponders:press complete:completeCallback];
} else {
completeCallback(true, press);
}
Expand Down

0 comments on commit ed4e0e3

Please sign in to comment.