From 6bb16bbd8ffb00b335e47a4c472211553d3f4581 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:08:39 -0800 Subject: [PATCH 1/4] [Win32] view.focus sometimes skips setting focus --- .../TextInput/TextInputState.win32.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js b/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js index 73e68522f2d..cea7d635ef2 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js @@ -21,8 +21,7 @@ import type { import {Commands as AndroidTextInputCommands} from '../../Components/TextInput/AndroidTextInputNativeComponent'; import {Commands as iOSTextInputCommands} from '../../Components/TextInput/RCTSingelineTextInputNativeComponent'; - -import {UIManager} from 'react-native'; +import {Commands as Win32TextInputCommands} from '../../Components/TextInput/Win32TextInputNativeComponent'; const {findNodeHandle} = require('../../ReactNative/RendererProxy'); const Platform = require('../../Utilities/Platform'); @@ -106,7 +105,16 @@ function focusTextInput(textField: ?ComponentRef) { return; } - if (textField != null) { + // [Win32 + if (Platform.OS === 'win32' && textField != null) { + // On Windows, we cannot test if the currentlyFocusedInputRef equals the + // target ref because the call to focus on the target ref may occur before + // an onBlur event for the target ref has been dispatched to JS but after + // the target ref has lost native focus. + focusInput(textField); + Win32TextInputCommands.focus(textField); + // Win32] + } else if (textField != null) { const fieldCanBeFocused = currentlyFocusedInputRef !== textField && // $FlowFixMe - `currentProps` is missing in `NativeMethods` @@ -126,11 +134,6 @@ function focusTextInput(textField: ?ComponentRef) { } else if (Platform.OS === 'android') { AndroidTextInputCommands.focus(textField); } - // [Win32 - else if (Platform.OS === 'win32') { - UIManager.focus(findNodeHandle(textField)); - } - // Win32] } } @@ -164,7 +167,7 @@ function blurTextInput(textField: ?ComponentRef) { } // [Win32 else if (Platform.OS === 'win32') { - UIManager.blur(findNodeHandle(textField)); + Win32TextInputCommands.blur(textField); } // Win32] } @@ -250,4 +253,4 @@ module.exports = { registerInput, unregisterInput, isTextInput, -}; +}; \ No newline at end of file From ca533b6b03c3a2a2eda25188351df3438b58128d Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:08:46 -0800 Subject: [PATCH 2/4] Change files --- ...-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json diff --git a/change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json b/change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json new file mode 100644 index 00000000000..be71cff759a --- /dev/null +++ b/change/@office-iss-react-native-win32-25963317-e0eb-4d0b-8253-3e2490f2a1ab.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "[Win32] view.focus sometimes skips setting focus", + "packageName": "@office-iss/react-native-win32", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} From 74d562ae424d6ccbe81900728c79ab137690e826 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 8 Feb 2024 08:38:25 -0800 Subject: [PATCH 3/4] format --- .../src/Libraries/Components/TextInput/TextInputState.win32.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js b/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js index cea7d635ef2..79373c4b650 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Components/TextInput/TextInputState.win32.js @@ -253,4 +253,4 @@ module.exports = { registerInput, unregisterInput, isTextInput, -}; \ No newline at end of file +}; From 44238c29f28ebbd6589cfd3fb0910542e360aad2 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:44:00 -0800 Subject: [PATCH 4/4] unblock ci --- .unbroken_exclusions | 1 + 1 file changed, 1 insertion(+) diff --git a/.unbroken_exclusions b/.unbroken_exclusions index c45218154c0..fc3b366a363 100644 --- a/.unbroken_exclusions +++ b/.unbroken_exclusions @@ -21,3 +21,4 @@ URL not found https://docs.github.com/get-started/quickstart while parsing CONTR !packages/@rnw-scripts/format-files/node_modules !packages/@rnw-scripts/promote-release/node_modules !.github/ISSUE_TEMPLATE +!.github/security.md \ No newline at end of file