From 8fd2f1263c0a739aa74c82832c7cdb75027d7105 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 10 Jan 2024 07:01:22 -0800 Subject: [PATCH] BridgelessUIManager: Finish focus, blur (#42210) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42210 Implement Focus and blur, by using commands. Changelog: [Internal] Reviewed By: dmytrorykun Differential Revision: D52383997 fbshipit-source-id: ca3c20d77b17147b592cbf3c48772b857a2e2c55 --- .../ReactNative/BridgelessUIManager.js | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js b/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js index bbc460ffc95fb3..b36d937e38cd43 100644 --- a/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js +++ b/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js @@ -217,10 +217,38 @@ const UIManagerJSPlatformAPIs = Platform.select({ return {}; }, focus: (reactTag: ?number): void => { - raiseSoftError('focus'); + if (reactTag == null) { + console.error( + `focus() noop: Cannot be called with ${String(reactTag)} reactTag`, + ); + return; + } + + const FabricUIManager = nullthrows(getFabricUIManager()); + const shadowNode = + FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag); + if (!shadowNode) { + console.error(`focus() noop: Cannot find view with tag #${reactTag}`); + return; + } + FabricUIManager.dispatchCommand(shadowNode, 'focus', []); }, blur: (reactTag: ?number): void => { - raiseSoftError('blur'); + if (reactTag == null) { + console.error( + `blur() noop: Cannot be called with ${String(reactTag)} reactTag`, + ); + return; + } + + const FabricUIManager = nullthrows(getFabricUIManager()); + const shadowNode = + FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag); + if (!shadowNode) { + console.error(`blur() noop: Cannot find view with tag #${reactTag}`); + return; + } + FabricUIManager.dispatchCommand(shadowNode, 'blur', []); }, }, });