@@ -1229,9 +1229,21 @@ void WindowsTextInputComponentView::updateLayoutMetrics(
1229
1229
m_imgHeight = newHeight;
1230
1230
}
1231
1231
1232
-
1233
1232
// When we are notified by RichEdit that the text changed, we need to notify JS
1234
1233
void WindowsTextInputComponentView::OnTextUpdated () noexcept {
1234
+ // Check if RichEdit says the control was modified BEFORE calling updateState
1235
+ // to avoid issues where updateState might trigger another text change
1236
+ LRESULT modified = 0 ;
1237
+ bool shouldEmitOnChange = false ;
1238
+ if (m_eventEmitter && !m_comingFromJS) {
1239
+ m_textServices->TxSendMessage (EM_GETMODIFY, 0 , 0 , &modified);
1240
+ if (modified) {
1241
+ shouldEmitOnChange = true ;
1242
+ // Clear the modify flag immediately to prevent duplicate events
1243
+ m_textServices->TxSendMessage (EM_SETMODIFY, FALSE , 0 , nullptr );
1244
+ }
1245
+ }
1246
+
1235
1247
auto data = m_state->getData ();
1236
1248
// auto newAttributedString = getAttributedString();
1237
1249
// if (data.attributedString == newAttributedString)
@@ -1241,7 +1253,7 @@ void WindowsTextInputComponentView::OnTextUpdated() noexcept {
1241
1253
1242
1254
m_state->updateState (std::move (data));
1243
1255
1244
- if (m_eventEmitter && !m_comingFromJS && !m_comingFromState ) {
1256
+ if (shouldEmitOnChange ) {
1245
1257
// call onChange event
1246
1258
auto emitter = std::static_pointer_cast<const facebook::react::WindowsTextInputEventEmitter>(m_eventEmitter);
1247
1259
facebook::react::WindowsTextInputEventEmitter::OnChange onChangeArgs;
@@ -1250,6 +1262,17 @@ void WindowsTextInputComponentView::OnTextUpdated() noexcept {
1250
1262
emitter->onChange (onChangeArgs);
1251
1263
}
1252
1264
1265
+ if (m_eventEmitter && !m_comingFromJS) {
1266
+ if (windowsTextInputProps ().multiline ) {
1267
+ auto [contentWidth, contentHeight] = GetContentSize ();
1268
+ auto emitter = std::static_pointer_cast<const facebook::react::WindowsTextInputEventEmitter>(m_eventEmitter);
1269
+ facebook::react::WindowsTextInputEventEmitter::OnContentSizeChange onContentSizeChangeArgs;
1270
+ onContentSizeChangeArgs.contentSize .width = contentWidth;
1271
+ onContentSizeChangeArgs.contentSize .height = contentHeight;
1272
+ emitter->onContentSizeChange (onContentSizeChangeArgs);
1273
+ }
1274
+ }
1275
+
1253
1276
if (UiaClientsAreListening ()) {
1254
1277
auto text = GetTextFromRichEdit ();
1255
1278
winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty (
@@ -1322,13 +1345,6 @@ void WindowsTextInputComponentView::onMounted() noexcept {
1322
1345
m_propBits |= TXTBIT_CHARFORMATCHANGE;
1323
1346
}
1324
1347
InternalFinalize ();
1325
-
1326
- // Handle autoFocus property - focus the component when mounted if autoFocus is true
1327
- if (windowsTextInputProps ().autoFocus ) {
1328
- if (auto root = rootComponentView ()) {
1329
- root->TrySetFocusedComponent (*get_strong (), winrt::Microsoft::ReactNative::FocusNavigationDirection::None);
1330
- }
1331
- }
1332
1348
}
1333
1349
1334
1350
std::optional<std::string> WindowsTextInputComponentView::getAccessiblityValue () noexcept {
0 commit comments