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

Commit a1a9cde

Browse files
committed
Migrate FlutterCallbackCache and FlutterKeyboardManager to ARC
1 parent 6dc91bf commit a1a9cde

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ source_set("flutter_framework_source_arc") {
5959
public_configs = [ "//flutter:config" ]
6060

6161
sources = [
62+
"framework/Source/FlutterCallbackCache.mm",
63+
"framework/Source/FlutterCallbackCache_Internal.h",
64+
"framework/Source/FlutterKeyboardManager.h",
65+
"framework/Source/FlutterKeyboardManager.mm",
6266
"framework/Source/FlutterMetalLayer.h",
6367
"framework/Source/FlutterMetalLayer.mm",
6468
"framework/Source/FlutterTextInputDelegate.h",
@@ -70,6 +74,8 @@ source_set("flutter_framework_source_arc") {
7074
"UIKit.framework",
7175
"IOSurface.framework",
7276
]
77+
78+
deps += [ "//flutter/lib/ui" ]
7379
}
7480

7581
source_set("flutter_framework_source") {
@@ -84,8 +90,6 @@ source_set("flutter_framework_source") {
8490
# New files are highly encouraged to be in ARC.
8591
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
8692
"framework/Source/FlutterAppDelegate.mm",
87-
"framework/Source/FlutterCallbackCache.mm",
88-
"framework/Source/FlutterCallbackCache_Internal.h",
8993
"framework/Source/FlutterChannelKeyResponder.h",
9094
"framework/Source/FlutterChannelKeyResponder.mm",
9195
"framework/Source/FlutterDartProject.mm",
@@ -100,8 +104,6 @@ source_set("flutter_framework_source") {
100104
"framework/Source/FlutterHeadlessDartRunner.mm",
101105
"framework/Source/FlutterKeyPrimaryResponder.h",
102106
"framework/Source/FlutterKeySecondaryResponder.h",
103-
"framework/Source/FlutterKeyboardManager.h",
104-
"framework/Source/FlutterKeyboardManager.mm",
105107
"framework/Source/FlutterOverlayView.h",
106108
"framework/Source/FlutterOverlayView.mm",
107109
"framework/Source/FlutterPlatformPlugin.h",

shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@
77
#include "flutter/fml/logging.h"
88
#include "flutter/lib/ui/plugins/callback_cache.h"
99

10-
@implementation FlutterCallbackInformation
11-
12-
- (void)dealloc {
13-
[_callbackName release];
14-
[_callbackClassName release];
15-
[_callbackLibraryPath release];
16-
[super dealloc];
17-
}
10+
FLUTTER_ASSERT_ARC
1811

12+
@implementation FlutterCallbackInformation
1913
@end
2014

2115
@implementation FlutterCallbackCache
@@ -25,7 +19,7 @@ + (FlutterCallbackInformation*)lookupCallbackInformation:(int64_t)handle {
2519
if (info == nullptr) {
2620
return nil;
2721
}
28-
FlutterCallbackInformation* new_info = [[[FlutterCallbackInformation alloc] init] autorelease];
22+
FlutterCallbackInformation* new_info = [[FlutterCallbackInformation alloc] init];
2923
new_info.callbackName = [NSString stringWithUTF8String:info->name.c_str()];
3024
new_info.callbackClassName = [NSString stringWithUTF8String:info->class_name.c_str()];
3125
new_info.callbackLibraryPath = [NSString stringWithUTF8String:info->library_path.c_str()];

shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.mm

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// found in the LICENSE file.
44

55
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManager.h"
6+
67
#include "flutter/fml/platform/darwin/message_loop_darwin.h"
7-
#include "flutter/fml/platform/darwin/weak_nsobject.h"
8+
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
9+
10+
FLUTTER_ASSERT_ARC
811

912
static constexpr CFTimeInterval kDistantFuture = 1.0e10;
1013

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

2932
@end
3033

31-
@implementation FlutterKeyboardManager {
32-
std::unique_ptr<fml::WeakNSObjectFactory<FlutterKeyboardManager>> _weakFactory;
33-
}
34+
@implementation FlutterKeyboardManager
3435

3536
- (nonnull instancetype)init {
3637
self = [super init];
3738
if (self != nil) {
3839
_primaryResponders = [[NSMutableArray alloc] init];
3940
_secondaryResponders = [[NSMutableArray alloc] init];
40-
_weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterKeyboardManager>>(self);
4141
}
4242
return self;
4343
}
@@ -51,21 +51,8 @@ - (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responde
5151
}
5252

5353
- (void)dealloc {
54-
// It will be destroyed and invalidate its weak pointers
55-
// before any other members are destroyed.
56-
_weakFactory.reset();
57-
5854
[_primaryResponders removeAllObjects];
5955
[_secondaryResponders removeAllObjects];
60-
[_primaryResponders release];
61-
[_secondaryResponders release];
62-
_primaryResponders = nil;
63-
_secondaryResponders = nil;
64-
[super dealloc];
65-
}
66-
67-
- (fml::WeakNSObject<FlutterKeyboardManager>)getWeakNSObject {
68-
return _weakFactory->GetWeakNSObject();
6956
}
7057

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

92-
__block auto weakSelf = [self getWeakNSObject];
79+
__block __weak __typeof(self) weakSelf = self;
9380
__block NSUInteger unreplied = [self.primaryResponders count];
9481
__block BOOL anyHandled = false;
9582
FlutterAsyncKeyCallback replyCallback = ^(BOOL handled) {
@@ -98,7 +85,7 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
9885
anyHandled = anyHandled || handled;
9986
if (unreplied == 0) {
10087
if (!anyHandled && weakSelf) {
101-
[weakSelf.get() dispatchToSecondaryResponders:press complete:completeCallback];
88+
[weakSelf dispatchToSecondaryResponders:press complete:completeCallback];
10289
} else {
10390
completeCallback(true, press);
10491
}

0 commit comments

Comments
 (0)