Skip to content

Commit 21442fd

Browse files
authored
fix: scrolling when height is not provided - android (#342)
# Summary Fixes scrolling behavior when height/maxHeight is not provided for android `EnrichedTextInput`. Before such component was not scrollable, currently it scrolls properly (when not nested inside any other scrollable component). ## Test Plan - Define `EnrichedTextInput` outside of scrollable - Specify basic styles for `EnrichedTextInput`. Ensure height and max height are not provided - Type long content, so component takes more space than screen height - Notice that `EnrichedTextInput` is scrollable ## Screenshots / Videos https://github.com/user-attachments/assets/4d0f3fe4-7e96-494d-a5c0-365bb4da425a ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ❌ | | Android | ✅ |
1 parent 728cd2f commit 21442fd

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class EnrichedTextInputViewManager :
365365
attachmentsPositions: FloatArray?,
366366
): Long {
367367
val id = localData?.getInt("viewTag")
368-
return MeasurementStore.getMeasureById(context, id, width, props)
368+
return MeasurementStore.getMeasureById(context, id, width, height, heightMode, props)
369369
}
370370

371371
companion object {

android/src/main/java/com/swmansion/enriched/MeasurementStore.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.facebook.react.uimanager.PixelUtil
1313
import com.facebook.react.views.text.ReactTypefaceUtils.applyStyles
1414
import com.facebook.react.views.text.ReactTypefaceUtils.parseFontStyle
1515
import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight
16+
import com.facebook.yoga.YogaMeasureMode
1617
import com.facebook.yoga.YogaMeasureOutput
1718
import com.swmansion.enriched.styles.HtmlStyle
1819
import com.swmansion.enriched.utils.EnrichedParser
@@ -157,7 +158,7 @@ object MeasurementStore {
157158
return size
158159
}
159160

160-
fun getMeasureById(
161+
private fun getMeasureById(
161162
context: Context,
162163
id: Int?,
163164
width: Float,
@@ -184,4 +185,23 @@ object MeasurementStore {
184185
data[id] = MeasurementParams(true, width, size, value.spannable, value.paintParams)
185186
return size
186187
}
188+
189+
fun getMeasureById(
190+
context: Context,
191+
id: Int?,
192+
width: Float,
193+
height: Float,
194+
heightMode: YogaMeasureMode?,
195+
props: ReadableMap?,
196+
): Long {
197+
val size = getMeasureById(context, id, width, props)
198+
if (heightMode !== YogaMeasureMode.AT_MOST) {
199+
return size
200+
}
201+
202+
val calculatedHeight = YogaMeasureOutput.getHeight(size)
203+
val atMostHeight = PixelUtil.toDIPFromPixel(height)
204+
val finalHeight = calculatedHeight.coerceAtMost(atMostHeight)
205+
return YogaMeasureOutput.make(YogaMeasureOutput.getWidth(size), finalHeight)
206+
}
187207
}

0 commit comments

Comments
 (0)