Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
34b2290
feat: add onScroll event to web
Oct 26, 2026
beb0696
feat: add scroll event throtling on web
Oct 26, 2026
da69d5f
refactor: changed the throttle ref to a number not an object
Oct 26, 2026
cff0e77
Merge branch 'main' of https://github.com/software-mansion/react-nati…
Oct 26, 2026
a29b77f
feat: add onScroll on ios
Oct 27, 2026
4aa81bf
fix: fix the layout scroll loop
Oct 27, 2026
746be5b
refactor: add handler for debuging scrollEvent in example app
Oct 27, 2026
8c54bbc
refactor: change the import path for onScrollEvent
Oct 27, 2026
fe40d4c
feat: added onScroll on android
Oct 28, 2026
b953d35
feat(web): add e2e tests
Oct 28, 2026
73ce67a
feat: more towards e2e test
Oct 28, 2026
ad95c50
feat(mobile): add more cases to tests
Oct 28, 2026
0a2ba65
fix(android): set input min height to avoid an unwanted scroll
Oct 29, 2026
0f1bcd0
fix: fix the tests on android
Oct 29, 2026
31b11c5
merge main
Oct 29, 2026
cbb9979
refactor: restore podfile.lock
Oct 29, 2026
5af689d
fix: restore podfile.lock again
Oct 29, 2026
e1d8f23
fix: fix the lint issues
Oct 29, 2026
2e5d181
refactor: remove throtling to behave more like react native
Oct 30, 2026
b494dcd
refactor: removed the helper on android to match the code on other pl…
Oct 30, 2026
137db01
Merge branch 'main' of https://github.com/software-mansion/react-nati…
Nov 3, 2026
bdd7812
feat: change mobile scroll tests
relextm19 Nov 4, 2026
4007cb3
fix(android): fix bug in android scroll event emission
relextm19 Nov 4, 2026
a9ef2bc
refactor: more suiting comment
relextm19 Nov 4, 2026
ce0bc6f
fix(web): stop react from useless rerendering
relextm19 Nov 4, 2026
367e352
feat: add docs for onScroll
relextm19 Nov 4, 2026
60c7091
feat(ios): only emmit scrollEvent when contentOffset changes
relextm19 Nov 4, 2026
8561157
Merge branch 'main' of https://github.com/software-mansion/react-nati…
relextm19 Nov 4, 2026
91cca3a
fix(ios): lint fix
relextm19 Nov 4, 2026
4a30f60
feat: only calculate scroll offset if we have a handler
relextm19 Nov 11, 2026
17fe873
fix: fix lint warning
relextm19 Nov 11, 2026
2cdeddd
feat: add update delay in scroll tests
relextm19 Nov 11, 2026
3d0ce66
Merge branch 'main' into @relextm19/scroll-position
szydlovsky Nov 12, 2026
2ff17fd
Merge branch 'main' into @relextm19/scroll-position
szydlovsky Nov 12, 2026
8150534
fix: weird locale-related measurements
szydlovsky Nov 13, 2026
e1edaeb
chore: update affected test screenshots
szydlovsky Nov 13, 2026
78636c0
chore: fix broken image test
szydlovsky Nov 13, 2026
06d8dd9
fix: copilot suggested improvements
szydlovsky Nov 13, 2026
8e79380
fix: test assets are available again
szydlovsky Nov 24, 2026
2f1e1c2
fix: move maxTextHeight to MeasurementParams
szydlovsky Nov 25, 2026
51841f9
Merge branch 'main' into @szydlovsky/fix-android-measurement-jumps
szydlovsky Nov 25, 2026
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
Binary file modified .maestro/enrichedInput/screenshots/android/checkbox_toggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .maestro/enrichedInput/screenshots/android/font_scaling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .maestro/enrichedInput/screenshots/android/initial_placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class EnrichedTextInputView :
val customStyles: CustomStyles? = CustomStyles(this)
var isDuringTransaction: Boolean = false
var isRemovingMany: Boolean = false

var isWaitingForHeightUpdate: Boolean = false
private var didCapScrollWhileWaiting = false
var scrollEnabled: Boolean = true
var allowFontScaling: Boolean = EnrichedConstants.ALLOW_FONT_SCALING_DEFAULT
set(value) {
Expand Down Expand Up @@ -187,7 +190,25 @@ class EnrichedTextInputView :
// Android's internal cursor tracker gets confused by ALIGN_CENTER + LeadingMarginSpan
// and attempts to scroll the text horizontally.
// We lock the horizontal scroll to 0 to prevent the view from shifting.
super.scrollTo(0, y)
// Height updates are async, so new text is laid out before the view grows. Cap the scroll at its
// post-resize value, otherwise EditText jumps to the new line and back.
val targetY = if (isWaitingForHeightUpdate) y.coerceAtMost(getMaxScrollAfterHeightUpdate()) else y
if (targetY < y) didCapScrollWhileWaiting = true
super.scrollTo(0, targetY)
}

fun onHeightUpdateMounted() {
isWaitingForHeightUpdate = false
if (!didCapScrollWhileWaiting) return
didCapScrollWhileWaiting = false
// The predicted height can be wrong (e.g. when it comes from flex)
post { forceScrollToSelection() }
}

private fun getMaxScrollAfterHeightUpdate(): Int {
val maxTextHeight = MeasurementStore.getMaxTextHeight(id) ?: return Int.MAX_VALUE
val textHeight = layout?.height ?: return Int.MAX_VALUE
return (textHeight - maxTextHeight).toInt().coerceAtLeast(0)
}

override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
Expand Down Expand Up @@ -1127,6 +1148,9 @@ class EnrichedTextInputView :
}
}

