Add focus/blur commands to View (#53828)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53828

Adds focus and blur commands to Android views.

Changelog: [Internal]

Reviewed By: rozele

Differential Revision: D82644681

fbshipit-source-id: 96fa6370e177c91742d285b0b158b77447d105f6
This commit is contained in:
Devan Buggay
2025-09-18 00:36:55 -07:00
committed by Facebook GitHub Bot
parent 2945fa6e0e
commit 14458d8699
2 changed files with 22 additions and 0 deletions
@@ -416,6 +416,14 @@ public open class ReactViewGroup public constructor(context: Context?) :
updateClippingToRect(clippingRect, excludedViews)
}
internal fun requestFocusFromJS() {
super.requestFocus(FOCUS_DOWN, null)
}
internal fun clearFocusFromJS() {
super.clearFocus()
}
override fun endViewTransition(view: View) {
super.endViewTransition(view)
childrenRemovedWhileTransitioning?.remove(view.id)
@@ -404,6 +404,8 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
when (commandId) {
HOTSPOT_UPDATE_KEY -> handleHotspotUpdate(root, args)
"setPressed" -> handleSetPressed(root, args)
"focus" -> handleFocus(root)
"blur" -> handleBlur(root)
else -> {}
}
}
@@ -428,4 +430,16 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
val y = args.getDouble(1).dpToPx()
root.drawableHotspotChanged(x, y)
}
private fun handleFocus(root: ReactViewGroup) {
if (ReactNativeFeatureFlags.enableImperativeFocus()) {
root.requestFocusFromJS()
}
}
private fun handleBlur(root: ReactViewGroup) {
if (ReactNativeFeatureFlags.enableImperativeFocus()) {
root.clearFocusFromJS()
}
}
}