Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fixed onChange prop of textinput not be called in some cases #23687

Closed
wants to merge 4 commits into from
Closed
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
30 changes: 20 additions & 10 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
notifyDelegate:YES];

[self textInputDidChange];

_nativeEventCount++;

if (_onChange) {
Copy link
Contributor

@shergin shergin Jun 26, 2019

Choose a reason for hiding this comment

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

I am not comfortable with calling onChange inside textInputShouldChangeTextInRange.

As I said previously, all quicky behavior should be implemented in delegate adapter classes.
I do want to fix this issue very very badly but we cannot sacrifice maintainability of the code for this (so we need to improve the quality of this to make it merged).

_onChange(@{
@"text": _predictedText,
@"target": self.reactTag,
@"eventCount": @(_nativeEventCount),
});
}
}

return NO;
Expand All @@ -417,6 +427,16 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
@"eventCount": @(_nativeEventCount),
});
}

_nativeEventCount++;

if (_onChange) {
_onChange(@{
@"text": _predictedText,
@"target": self.reactTag,
@"eventCount": @(_nativeEventCount),
});
}

return YES;
}
Expand All @@ -439,16 +459,6 @@ - (void)textInputDidChange
// JS will assume the selection changed based on the location of our shouldChangeTextInRange, so reset it.
[self textInputDidChangeSelection];
}

_nativeEventCount++;

if (_onChange) {
_onChange(@{
@"text": self.attributedText.string,
@"target": self.reactTag,
@"eventCount": @(_nativeEventCount),
});
}
}

- (void)textInputDidChangeSelection
Expand Down