This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate FlutterChannelKeyResponder and FlutterSpellCheckPlugin to ARC #52148
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Migrate FlutterChannelKeyResponder and FlutterSpellCheckPlugin to ARC
- Loading branch information
commit 6106d3baeb7c33bbb18b1ed2708f687469211a41
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,25 +8,39 @@ | |
| #import <UIKit/UIKit.h> | ||
|
|
||
| #import "flutter/fml/logging.h" | ||
| #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" | ||
|
|
||
| FLUTTER_ASSERT_ARC | ||
|
|
||
| // Method Channel name to start spell check. | ||
| static NSString* const kInitiateSpellCheck = @"SpellCheck.initiateSpellCheck"; | ||
|
|
||
| @interface FlutterSpellCheckResult : NSObject | ||
|
|
||
| @property(nonatomic, copy, readonly) NSArray<NSString*>* suggestions; | ||
| @property(nonatomic, assign, readonly) NSRange misspelledRange; | ||
|
|
||
| - (instancetype)init NS_UNAVAILABLE; | ||
| + (instancetype)new NS_UNAVAILABLE; | ||
| - (instancetype)initWithMisspelledRange:(NSRange)range | ||
| suggestions:(NSArray<NSString*>*)suggestions NS_DESIGNATED_INITIALIZER; | ||
| - (NSDictionary<NSString*, NSObject*>*)toDictionary; | ||
|
|
||
| @end | ||
|
|
||
| @interface FlutterSpellCheckPlugin () | ||
|
|
||
| @property(nonatomic, retain) UITextChecker* textChecker; | ||
| @property(nonatomic) UITextChecker* textChecker; | ||
|
|
||
| @end | ||
|
|
||
| @implementation FlutterSpellCheckPlugin | ||
|
|
||
| - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | ||
| if (!_textChecker) { | ||
| if (!self.textChecker) { | ||
| // UITextChecker is an expensive object to initiate, see: | ||
| // https://github.com/flutter/flutter/issues/104454. Lazily initialate the UITextChecker object | ||
| // until at first method channel call. We avoid using lazy getter for testing. | ||
| _textChecker = [[UITextChecker alloc] init]; | ||
| self.textChecker = [[UITextChecker alloc] init]; | ||
| } | ||
| NSString* method = call.method; | ||
| NSArray* args = call.arguments; | ||
|
|
@@ -88,13 +102,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
| } | ||
| } while (nextSpellSuggestion != nil && nextOffset < text.length); | ||
|
|
||
| NSMutableArray* methodChannelResult = [[[NSMutableArray alloc] init] autorelease]; | ||
| NSMutableArray* methodChannelResult = [[NSMutableArray alloc] init]; | ||
|
||
|
|
||
| for (FlutterSpellCheckResult* result in allSpellSuggestions) { | ||
| [methodChannelResult addObject:[result toDictionary]]; | ||
| } | ||
|
|
||
| [allSpellSuggestions release]; | ||
| return methodChannelResult; | ||
| } | ||
|
|
||
|
|
@@ -121,19 +134,8 @@ - (FlutterSpellCheckResult*)findSpellCheckSuggestionsForText:(NSString*)text | |
| NSArray<NSString*>* suggestions = [self.textChecker guessesForWordRange:misspelledRange | ||
| inString:text | ||
| language:language]; | ||
| FlutterSpellCheckResult* result = | ||
| [[[FlutterSpellCheckResult alloc] initWithMisspelledRange:misspelledRange | ||
| suggestions:suggestions] autorelease]; | ||
| return result; | ||
| } | ||
|
|
||
| - (UITextChecker*)textChecker { | ||
| return _textChecker; | ||
| } | ||
|
|
||
| - (void)dealloc { | ||
| [_textChecker release]; | ||
| [super dealloc]; | ||
| return [[FlutterSpellCheckResult alloc] initWithMisspelledRange:misspelledRange | ||
| suggestions:suggestions]; | ||
| } | ||
|
|
||
| @end | ||
|
|
@@ -151,18 +153,14 @@ - (instancetype)initWithMisspelledRange:(NSRange)range | |
| } | ||
|
|
||
| - (NSDictionary<NSString*, NSObject*>*)toDictionary { | ||
| NSMutableDictionary* result = [[[NSMutableDictionary alloc] initWithCapacity:3] autorelease]; | ||
| result[@"startIndex"] = @(_misspelledRange.location); | ||
| // The end index represents the next index after the last character of a misspelled word to match | ||
| // the behavior of Dart's TextRange: https://api.flutter.dev/flutter/dart-ui/TextRange/end.html | ||
| result[@"endIndex"] = @(_misspelledRange.location + _misspelledRange.length); | ||
| result[@"suggestions"] = _suggestions; | ||
| return result; | ||
| } | ||
|
|
||
| - (void)dealloc { | ||
| [_suggestions release]; | ||
| [super dealloc]; | ||
| return @{ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid the |
||
| @"startIndex" : @(_misspelledRange.location), | ||
| // The end index represents the next index after the last character of a misspelled word to | ||
| // match the behavior of Dart's TextRange: | ||
| // https://api.flutter.dev/flutter/dart-ui/TextRange/end.html | ||
| @"endIndex" : @(_misspelledRange.location + _misspelledRange.length), | ||
| @"suggestions" : _suggestions, | ||
| }; | ||
| } | ||
|
|
||
| @end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just make this an
NSDictionaryand remove themutableCopy;sendMessage:doesn't require a mutable dictionary. I looked at the history; there used to be conditional additional key/value setting logic, which is why it was mutable, but now that's just cruft.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.