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

fix: propagate textDidChangeNotification and editingChanged events further #305

Conversation

kirillzyusko
Copy link

@kirillzyusko kirillzyusko commented Jan 20, 2024

Right now if I add another listener for editingChanged event -> I'll not get any updates.

It happens because of problem described here (a particular issue with discussion was in RedMadRobot/input-mask-ios#12 but it's in Russian language).

In general author of input-mask-ios suggest to add a custom delegate with onEditingChanged callback. However for 3rd party libraries (such as react-native-keyboard-controller it could be a problematic approach, because I need to set a callback to textField delegate - but for that I need to know the interface/protocol of this delegate, and I can not import this protocol from react-native-text-input-mask - in order to do this I need to make a dependency on react-native-text-input-mask in Podfile, but it should be optional dependency and I feel like it makes an approach very complicated without explicit benefits).

So I went with an approach where we directly re-send events 👀

Feel free to suggest other alternatives if you have them!

Also for reference I'm attaching an original PR with fix from react-native-keyboard-controller: kirillzyusko/react-native-keyboard-controller#341

kirillzyusko added a commit to kirillzyusko/react-native-keyboard-controller that referenced this pull request Jan 21, 2024
…nput from `react-native-text-input-mask` on iOS (#341)

## 📜 Description

Fixed a problem when `onTextChange` is not fired on iOS if `TextInput`
from `react-native-text-input-mask`.

## 💡 Motivation and Context

The issue and solution is described
[here](https://github.com/RedMadRobot/input-mask-ios?tab=readme-ov-file#uitextfieldtextdidchange-notification-and-target-action-editingchanged-event).

However, if I add delegate with `onEditingChanged` method, then I can
not assign my listener to this callback (the delegate can not be casted
to my own type and I can not import existing class from another module
because RNKC is not depending on another module). And adding an optional
dependency to Podfile makes installation process harder and I don't see
explicit benefits of making the approach more complex.

For now I'll go with this solution (also I opened a PR to
`react-native-text-input-mask`, see
react-native-text-input-mask/react-native-text-input-mask#305).
Maybe later I'll revisit and make it more sophisticated, but for now we
have a working solution and I'm pretty happy with that.

Closes
#330

## 📢 Changelog

### Docs
- add a reference to the known problem (it should be fixable by applying
a patch);

### E2E
- added new test to check that `react-native-text-input-mask`
integration works;

### JS

- changed icon for `react-native-text-input-mask` example;
- specified `black` color for TextInput in
`react-native-text-input-mask` example;
- patched `react-native-text-input-mask` library;

## 🤔 How Has This Been Tested?

Tested on iPhone 15 Pro 17.2

## 📸 Screenshots (if appropriate):

|Before|After|
|------|------|

|![image](https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/ff1cbf24-ea58-4ffb-b5ac-5d9ab4ff64ee)|![image](https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/e08021bf-74e6-4ebc-b40e-b196f9a9a817)|

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
@kirillzyusko
Copy link
Author

Eventually I went into a different direction and I'm adding own delegate to focused inputs (and consume editingChanged events on delegate level): kirillzyusko/react-native-keyboard-controller#435

I'm closing this PR as it's not needed anymore, I believe 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant