@craft-native/android 0.0.162 → 0.0.163
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 +5 -0
- package/package.json +1 -1
- package/templates/MainActivityNative.kt.template +30 -28
package/README.md
CHANGED
|
@@ -137,6 +137,11 @@ their intrinsic width unless explicitly configured.
|
|
|
137
137
|
Wrapped containers also honor `alignContent` (`center`, `flex-end`,
|
|
138
138
|
`space-between`, `space-around`, `space-evenly`, and `stretch`) consistently
|
|
139
139
|
across hosts.
|
|
140
|
+
The Android local fallback keeps fractional line and grid spacing until each
|
|
141
|
+
child frame is rounded, matching the shared layout ABI when an older runtime
|
|
142
|
+
does not expose its optional alignment symbols.
|
|
143
|
+
Its flex main-axis fallback applies the same fractional treatment to
|
|
144
|
+
`space-around` and `space-evenly` before rounding positions.
|
|
140
145
|
Shared wrapped-line IDs are accepted only when they are complete and monotonic;
|
|
141
146
|
invalid bridge data falls back to the host layout implementation.
|
|
142
147
|
Push, replace, and back preserve the
|
package/package.json
CHANGED
|
@@ -791,28 +791,28 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
791
791
|
} else {
|
|
792
792
|
val totalRows = layout.rowHeights.sum()
|
|
793
793
|
val rowGaps = max(0, layout.rowHeights.size - 1) * rowGap
|
|
794
|
-
val freeRows = max(0, contentHeight - totalRows - rowGaps)
|
|
794
|
+
val freeRows = max(0, contentHeight - totalRows - rowGaps).toFloat()
|
|
795
795
|
val rowCount = max(1, layout.rowHeights.size)
|
|
796
|
-
var rowLeading =
|
|
797
|
-
var rowBetween = rowGap
|
|
798
|
-
var rowExtra =
|
|
796
|
+
var rowLeading = 0f
|
|
797
|
+
var rowBetween = rowGap.toFloat()
|
|
798
|
+
var rowExtra = 0f
|
|
799
799
|
when (alignContentCode()) {
|
|
800
|
-
1 -> rowLeading = freeRows /
|
|
800
|
+
1 -> rowLeading = freeRows / 2f
|
|
801
801
|
2 -> rowLeading = freeRows
|
|
802
|
-
3 -> if (rowCount > 1) rowBetween += freeRows / (rowCount - 1)
|
|
802
|
+
3 -> if (rowCount > 1) rowBetween += freeRows / (rowCount - 1).toFloat()
|
|
803
803
|
4 -> {
|
|
804
|
-
rowLeading = freeRows / (rowCount * 2)
|
|
805
|
-
rowBetween += freeRows / rowCount
|
|
804
|
+
rowLeading = freeRows / (rowCount * 2).toFloat()
|
|
805
|
+
rowBetween += freeRows / rowCount.toFloat()
|
|
806
806
|
}
|
|
807
807
|
6 -> {
|
|
808
|
-
rowLeading = freeRows / (rowCount + 1)
|
|
809
|
-
rowBetween += freeRows / (rowCount + 1)
|
|
808
|
+
rowLeading = freeRows / (rowCount + 1).toFloat()
|
|
809
|
+
rowBetween += freeRows / (rowCount + 1).toFloat()
|
|
810
810
|
}
|
|
811
|
-
5 -> rowExtra = freeRows / rowCount
|
|
811
|
+
5 -> rowExtra = freeRows / rowCount.toFloat()
|
|
812
812
|
}
|
|
813
|
-
var rowTop = paddingTop + rowLeading
|
|
813
|
+
var rowTop = paddingTop.toFloat() + rowLeading
|
|
814
814
|
for ((rowIndex, row) in layout.rows.withIndex()) {
|
|
815
|
-
val rowHeight = layout.rowHeights[rowIndex] + rowExtra
|
|
815
|
+
val rowHeight = layout.rowHeights[rowIndex].toFloat() + rowExtra
|
|
816
816
|
for ((column, entry) in row.withIndex()) {
|
|
817
817
|
val align = entry.style.alignSelf ?: alignItems
|
|
818
818
|
val lp = entry.view.layoutParams as? MarginLayoutParams
|
|
@@ -821,7 +821,7 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
821
821
|
val marginTop = lp?.topMargin ?: 0
|
|
822
822
|
val marginBottom = lp?.bottomMargin ?: 0
|
|
823
823
|
val availableWidth = max(0, layout.cellWidth - marginLeft - marginRight)
|
|
824
|
-
val availableHeight = max(0, rowHeight - marginTop - marginBottom)
|
|
824
|
+
val availableHeight = max(0, (rowHeight - marginTop - marginBottom).roundToInt())
|
|
825
825
|
val childWidth = if (align == "stretch" && entry.style.width == null) availableWidth else min(availableWidth, entry.width)
|
|
826
826
|
val childHeight = if (align == "stretch" && entry.style.height == null) availableHeight else min(availableHeight, entry.height)
|
|
827
827
|
val x = paddingLeft + column * (layout.cellWidth + columnGap) + marginLeft + when (align) {
|
|
@@ -829,11 +829,11 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
829
829
|
"flex-end" -> availableWidth - childWidth
|
|
830
830
|
else -> 0
|
|
831
831
|
}
|
|
832
|
-
val y = rowTop + marginTop + when (align) {
|
|
832
|
+
val y = (rowTop + marginTop + when (align) {
|
|
833
833
|
"center" -> (availableHeight - childHeight) / 2
|
|
834
834
|
"flex-end" -> availableHeight - childHeight
|
|
835
835
|
else -> 0
|
|
836
|
-
}
|
|
836
|
+
}).roundToInt()
|
|
837
837
|
entry.view.layout(x, y, x + childWidth, y + childHeight)
|
|
838
838
|
}
|
|
839
839
|
rowTop += rowHeight + rowBetween
|
|
@@ -930,8 +930,7 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
930
930
|
}
|
|
931
931
|
val free = max(0, availableMain - distributedMain)
|
|
932
932
|
val (leading, between) = distribution(free, line.entries.size)
|
|
933
|
-
var mainOffset = if (orientation == HORIZONTAL) paddingLeft else paddingTop
|
|
934
|
-
mainOffset += leading
|
|
933
|
+
var mainOffset = (if (orientation == HORIZONTAL) paddingLeft else paddingTop).toFloat() + leading
|
|
935
934
|
for ((index, entry) in line.entries.withIndex()) {
|
|
936
935
|
val lp = entry.view.layoutParams as? MarginLayoutParams
|
|
937
936
|
val marginStart = if (orientation == HORIZONTAL) lp?.leftMargin ?: 0 else lp?.topMargin ?: 0
|
|
@@ -958,10 +957,10 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
958
957
|
// local main-axis rule remains the fallback for old runtimes
|
|
959
958
|
// that return widths only.
|
|
960
959
|
val sharedPosition = if (!reverse) sharedPositions?.get(index)?.roundToInt() else null
|
|
961
|
-
val positionedMain = sharedPosition?.let { (if (orientation == HORIZONTAL) paddingLeft else paddingTop) + it }
|
|
960
|
+
val positionedMain = sharedPosition?.let { (if (orientation == HORIZONTAL) paddingLeft else paddingTop).toFloat() + it }
|
|
962
961
|
?: mainOffset + marginStart
|
|
963
|
-
val x = if (orientation == HORIZONTAL) positionedMain else lineOffset + crossPosition
|
|
964
|
-
val y = if (orientation == HORIZONTAL) lineOffset + crossPosition else positionedMain
|
|
962
|
+
val x = if (orientation == HORIZONTAL) positionedMain.roundToInt() else lineOffset + crossPosition
|
|
963
|
+
val y = if (orientation == HORIZONTAL) lineOffset + crossPosition else positionedMain.roundToInt()
|
|
965
964
|
val distributedPrimary = sharedPrimary?.get(index)?.roundToInt() ?: fallbackWidths[index]
|
|
966
965
|
val w = if (orientation == HORIZONTAL) distributedPrimary else crossSize
|
|
967
966
|
val h = if (orientation == HORIZONTAL) crossSize else distributedPrimary
|
|
@@ -981,13 +980,16 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
981
980
|
onLayoutChanged?.invoke()
|
|
982
981
|
}
|
|
983
982
|
|
|
984
|
-
private fun distribution(free: Int, count: Int): Pair<
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
983
|
+
private fun distribution(free: Int, count: Int): Pair<Float, Float> {
|
|
984
|
+
val available = free.toFloat()
|
|
985
|
+
return when (justifyContent) {
|
|
986
|
+
"center" -> available / 2f to 0f
|
|
987
|
+
"flex-end" -> available to 0f
|
|
988
|
+
"space-between" -> 0f to if (count > 1) available / (count - 1).toFloat() else 0f
|
|
989
|
+
"space-around" -> available / (count * 2).toFloat() to available / count.toFloat()
|
|
990
|
+
"space-evenly" -> available / (count + 1).toFloat() to available / (count + 1).toFloat()
|
|
991
|
+
else -> 0f to 0f
|
|
992
|
+
}
|
|
991
993
|
}
|
|
992
994
|
}
|
|
993
995
|
|