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

Commit e116695

Browse files
committed
Migrate FlutterChannelKeyResponder and FlutterSpellCheckPlugin to ARC
1 parent 66ad802 commit e116695

File tree

4 files changed

+37
-58
lines changed

4 files changed

+37
-58
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",
@@ -108,8 +112,6 @@ source_set("flutter_framework_source") {
108112
# New files are highly encouraged to be in ARC.
109113
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
110114
"framework/Source/FlutterAppDelegate.mm",
111-
"framework/Source/FlutterChannelKeyResponder.h",
112-
"framework/Source/FlutterChannelKeyResponder.mm",
113115
"framework/Source/FlutterDartProject.mm",
114116
"framework/Source/FlutterDartProject_Internal.h",
115117
"framework/Source/FlutterEngine.mm",
@@ -126,8 +128,6 @@ source_set("flutter_framework_source") {
126128
"framework/Source/FlutterPluginAppLifeCycleDelegate.mm",
127129
"framework/Source/FlutterSemanticsScrollView.h",
128130
"framework/Source/FlutterSemanticsScrollView.mm",
129-
"framework/Source/FlutterSpellCheckPlugin.h",
130-
"framework/Source/FlutterSpellCheckPlugin.mm",
131131
"framework/Source/FlutterUIPressProxy.h",
132132
"framework/Source/FlutterUIPressProxy.mm",
133133
"framework/Source/FlutterUndoManagerDelegate.h",

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+
NSMutableDictionary* 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+
} mutableCopy];
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: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@
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, readonly) UITextChecker* textChecker;
1933

2034
@end
2135

@@ -88,13 +102,12 @@ - (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 = [[NSMutableArray alloc] init];
92106

93107
for (FlutterSpellCheckResult* result in allSpellSuggestions) {
94108
[methodChannelResult addObject:[result toDictionary]];
95109
}
96110

97-
[allSpellSuggestions release];
98111
return methodChannelResult;
99112
}
100113

@@ -121,19 +134,8 @@ - (FlutterSpellCheckResult*)findSpellCheckSuggestionsForText:(NSString*)text
121134
NSArray<NSString*>* suggestions = [self.textChecker guessesForWordRange:misspelledRange
122135
inString:text
123136
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];
137+
return [[FlutterSpellCheckResult alloc] initWithMisspelledRange:misspelledRange
138+
suggestions:suggestions];
137139
}
138140

139141
@end
@@ -151,18 +153,14 @@ - (instancetype)initWithMisspelledRange:(NSRange)range
151153
}
152154

153155
- (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];
156+
return @{
157+
@"startIndex" : @(_misspelledRange.location),
158+
// The end index represents the next index after the last character of a misspelled word to
159+
// match the behavior of Dart's TextRange:
160+
// https://api.flutter.dev/flutter/dart-ui/TextRange/end.html
161+
@"endIndex" : @(_misspelledRange.location + _misspelledRange.length),
162+
@"suggestions" : _suggestions,
163+
};
166164
}
167165

168166
@end

0 commit comments

Comments
 (0)