Skip to content
Open
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 @@ -11,14 +11,16 @@ class EnrichedTextInputViewLayoutManager(
val text = view.text
val paint = view.paint

val needUpdate = MeasurementStore.store(view.id, text, paint)
if (!needUpdate) return
MeasurementStore.store(view.id, text, paint) {
val stateWrapper = view.stateWrapper ?: return@store false

val counter = forceHeightRecalculationCounter
forceHeightRecalculationCounter++
val state = Arguments.createMap()
state.putInt("forceHeightRecalculationCounter", counter)
view.stateWrapper?.updateState(state)
forceHeightRecalculationCounter++
val state = Arguments.createMap()
state.putInt("forceHeightRecalculationCounter", forceHeightRecalculationCounter)
stateWrapper.updateState(state)

true
}
}

fun releaseMeasurementStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ object MeasurementStore {
id: Int,
spannable: Spannable?,
paint: TextPaint,
): Boolean {
invalidateShadowNode: () -> Boolean,
) {
val cachedWidth = data[id]?.cachedWidth ?: 0f
val cachedSize = data[id]?.cachedSize ?: 0L
val initialized = data[id]?.initialized ?: true

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

data[id] = MeasurementParams(initialized, cachedWidth, size, spannable, paintParams)
return cachedSize != size
// stateWrapper might be null during the first measures,
// we want to cache the size only when it was actually
// handled in the shadow node. The cached size and the actual
// rendered one should be in sync.
val invalidated = cachedSize != size && invalidateShadowNode()
val storedSize = if (invalidated) size else cachedSize

data[id] = MeasurementParams(initialized, cachedWidth, storedSize, spannable, paintParams)
}

fun release(id: Int) {
Expand Down Expand Up @@ -130,7 +137,7 @@ object MeasurementStore {
props: ReadableMap?,
): Float {
val propsFontSize = props?.getDouble("fontSize")?.toFloat()
if (propsFontSize == null) return defaultView.textSize
if (propsFontSize == null || propsFontSize <= 0) return defaultView.textSize

return ceil(pixelFromSpOrDp(propsFontSize, allowFontScalingFromProps(props)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EnrichedTextInputShadowNode final
const LayoutConstraints &layoutConstraints) const override;

private:
int forceHeightRecalculationCounter_;
int forceHeightRecalculationCounter_{0};
std::shared_ptr<EnrichedTextInputMeasurementManager> measurementsManager_;
};
} // namespace facebook::react
Loading