Skip to content

Add focus and blur dispatching logic to BaseViewManager#51724

Closed
Abbondanzo wants to merge 2 commits into
react:mainfrom
Abbondanzo:export-D75579321
Closed

Add focus and blur dispatching logic to BaseViewManager#51724
Abbondanzo wants to merge 2 commits into
react:mainfrom
Abbondanzo:export-D75579321

Conversation

@Abbondanzo

Copy link
Copy Markdown
Contributor

Summary:
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

Differential Revision: D75579321

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 31, 2025
@facebook-github-bot

Copy link
Copy Markdown
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
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
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D75579321

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 5, 2025
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in e960a28.

@react-native-bot

Copy link
Copy Markdown
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants