Add focus and blur dispatching logic to BaseViewManager#51724
Closed
Abbondanzo wants to merge 2 commits into
Closed
Add focus and blur dispatching logic to BaseViewManager#51724Abbondanzo wants to merge 2 commits into
Abbondanzo wants to merge 2 commits into
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D75579321 |
Summary: As the title suggests, forwards `onBlur`/`onFocus` props into the Pressability config that the component creates. Also updates `TouchableWithoutFeedback` to pass its `onFocus`/`onBlur` props from the config into elementProps on Android only since they've been added to Android's BaseViewConfig Changelog: [Internal] Differential Revision: D75238328
f0eb79a to
1c14213
Compare
Summary: Pull Request resolved: #51724 Moves focus change listener logic from `ReactViewManager` to `BaseViewManager` so all view managers that extend the class can get focus/blur event dispatching for free. This does so by applying event listeners where `addEventEmitters` is called, so any extending classes must try to call `super.addEventEmitters` or implement it themselves. In the case of TextInput, this logic is re-implemented because the component emits an additional event when the text input is blurred and I wanted to avoid duplicate calls to get the event emitter for the view instance. In addition, I've added logic and a test case to ensure that any preexisting focus change listeners set on the view instance are called. There can only ever be one focus change listener tied to a view instance, so this ensures that ones created during view instantiation are retained. However, this does not guarantee that events are emitted for downstream users who overwrite the focus change listener later in the view's lifecycle (i.e. in response to a prop change or an extending view manager that doesn't call `super.addEventEmitters`). There is no clean way to enforce that the `BaseViewManager` focus change listener is always set without changing the generics and introducing a significant breaking change. Changelog: [Android][Added] - Adds support for onFocus/onBlur event dispatching logic to all native views that implement `BaseViewManager` Reviewed By: NickGerleman Differential Revision: D75579321
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D75579321 |
1c14213 to
d273d2e
Compare
Contributor
|
This pull request has been merged in e960a28. |
Collaborator
|
This pull request was successfully merged by @Abbondanzo in e960a28 When will my fix make it into a release? | How to file a pick request? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Moves focus change listener logic from
ReactViewManagertoBaseViewManagerso all view managers that extend the class can get focus/blur event dispatching for free. This does so by applying event listeners whereaddEventEmittersis called, so any extending classes must try to callsuper.addEventEmittersor implement it themselves. In the case of TextInput, this logic is re-implemented because the component emits an additional event when the text input is blurred and I wanted to avoid duplicate calls to get the event emitter for the view instance.In addition, I've added logic and a test case to ensure that any preexisting focus change listeners set on the view instance are called. There can only ever be one focus change listener tied to a view instance, so this ensures that ones created during view instantiation are retained. However, this does not guarantee that events are emitted for downstream users who overwrite the focus change listener later in the view's lifecycle (i.e. in response to a prop change or an extending view manager that doesn't call
super.addEventEmitters). There is no clean way to enforce that theBaseViewManagerfocus change listener is always set without changing the generics and introducing a significant breaking change.Changelog: [Android][Added] - Adds support for onFocus/onBlur event dispatching logic to all native views that implement
BaseViewManagerDifferential Revision: D75579321