@craft-native/android 0.0.141 → 0.0.143
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 +2 -0
- package/package.json +1 -1
- package/templates/MainActivityNative.kt.template +59 -16
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 ->
|
|
@@ -1896,6 +1928,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
1896
1928
|
if (!screen.controls.containsKey("id:$target")) return false
|
|
1897
1929
|
makeView(screen, document, target, screen.controls)
|
|
1898
1930
|
val updated = screen.controls["id:$target"] ?: return false
|
|
1931
|
+
screen.lastLayoutBounds.remove(updated)
|
|
1899
1932
|
if (!updateParentLayoutStyle(updated, document.optJSONObject("style") ?: JSONObject())) return false
|
|
1900
1933
|
}
|
|
1901
1934
|
if (applied.isNotEmpty()) {
|
|
@@ -1908,14 +1941,16 @@ class MainActivity : AppCompatActivity() {
|
|
|
1908
1941
|
if (!screen.active) return
|
|
1909
1942
|
val observer = screen.view.viewTreeObserver
|
|
1910
1943
|
if (observer.isAlive) {
|
|
1911
|
-
val listener = object : ViewTreeObserver.
|
|
1912
|
-
override fun
|
|
1913
|
-
if (observer.isAlive) observer.
|
|
1944
|
+
val listener = object : ViewTreeObserver.OnPreDrawListener {
|
|
1945
|
+
override fun onPreDraw(): Boolean {
|
|
1946
|
+
if (observer.isAlive) observer.removeOnPreDrawListener(this)
|
|
1914
1947
|
if (screen.active) emitLayoutEvents(screen)
|
|
1948
|
+
return true
|
|
1915
1949
|
}
|
|
1916
1950
|
}
|
|
1917
|
-
observer.
|
|
1951
|
+
observer.addOnPreDrawListener(listener)
|
|
1918
1952
|
}
|
|
1953
|
+
screen.view.forceLayout()
|
|
1919
1954
|
screen.view.requestLayout()
|
|
1920
1955
|
// A tree that is already settled may not produce a global-layout
|
|
1921
1956
|
// callback; keep the event path live for that case as well.
|
|
@@ -1929,15 +1964,23 @@ class MainActivity : AppCompatActivity() {
|
|
|
1929
1964
|
*/
|
|
1930
1965
|
private fun updateParentLayoutStyle(view: View, style: JSONObject): Boolean {
|
|
1931
1966
|
var parent = view.parent
|
|
1967
|
+
var found = false
|
|
1932
1968
|
while (parent != null) {
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1969
|
+
when (parent) {
|
|
1970
|
+
is CraftNativeFlexLayout -> {
|
|
1971
|
+
if (!found) parent.setChildStyle(view, style, resources.displayMetrics.density)
|
|
1972
|
+
parent.forceLayout()
|
|
1973
|
+
parent.requestLayout()
|
|
1974
|
+
found = true
|
|
1975
|
+
}
|
|
1976
|
+
is CraftNativeScrollView -> {
|
|
1977
|
+
parent.forceLayout()
|
|
1978
|
+
parent.requestLayout()
|
|
1979
|
+
}
|
|
1937
1980
|
}
|
|
1938
1981
|
parent = parent.parent
|
|
1939
1982
|
}
|
|
1940
|
-
return
|
|
1983
|
+
return found
|
|
1941
1984
|
}
|
|
1942
1985
|
|
|
1943
1986
|
private fun renderCommitted(screen: Screen, document: JSONObject) {
|