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

Commit e7d8c62

Browse files
authored
Migrate FlutterChannelKeyResponder and FlutterSpellCheckPlugin to ARC (#52148)
Clean up headers in FlutterChannelKeyResponder and FlutterSpellCheckPlugin. Migrate to ARC. Move `FlutterSpellCheckResult` interface into the .mm since it's only used there. Part of flutter/flutter#137801. Blocked by #51633 `FlutterUIPressProxy`
1 parent 7c83b12 commit e7d8c62

File tree

4 files changed

+40
-60
lines changed

4 files changed

+40
-60
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ source_set("flutter_framework_source_arc") {
6161
sources = [
6262
"framework/Source/FlutterCallbackCache.mm",
6363
"framework/Source/FlutterCallbackCache_Internal.h",
64+
"framework/Source/FlutterChannelKeyResponder.h",
65+
"framework/Source/FlutterChannelKeyResponder.mm",
6466
"framework/Source/FlutterDartVMServicePublisher.h",
6567
"framework/Source/FlutterDartVMServicePublisher.mm",
6668
"framework/Source/FlutterEmbedderKeyResponder.h",
@@ -73,6 +75,8 @@ source_set("flutter_framework_source_arc") {
7375
"framework/Source/FlutterMetalLayer.mm",
7476
"framework/Source/FlutterRestorationPlugin.h",
7577
"framework/Source/FlutterRestorationPlugin.mm",
78+
"framework/Source/FlutterSpellCheckPlugin.h",
79+
"framework/Source/FlutterSpellCheckPlugin.mm",
7680
"framework/Source/FlutterTextInputDelegate.h",
7781
"framework/Source/FlutterTextInputPlugin.h",
7882
"framework/Source/FlutterTextInputPlugin.mm",
@@ -137,8 +141,6 @@ source_set("flutter_framework_source") {
137141
# New files are highly encouraged to be in ARC.
138142
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
139143
"framework/Source/FlutterAppDelegate.mm",
140-
"framework/Source/FlutterChannelKeyResponder.h",
141-
"framework/Source/FlutterChannelKeyResponder.mm",
142144
"framework/Source/FlutterDartProject.mm",
143145
"framework/Source/FlutterDartProject_Internal.h",
144146
"framework/Source/FlutterEngine.mm",
@@ -155,8 +157,6 @@ source_set("flutter_framework_source") {
155157
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
156158
"framework/Source/FlutterSemanticsScrollView.h",
157159
"framework/Source/FlutterSemanticsScrollView.mm",
158-
"framework/Source/FlutterSpellCheckPlugin.h",
159-
"framework/Source/FlutterSpellCheckPlugin.mm",
160160
"framework/Source/FlutterUndoManagerDelegate.h",
161161
"framework/Source/FlutterUndoManagerPlugin.h",
162162
"framework/Source/FlutterUndoManagerPlugin.mm",

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

55
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponder.h"
66

7-
#import <objc/message.h>
8-
#include <sys/types.h>
9-
#include "fml/memory/weak_ptr.h"
10-
11-
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
12-
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
7+
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
138
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h"
14-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
159
#import "flutter/shell/platform/darwin/ios/framework/Source/KeyCodeMap_Internal.h"
1610

11+
FLUTTER_ASSERT_ARC
12+
1713
namespace {
1814
// An enumeration of the modifier values that the framework expects. These are
1915
// largely the same values as the OS (UIKeyModifierShift, etc.), but because the
@@ -139,7 +135,7 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
139135
NSString* characters = getEventCharacters(press.key.characters, press.key.keyCode);
140136
NSString* charactersIgnoringModifiers =
141137
getEventCharacters(press.key.charactersIgnoringModifiers, press.key.keyCode);
142-
NSMutableDictionary* keyMessage = [[@{
138+
NSDictionary* keyMessage = @{
143139
@"keymap" : @"ios",
144140
@"type" : type,
145141
@"keyCode" : @(press.key.keyCode),
@@ -148,7 +144,7 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
148144
@"charactersIgnoringModifiers" : charactersIgnoringModifiers == nil
149145
? @""
150146
: charactersIgnoringModifiers,
151-
} mutableCopy] autorelease];
147+
};
152148
[self.channel sendMessage:keyMessage
153149
reply:^(id reply) {
154150
bool handled = reply ? [[reply valueForKey:@"handled"] boolValue] : true;

shell/platform/darwin/ios/framework/Source/FlutterSpellCheckPlugin.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,13 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERSPELLCHECKPLUGIN_H_
66
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERSPELLCHECKPLUGIN_H_
77

8-
#include "flutter/fml/memory/weak_ptr.h"
9-
108
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
11-
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
9+
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
1210

1311
@interface FlutterSpellCheckPlugin : NSObject
1412

1513
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
1614

1715
@end
1816

19-
@interface FlutterSpellCheckResult : NSObject
20-
21-
@property(nonatomic, copy, readonly) NSArray<NSString*>* suggestions;
22-
@property(nonatomic, assign, readonly) NSRange misspelledRange;
23-
24-
- (instancetype)init NS_UNAVAILABLE;
25-
+ (instancetype)new NS_UNAVAILABLE;
26-
- (instancetype)initWithMisspelledRange:(NSRange)range
27-
suggestions:(NSArray<NSString*>*)suggestions NS_DESIGNATED_INITIALIZER;
28-
- (NSDictionary<NSString*, NSObject*>*)toDictionary;
29-
30-
@end
31-
3217
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERSPELLCHECKPLUGIN_H_

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

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,39 @@
88
#import <UIKit/UIKit.h>
99

1010
#import "flutter/fml/logging.h"
11-
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
11+
12+
FLUTTER_ASSERT_ARC
1213

1314
// Method Channel name to start spell check.
1415
static NSString* const kInitiateSpellCheck = @"SpellCheck.initiateSpellCheck";
1516

17+
@interface FlutterSpellCheckResult : NSObject
18+
19+
@property(nonatomic, copy, readonly) NSArray<NSString*>* suggestions;
20+
@property(nonatomic, assign, readonly) NSRange misspelledRange;
21+
22+
- (instancetype)init NS_UNAVAILABLE;
23+
+ (instancetype)new NS_UNAVAILABLE;
24+
- (instancetype)initWithMisspelledRange:(NSRange)range
25+
suggestions:(NSArray<NSString*>*)suggestions NS_DESIGNATED_INITIALIZER;
26+
- (NSDictionary<NSString*, NSObject*>*)toDictionary;
27+
28+
@end
29+
1630
@interface FlutterSpellCheckPlugin ()
1731

18-
@property(nonatomic, retain) UITextChecker* textChecker;
32+
@property(nonatomic) UITextChecker* textChecker;
1933

2034
@end
2135

2236
@implementation FlutterSpellCheckPlugin
2337

2438
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
25-
if (!_textChecker) {
39+
if (!self.textChecker) {
2640
// UITextChecker is an expensive object to initiate, see:
2741
// https://github.com/flutter/flutter/issues/104454. Lazily initialate the UITextChecker object
2842
// until at first method channel call. We avoid using lazy getter for testing.
29-
_textChecker = [[UITextChecker alloc] init];
43+
self.textChecker = [[UITextChecker alloc] init];
3044
}
3145
NSString* method = call.method;
3246
NSArray* args = call.arguments;
@@ -88,13 +102,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
88102
}
89103
} while (nextSpellSuggestion != nil && nextOffset < text.length);
90104

91-
NSMutableArray* methodChannelResult = [[[NSMutableArray alloc] init] autorelease];
105+
NSMutableArray* methodChannelResult =
106+
[[NSMutableArray alloc] initWithCapacity:allSpellSuggestions.count];
92107

93108
for (FlutterSpellCheckResult* result in allSpellSuggestions) {
94109
[methodChannelResult addObject:[result toDictionary]];
95110
}
96111

97-
[allSpellSuggestions release];
98112
return methodChannelResult;
99113
}
100114

@@ -121,19 +135,8 @@ - (FlutterSpellCheckResult*)findSpellCheckSuggestionsForText:(NSString*)text
121135
NSArray<NSString*>* suggestions = [self.textChecker guessesForWordRange:misspelledRange
122136
inString:text
123137
language:language];
124-
FlutterSpellCheckResult* result =
125-
[[[FlutterSpellCheckResult alloc] initWithMisspelledRange:misspelledRange
126-
suggestions:suggestions] autorelease];
127-
return result;
128-
}
129-
130-
- (UITextChecker*)textChecker {
131-
return _textChecker;
132-
}
133-
134-
- (void)dealloc {
135-
[_textChecker release];
136-
[super dealloc];
138+
return [[FlutterSpellCheckResult alloc] initWithMisspelledRange:misspelledRange
139+
suggestions:suggestions];
137140
}
138141

139142
@end
@@ -151,18 +154,14 @@ - (instancetype)initWithMisspelledRange:(NSRange)range
151154
}
152155

153156
- (NSDictionary<NSString*, NSObject*>*)toDictionary {
154-
NSMutableDictionary* result = [[[NSMutableDictionary alloc] initWithCapacity:3] autorelease];
155-
result[@"startIndex"] = @(_misspelledRange.location);
156-
// The end index represents the next index after the last character of a misspelled word to match
157-
// the behavior of Dart's TextRange: https://api.flutter.dev/flutter/dart-ui/TextRange/end.html
158-
result[@"endIndex"] = @(_misspelledRange.location + _misspelledRange.length);
159-
result[@"suggestions"] = _suggestions;
160-
return result;
161-
}
162-
163-
- (void)dealloc {
164-
[_suggestions release];
165-
[super dealloc];
157+
return @{
158+
@"startIndex" : @(_misspelledRange.location),
159+
// The end index represents the next index after the last character of a misspelled word to
160+
// match the behavior of Dart's TextRange:
161+
// https://api.flutter.dev/flutter/dart-ui/TextRange/end.html
162+
@"endIndex" : @(_misspelledRange.location + _misspelledRange.length),
163+
@"suggestions" : _suggestions,
164+
};
166165
}
167166

168167
@end

0 commit comments

Comments
 (0)