Skip to content

Commit

Permalink
fix: do not overwrite external inputAccessoryView on Fabric (#48339)
Browse files Browse the repository at this point in the history
Summary:
If 3rd party libs are using `inputAccessoryView` - the current code can easily break it. Whenever props gets changed we call `setDefaultInputAccessoryView` which will simply overwrite the current `inputAccessoryView` (which is highly undesirable).

The same fix on paper was made ~7 years ago: bf36983

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[IOS] [FIXED] - Fixed problem with accessory view & 3rd party libs

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #48339

Test Plan: Make sure `inputAccessoryView` functionality works as before

Reviewed By: javache

Differential Revision: D67451188

Pulled By: cipolleschi

fbshipit-source-id: bc3fa82ae15f8acedfd0b4e17bdea69cbd8c8a8d
  • Loading branch information
kirillzyusko authored and robhogan committed Dec 30, 2024
1 parent 489b22c commit d34032b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ @implementation RCTTextInputComponentView {
* later comparison insensitive to them.
*/
NSDictionary<NSAttributedStringKey, id> *_originalTypingAttributes;

BOOL _hasInputAccessoryView;
}

#pragma mark - UIView overrides
Expand Down Expand Up @@ -610,10 +612,12 @@ - (void)setDefaultInputAccessoryView
keyboardType == UIKeyboardTypeDecimalPad || keyboardType == UIKeyboardTypeASCIICapableNumberPad) &&
(containsKeyType || containsInputAccessoryViewButtonLabel);

if ((_backedTextInputView.inputAccessoryView != nil) == shouldHaveInputAccessoryView) {
if (_hasInputAccessoryView == shouldHaveInputAccessoryView) {
return;
}

_hasInputAccessoryView = shouldHaveInputAccessoryView;

if (shouldHaveInputAccessoryView) {
NSString *buttonLabel = inputAccessoryViewButtonLabel != nil ? inputAccessoryViewButtonLabel
: [self returnKeyTypeToString:returnKeyType];
Expand Down

0 comments on commit d34032b

Please sign in to comment.