@craft-native/android 0.0.141 → 0.0.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -120,6 +120,8 @@ same shrink defaults as the iOS renderer; buttons and editable fields retain
|
|
|
120
120
|
their intrinsic width unless explicitly configured.
|
|
121
121
|
Wrapped containers also honor `alignContent` (`center`, `flex-end`,
|
|
122
122
|
`space-between`, `space-around`, and `stretch`) consistently across hosts.
|
|
123
|
+
Shared wrapped-line IDs are accepted only when they are complete and monotonic;
|
|
124
|
+
invalid bridge data falls back to the host layout implementation.
|
|
123
125
|
Push, replace, and back preserve the
|
|
124
126
|
previous screen's views and JavaScript state; Android's system back button pops
|
|
125
127
|
the route. Native mode accepts neither `--html-path` nor `--dev-server`. Its
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import android.graphics.BitmapFactory
|
|
|
13
13
|
import android.graphics.Canvas
|
|
14
14
|
import android.graphics.Color
|
|
15
15
|
import android.graphics.DashPathEffect
|
|
16
|
+
import android.graphics.Matrix
|
|
16
17
|
import android.graphics.Paint
|
|
17
18
|
import android.graphics.Path
|
|
18
19
|
import android.graphics.Typeface
|
|
@@ -217,16 +218,36 @@ private class CraftNativeSvgView(context: Context) : View(context) {
|
|
|
217
218
|
setMeasuredDimension(resolveSize(width, widthMeasureSpec), resolveSize(height, heightMeasureSpec))
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
/** viewBox units to the view's pixels, set by each draw. */
|
|
222
|
+
private val viewTransform = Matrix()
|
|
223
|
+
private val inverseTransform = Matrix()
|
|
224
|
+
|
|
220
225
|
override fun onDraw(canvas: Canvas) {
|
|
221
226
|
super.onDraw(canvas)
|
|
222
227
|
val box = viewBox() ?: return
|
|
223
228
|
if (box.first <= 0 || box.second <= 0) return
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
// Centred at one scale (SVG's default, `xMidYMid meet`), or each axis
|
|
230
|
+
// stretched to fill (`preserveAspectRatio="none"`).
|
|
231
|
+
val stretch = drawing.optJSONObject("props")?.optString("preserveAspectRatio")?.trim() == "none"
|
|
232
|
+
var sx = width.toFloat() / box.first
|
|
233
|
+
var sy = height.toFloat() / box.second
|
|
234
|
+
var dx = 0f
|
|
235
|
+
var dy = 0f
|
|
236
|
+
if (!stretch) {
|
|
237
|
+
val scale = min(sx, sy)
|
|
238
|
+
sx = scale
|
|
239
|
+
sy = scale
|
|
240
|
+
dx = (width - box.first * scale) / 2f
|
|
241
|
+
dy = (height - box.second * scale) / 2f
|
|
242
|
+
}
|
|
243
|
+
if (!sx.isFinite() || !sy.isFinite() || sx <= 0f || sy <= 0f) return
|
|
244
|
+
viewTransform.reset()
|
|
245
|
+
viewTransform.postTranslate(-box.third, -box.fourth)
|
|
246
|
+
viewTransform.postScale(sx, sy)
|
|
247
|
+
viewTransform.postTranslate(dx, dy)
|
|
248
|
+
viewTransform.invert(inverseTransform)
|
|
226
249
|
canvas.save()
|
|
227
|
-
canvas.
|
|
228
|
-
canvas.scale(scale, scale)
|
|
229
|
-
canvas.translate(-box.third, -box.fourth)
|
|
250
|
+
canvas.concat(viewTransform)
|
|
230
251
|
drawNodes(canvas, drawing.optJSONArray("children") ?: JSONArray(), SvgPaint().merge(drawing))
|
|
231
252
|
canvas.restore()
|
|
232
253
|
}
|
|
@@ -310,7 +331,17 @@ private class CraftNativeSvgView(context: Context) : View(context) {
|
|
|
310
331
|
}
|
|
311
332
|
}
|
|
312
333
|
}
|
|
313
|
-
|
|
334
|
+
// `vector-effect="non-scaling-stroke"`: the stroke is in the view's
|
|
335
|
+
// pixels, so a stretched chart's line keeps its width.
|
|
336
|
+
if (props.optString("vectorEffect") == "non-scaling-stroke") {
|
|
337
|
+
val line = Path(path).apply { transform(viewTransform) }
|
|
338
|
+
canvas.save()
|
|
339
|
+
canvas.concat(inverseTransform)
|
|
340
|
+
canvas.drawPath(line, stroke)
|
|
341
|
+
canvas.restore()
|
|
342
|
+
} else {
|
|
343
|
+
canvas.drawPath(path, stroke)
|
|
344
|
+
}
|
|
314
345
|
}
|
|
315
346
|
}
|
|
316
347
|
|
|
@@ -443,7 +474,8 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
443
474
|
}.toFloatArray()
|
|
444
475
|
val sharedLineIds = CraftNative.flexLines(availableMain.toFloat(), gap.toFloat(), wrap, basis, margins)
|
|
445
476
|
val lineIds = sharedLineIds?.takeIf { ids ->
|
|
446
|
-
ids.size >= pending.size && ids.firstOrNull() == 0 &&
|
|
477
|
+
ids.size >= pending.size && ids.firstOrNull() == 0 &&
|
|
478
|
+
ids.indices.drop(1).all { index -> ids[index] >= ids[index - 1] }
|
|
447
479
|
}
|
|
448
480
|
var line = Line()
|
|
449
481
|
pending.forEachIndexed { index, entry ->
|