fun usesLocalePreferredLineHeight(): Boolean =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && isLocalePreferredLineHeightForMinimumUsed

private fun forceScrollToSelection() {
val textLayout = layout ?: return
val cursorOffset = selectionStart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class EnrichedTextInputViewLayoutManager(
val text = view.text
val paint = view.paint

val needUpdate = MeasurementStore.store(view.id, text, paint)
val needUpdate = MeasurementStore.store(view.id, text, paint, view.usesLocalePreferredLineHeight())
if (!needUpdate) return

forceHeightRecalculationCounter++
val state = Arguments.createMap()
state.putInt("forceHeightRecalculationCounter", forceHeightRecalculationCounter)
view.isWaitingForHeightUpdate = true
stateWrapper.updateState(state)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class EnrichedTextInputViewManager :
stateWrapper: StateWrapper?,
): Any? {
view.stateWrapper = stateWrapper
view.onHeightUpdateMounted()
return super.updateState(view, props, stateWrapper)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.swmansion.enriched.textinput

import android.content.Context
import android.graphics.Paint
import android.graphics.Typeface
import android.graphics.text.LineBreaker
import android.os.Build
Expand Down Expand Up @@ -28,6 +29,7 @@ object MeasurementStore {
data class PaintParams(
val typeface: Typeface,
val fontSize: Float,
val useLocalePreferredLineHeight: Boolean,
)

data class MeasurementParams(
Expand All @@ -36,6 +38,8 @@ object MeasurementStore {
val cachedSize: Long,
val spannable: CharSequence?,
val paintParams: PaintParams,
// In px, as given by Yoga's measure
val maxTextHeight: Float? = null,
)

private val data = ConcurrentHashMap<Int, MeasurementParams>()
Expand All @@ -44,22 +48,26 @@ object MeasurementStore {
id: Int,
spannable: Spannable?,
paint: TextPaint,
useLocalePreferredLineHeight: Boolean,
): Boolean {
val cachedWidth = data[id]?.cachedWidth ?: 0f
val cachedSize = data[id]?.cachedSize ?: 0L
val initialized = data[id]?.initialized ?: true
val maxTextHeight = data[id]?.maxTextHeight

val size = measure(cachedWidth, spannable, paint)
val paintParams = PaintParams(paint.typeface, paint.textSize)
val size = measure(cachedWidth, spannable, paint, useLocalePreferredLineHeight)
val paintParams = PaintParams(paint.typeface, paint.textSize, useLocalePreferredLineHeight)

data[id] = MeasurementParams(initialized, cachedWidth, size, spannable, paintParams)
data[id] = MeasurementParams(initialized, cachedWidth, size, spannable, paintParams, maxTextHeight)
return cachedSize != size
}

fun release(id: Int) {
data.remove(id)
}

fun getMaxTextHeight(id: Int): Float? = data[id]?.maxTextHeight

private fun measure(
maxWidth: Float,
spannable: CharSequence?,
Expand All @@ -71,13 +79,14 @@ object MeasurementStore {
textSize = paintParams.fontSize
}

return measure(maxWidth, spannable, paint)
return measure(maxWidth, spannable, paint, paintParams.useLocalePreferredLineHeight)
}

private fun measure(
maxWidth: Float,
spannable: CharSequence?,
paint: TextPaint,
useLocalePreferredLineHeight: Boolean,
): Long {
val text = spannable ?: ""
val textLength = text.length
Expand All @@ -95,6 +104,13 @@ object MeasurementStore {
builder.setUseLineSpacingFromFallbacks(true)
}

// EditText (targetSdk 35+) keeps empty lines as tall as lines with text, otherwise they're measured shorter than drawn
if (useLocalePreferredLineHeight && Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
Comment thread
szydlovsky marked this conversation as resolved.
Resolved
val minimumFontMetrics = Paint.FontMetrics()
paint.getFontMetricsForLocale(minimumFontMetrics)
builder.setMinimumFontMetrics(minimumFontMetrics)
}

val staticLayout = builder.build()
val heightInSP = PixelUtil.toDIPFromPixel(staticLayout.height.toFloat())
val widthInSP = PixelUtil.toDIPFromPixel(maxWidth)
Expand Down Expand Up @@ -175,7 +191,7 @@ object MeasurementStore {
}

val typeface = applyStyles(defaultView.typeface, fontStyle, fontWeight, fontFamily, context.assets)
val paintParams = PaintParams(typeface, fontSize)
val paintParams = PaintParams(typeface, fontSize, defaultView.usesLocalePreferredLineHeight())
val size = measure(width, text, paintParams)

if (id != null) {
Expand Down Expand Up @@ -208,7 +224,7 @@ object MeasurementStore {
textSize = value.paintParams.fontSize
}

val size = measure(width, value.spannable, paint)
val size = measure(width, value.spannable, paint, value.paintParams.useLocalePreferredLineHeight)
data[id] = MeasurementParams(true, width, size, value.spannable, value.paintParams)
return size
}
Expand All @@ -222,6 +238,18 @@ object MeasurementStore {
props: ReadableMap?,
): Long {
val size = getMeasureById(context, id, width, props)

if (id != null) {
val maxTextHeight =
when (heightMode) {
YogaMeasureMode.AT_MOST -> height
YogaMeasureMode.UNDEFINED -> Float.POSITIVE_INFINITY
else -> null
}
// Atomic, so a concurrent store() from the UI thread isn't overwritten with stale text measurements
data.computeIfPresent(id) { _, params -> params.copy(maxTextHeight = maxTextHeight) }
}

if (heightMode !== YogaMeasureMode.AT_MOST) {
return size
}
Expand Down
Loading