From 106fdc78b65e50ac710d790bd572afdc08f0b655 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Mon, 26 Apr 2021 14:00:44 -0700 Subject: [PATCH 1/3] If initial value is set, updated TextInput.value changes will not be reflected --- .../Views/TextInputViewManager.cpp | 19 +++++++++++++++---- .../Components/TextInput/TextInput.windows.js | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp index 84016df127f..3356974c5ab 100644 --- a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp +++ b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp @@ -133,6 +133,7 @@ class TextInputShadowNode : public ShadowNodeBase { void SetSelection(int64_t start, int64_t end); winrt::Shape FindCaret(xaml::DependencyObject element); + bool m_initialUpdateComplete = false; bool m_shouldClearTextOnFocus = false; bool m_shouldSelectTextOnFocus = false; bool m_contextMenuHidden = false; @@ -174,6 +175,9 @@ void TextInputShadowNode::createView(const winrt::Microsoft::ReactNative::JSValu } void TextInputShadowNode::dispatchTextInputChangeEvent(winrt::hstring newText) { + if (!m_initialUpdateComplete) { + return; + } m_nativeEventCount++; folly::dynamic eventData = folly::dynamic::object("target", m_tag)("text", react::uwp::HstringToDynamic(newText))( "eventCount", m_nativeEventCount); @@ -198,14 +202,20 @@ void TextInputShadowNode::registerEvents() { // another TextChanged event with correct event count. if (m_isTextBox) { m_passwordBoxPasswordChangingRevoker = {}; - m_textBoxTextChangingRevoker = control.as().TextChanging( - winrt::auto_revoke, [=](auto &&, auto &&) { m_nativeEventCount++; }); + m_textBoxTextChangingRevoker = + control.as().TextChanging(winrt::auto_revoke, [=](auto &&, auto &&) { + if (m_initialUpdateComplete) + m_nativeEventCount++; + }); } else { m_textBoxTextChangingRevoker = {}; if (control.try_as()) { - m_passwordBoxPasswordChangingRevoker = control.as().PasswordChanging( - winrt::auto_revoke, [=](auto &&, auto &&) { m_nativeEventCount++; }); + m_passwordBoxPasswordChangingRevoker = + control.as().PasswordChanging(winrt::auto_revoke, [=](auto &&, auto &&) { + if (m_initialUpdateComplete) + m_nativeEventCount++; + }); } } @@ -665,6 +675,7 @@ void TextInputShadowNode::updateProperties(winrt::Microsoft::ReactNative::JSValu } m_updating = false; + m_initialUpdateComplete = true; } void TextInputShadowNode::SetText(const winrt::Microsoft::ReactNative::JSValue &text) { diff --git a/vnext/src/Libraries/Components/TextInput/TextInput.windows.js b/vnext/src/Libraries/Components/TextInput/TextInput.windows.js index 08773db5819..e38fd03bcf2 100644 --- a/vnext/src/Libraries/Components/TextInput/TextInput.windows.js +++ b/vnext/src/Libraries/Components/TextInput/TextInput.windows.js @@ -1229,6 +1229,7 @@ function InternalTextInput(props: Props): React.Node { ref={_setNativeRef} {...props} dataDetectorTypes={props.dataDetectorTypes} + mostRecentEventCount={mostRecentEventCount} onBlur={_onBlur} onChange={_onChange} onContentSizeChange={props.onContentSizeChange} From 082f854919933fe09090f977438cb07f7dab8bdb Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Mon, 26 Apr 2021 14:01:07 -0700 Subject: [PATCH 2/3] Change files --- ...ative-windows-9aaace3c-20a8-4c24-90b2-d777742f65ba.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-9aaace3c-20a8-4c24-90b2-d777742f65ba.json diff --git a/change/react-native-windows-9aaace3c-20a8-4c24-90b2-d777742f65ba.json b/change/react-native-windows-9aaace3c-20a8-4c24-90b2-d777742f65ba.json new file mode 100644 index 00000000000..74c8fd17793 --- /dev/null +++ b/change/react-native-windows-9aaace3c-20a8-4c24-90b2-d777742f65ba.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "If initial value is set, updated TextInput.value changes will not be reflected", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} From 3c33a72a37abb75a111f1b6b5d8b81ff515fa29b Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Thu, 29 Apr 2021 16:27:42 -0700 Subject: [PATCH 3/3] default member initializers for bit-fields requires at least '/std:c++latest' --- .../Views/TextInputViewManager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp index 97c41a78bd1..59eb2f7cc56 100644 --- a/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp +++ b/vnext/Microsoft.ReactNative/Views/TextInputViewManager.cpp @@ -133,14 +133,14 @@ class TextInputShadowNode : public ShadowNodeBase { void SetSelection(int64_t start, int64_t end); winrt::Shape FindCaret(xaml::DependencyObject element); - bool m_initialUpdateComplete : 1 = false; - bool m_autoFocus : 1 = false; - bool m_shouldClearTextOnFocus : 1 = false; - bool m_shouldSelectTextOnFocus : 1 = false; - bool m_contextMenuHidden : 1 = false; - bool m_hideCaret : 1 = false; - bool m_isTextBox : 1 = true; - bool m_shouldClearTextOnSubmit : 1 = false; + bool m_initialUpdateComplete = false; + bool m_autoFocus = false; + bool m_shouldClearTextOnFocus = false; + bool m_shouldSelectTextOnFocus = false; + bool m_contextMenuHidden = false; + bool m_hideCaret = false; + bool m_isTextBox = true; + bool m_shouldClearTextOnSubmit = false; winrt::Microsoft::ReactNative::JSValue m_placeholderTextColor; std::vector m_submitKeyEvents{};