also looking at this
fix(mobile): preserve native editing, navigation, and durable media requests
#369
36 files
+864
-185
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -2,6 +2,34 @@ | ||
| 2 | 2 | import { test } from 'bun:test' |
| 3 | 3 | import { runKotlinFixture } from './testing' |
| 4 | 4 | |
| 5 | test('snaps authored padding to the nearest physical pixel at fractional density', async () => { | |
| 6 | const template = await Bun.file(new URL('../templates/MainActivityNative.kt.template', import.meta.url)).text() | |
| 7 | const padding = template.match(/internal fun craftNativePadding\([^]*?\n\}/)?.[0] | |
| 8 | const number = template.match(/private fun craftNativeNumber\([^]*?\n \?\.takeIf \{ it\.isFinite\(\) \}/)?.[0] | |
| 9 | if (!padding || !number) throw new Error('Native padding normalization is missing') | |
| 10 | await runKotlinFixture(` | |
| 11 | import kotlin.math.roundToInt | |
| 12 | ||
| 13 | class JSONObject(private val values: Map<String, Any?>) { | |
| 14 | fun opt(name: String): Any? = values[name] | |
| 15 | } | |
| 16 | ${number} | |
| 17 | ${padding} | |
| 18 | ||
| 19 | fun main() { | |
| 20 | val density = 2.625f | |
| 21 | check(craftNativePadding(JSONObject(mapOf("padding" to 4)), "padding", 0, density) == 11) | |
| 22 | check(craftNativePadding(JSONObject(mapOf("padding" to 8)), "padding", 0, density) == 21) | |
| 23 | check(craftNativePadding(JSONObject(mapOf("padding" to 4)), "padding", 0, 1f) == 4) | |
| 24 | for (invalid in listOf(null, -1, Double.NaN, Double.POSITIVE_INFINITY, true, "4")) { | |
| 25 | check(craftNativePadding(JSONObject(mapOf("padding" to invalid)), "padding", 7, density) == 7) | |
| 26 | } | |
| 27 | check(craftNativePadding(null, "padding", 7, density) == 7) | |
| 28 | println("PASS native padding rounds once to the nearest physical pixel and retains invalid-value defaults") | |
| 29 | } | |
| 30 | `) | |
| 31 | }, 180_000) | |
| 32 | ||
| 5 | 33 | test('sizes occupied and empty explicit grid rows after padding and fractional gaps', async () => { |
| 6 | 34 | const template = await Bun.file(new URL('../templates/MainActivityNative.kt.template', import.meta.url)).text() |
| 7 | 35 | const allocation = template.match(/ val rowHeights = if \(gridRows != null\) \{[\s\S]*?\n \} else naturalRowHeights/)?.[0] |
| @@ -167,7 +167,7 @@ private fun craftNativeFontWeight(value: Any?): String? = when (value) { | ||
| 167 | 167 | internal fun craftNativePadding(style: JSONObject?, name: String, fallback: Int, density: Float): Int { |
| 168 | 168 | val value = craftNativeNumber(style?.opt(name)) ?: Double.NaN |
| 169 | 169 | val pixels = value * density |
| 170 | return if (value.isFinite() && value >= 0 && pixels.isFinite()) pixels.toInt() else fallback | |
| 170 | return if (value.isFinite() && value >= 0 && pixels.isFinite()) pixels.roundToInt() else fallback | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | internal fun craftNativeFiniteFloat(style: JSONObject?, name: String, fallback: Float): Float { |