Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1350,12 +1350,14 @@ public open class ReactEditText public constructor(context: Context) : AppCompat
FLog.e(TAG, "onTextChanged[$id]: $s $start $before $count")
}

// The cached spannable must be up to date before the listeners run: a listener may commit a
// state update synchronously, which measures this view through the cached spannable.
updateCachedSpannable()

if (!isSettingTextFromJS) {
listeners?.forEach { listener -> listener.onTextChanged(s, start, before, count) }
}

updateCachedSpannable()

onContentSizeChange()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import android.text.TextWatcher
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.events.EventDispatcher

@OptIn(UnstableReactNativeAPI::class)
internal class ReactTextInputTextWatcher(
reactContext: ReactContext,
private val editText: ReactEditText,
Expand Down Expand Up @@ -52,7 +55,10 @@ internal class ReactTextInputTextWatcher(
val newStateData: WritableMap = WritableNativeMap()
newStateData.putInt("mostRecentEventCount", editText.incrementAndGetEventCounter())
newStateData.putInt("opaqueCacheId", editText.id)
stateWrapper.updateState(newStateData)
// Committing the state synchronously re-measures and re-lays out the input (and anything
// depending on its size) before the current frame is drawn, so the view's size and its
// text never disagree for a frame (e.g. when a multiline input gains or loses a line).
stateWrapper.updateState(newStateData, StateWrapper.UpdateMode.unstable_Immediate)
}

// The event that contains the event counter and updates it must be sent first.
Expand Down
Loading