Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
static NSString* const kAutofillHints = @"hints";

static NSString* const kAutocorrectionType = @"autocorrect";
static NSString* const kEnableSuggestions = @"enableSuggestions";

#pragma mark - Static Functions

Expand Down Expand Up @@ -934,8 +935,10 @@ - (void)configureWithDictionary:(NSDictionary*)configuration {
bool autocorrectIsDisabled = autocorrect && ![autocorrect boolValue];
self.autocorrectionType =
autocorrectIsDisabled ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;
NSString* enableSuggestions = configuration[kEnableSuggestions];
bool disableSuggestions = enableSuggestions && ![enableSuggestions boolValue];
Copy link
Member

@cbracken cbracken Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes:

  • In Objective-C we should be using BOOL, not bool. In this case, the surrounding code is unfortunately already using C++ bool. I'll send a separate cleanup patch.
  • The Dart side API for this is enableSuggestions, for readability, please deal with this settings in terms of enableSuggestions in the Obj-C code. See the style guide rationale for why. Again, the surrounding code violates this and I'll send a separate patch to clean it up.

Something like this works:

NSString* enableSuggestionsValue = configuration[kEnableSuggestions];
BOOL enableSuggestions = enabledSuggestionsValue ? enableSuggestionsValue.boolValue : YES;

self.spellCheckingType =
autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault;
disableSuggestions ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code was landed by @bleroux in #46144 to fix flutter/flutter#134881. Updating this behaviour will be a minor regression to users who were relying on disabling autocorrect to disable spelling suggestions, but that seems reasonable since this adds a new finer-grained mechanism to opt out.

The enableSuggestions API docs currently state that this flag only affects Android. @bleroux do you know the background on why we don't apply it to iOS as well?

If we change this behaviour, we will definitely need to update the framework side API documentation to reflect this and point to Apple's UITextSpellCheckingType docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enableSuggestions API docs currently state that this flag only affects Android. @bleroux do you know the background on why we don't apply it to iOS as well?

I don't know the background. The documentation landed in flutter/flutter#42550. It seems that this was implemented to match an Android feature. Maybe something similar did not exist on the iOS side at that time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that it wasn't possible to control these independently at the time that Flutter's enableSuggestions was added. Are we sure that's not still true? +1 to updating the docs if this change lands.

self.autofillId = AutofillIdFromDictionary(configuration);
if (autofill == nil) {
self.textContentType = @"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,23 +810,6 @@ - (void)testInputActionContinueAction {
OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/textinput" message:encodedMethodCall]);
}

- (void)testDisablingAutocorrectDisablesSpellChecking {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];

// Disable the interactive selection.
NSDictionary* config = self.mutableTemplateCopy;
[inputView configureWithDictionary:config];

XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeDefault);
XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeDefault);

[config setValue:@(NO) forKey:@"autocorrect"];
[inputView configureWithDictionary:config];

XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeNo);
XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeNo);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't delete tests for existing behaviour; they were added for a reason.

You'll need to update the existing test to reflect the new expected behaviour and add additional testing to cover all four combinations of autocorrect/enableSuggestions.

- (void)testReplaceTestLocalAdjustSelectionAndMarkedTextRange {
FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin];
[inputView setMarkedText:@"test text" selectedRange:NSMakeRange(0, 5)];
Expand Down