From 501edbf94ae162006281554d039b5904bcb7f29f Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Fri, 6 Jun 2025 17:39:12 +0530 Subject: [PATCH 1/3] Added support for selectionColor for textInput --- .../WindowsTextInputComponentView.cpp | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp index 506c2eb88fd..6e7c9643e28 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp @@ -319,21 +319,30 @@ struct CompTextHost : public winrt::implements { if (m_outer->windowsTextInputProps().textAttributes.foregroundColor) return (*m_outer->windowsTextInputProps().textAttributes.foregroundColor).AsColorRefNoAlpha(); // cr = 0x000000FF; - break; - - case COLOR_WINDOW: + break; case COLOR_WINDOW: if (m_outer->viewProps()->backgroundColor) return (*m_outer->viewProps()->backgroundColor).AsColorRefNoAlpha(); break; - // case COLOR_HIGHLIGHT: - // cr = RGB(0, 0, 255); - // cr = 0x0000ffFF; - // break; - // case COLOR_HIGHLIGHTTEXT: - // cr = RGB(255, 0, 0); - // cr = 0xFFFFFFFF; - // break; + case COLOR_HIGHLIGHT: + if (m_outer->windowsTextInputProps().selectionColor) + return (*m_outer->windowsTextInputProps().selectionColor).AsColorRefNoAlpha(); + break; + + case COLOR_HIGHLIGHTTEXT: + // For selected text color, we use the same color as the selection background + // or the text color if selection color is not specified + if (m_outer->windowsTextInputProps().selectionColor) { + // Calculate appropriate text color based on selection background + auto selectionColor = (*m_outer->windowsTextInputProps().selectionColor).AsColorRefNoAlpha(); + // Use white text for dark selection, black text for light selection + int r = GetRValue(selectionColor); + int g = GetGValue(selectionColor); + int b = GetBValue(selectionColor); + int brightness = (r * 299 + g * 587 + b * 114) / 1000; + return brightness > 125 ? RGB(0, 0, 0) : RGB(255, 255, 255); + } + break; // case COLOR_GRAYTEXT: // cr = RGB(128, 128, 128); @@ -1126,11 +1135,14 @@ void WindowsTextInputComponentView::updateProps( bool effectiveSpellCheck = newTextInputProps.spellCheck || newTextInputProps.autoCorrect; updateSpellCheck(effectiveSpellCheck); } - if (!oldProps || oldTextInputProps.autoCorrect != newTextInputProps.autoCorrect) { updateAutoCorrect(newTextInputProps.autoCorrect); } + if (oldTextInputProps.selectionColor != newTextInputProps.selectionColor) { + m_needsRedraw = true; + } + UpdatePropertyBits(); } From 2b641ec67529267b46aef4de7f8bd06c78e5d074 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Fri, 6 Jun 2025 17:43:36 +0530 Subject: [PATCH 2/3] yarn fix and format --- .../Composition/TextInput/WindowsTextInputComponentView.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp index 6e7c9643e28..a65db9c7d2b 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp @@ -319,7 +319,8 @@ struct CompTextHost : public winrt::implements { if (m_outer->windowsTextInputProps().textAttributes.foregroundColor) return (*m_outer->windowsTextInputProps().textAttributes.foregroundColor).AsColorRefNoAlpha(); // cr = 0x000000FF; - break; case COLOR_WINDOW: + break; + case COLOR_WINDOW: if (m_outer->viewProps()->backgroundColor) return (*m_outer->viewProps()->backgroundColor).AsColorRefNoAlpha(); break; From 36dc841389d1da8a7b0c172c58e8a17916a6b326 Mon Sep 17 00:00:00 2001 From: Abhijeet Jha <74712637+iamAbhi-916@users.noreply.github.com> Date: Fri, 6 Jun 2025 17:47:15 +0530 Subject: [PATCH 3/3] Change files --- ...ative-windows-b47cf142-681b-41f5-8ac6-d07b04f55165.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-b47cf142-681b-41f5-8ac6-d07b04f55165.json diff --git a/change/react-native-windows-b47cf142-681b-41f5-8ac6-d07b04f55165.json b/change/react-native-windows-b47cf142-681b-41f5-8ac6-d07b04f55165.json new file mode 100644 index 00000000000..8bf6a73898e --- /dev/null +++ b/change/react-native-windows-b47cf142-681b-41f5-8ac6-d07b04f55165.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "Added support for selectionColor for textInput", + "packageName": "react-native-windows", + "email": "74712637+iamAbhi-916@users.noreply.github.com", + "dependentChangeType": "none" +}