@craft-native/android 0.0.161 → 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 +7 -1
- package/package.json +1 -1
- package/templates/MainActivityNative.kt.template +37 -26
package/README.md
CHANGED
|
@@ -135,7 +135,13 @@ When `flexShrink` is omitted, horizontal text labels and scroll hosts use the
|
|
|
135
135
|
same shrink defaults as the iOS renderer; buttons and editable fields retain
|
|
136
136
|
their intrinsic width unless explicitly configured.
|
|
137
137
|
Wrapped containers also honor `alignContent` (`center`, `flex-end`,
|
|
138
|
-
`space-between`, `space-around`, and `stretch`) consistently
|
|
138
|
+
`space-between`, `space-around`, `space-evenly`, and `stretch`) consistently
|
|
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.
|
|
139
145
|
Shared wrapped-line IDs are accepted only when they are complete and monotonic;
|
|
140
146
|
invalid bridge data falls back to the host layout implementation.
|
|
141
147
|
Push, replace, and back preserve the
|
package/package.json
CHANGED
|
@@ -653,6 +653,7 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
653
653
|
"space-between" -> 3
|
|
654
654
|
"space-around" -> 4
|
|
655
655
|
"stretch" -> 5
|
|
656
|
+
"space-evenly" -> 6
|
|
656
657
|
else -> 0
|
|
657
658
|
}
|
|
658
659
|
|
|
@@ -790,24 +791,28 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
790
791
|
} else {
|
|
791
792
|
val totalRows = layout.rowHeights.sum()
|
|
792
793
|
val rowGaps = max(0, layout.rowHeights.size - 1) * rowGap
|
|
793
|
-
val freeRows = max(0, contentHeight - totalRows - rowGaps)
|
|
794
|
+
val freeRows = max(0, contentHeight - totalRows - rowGaps).toFloat()
|
|
794
795
|
val rowCount = max(1, layout.rowHeights.size)
|
|
795
|
-
var rowLeading =
|
|
796
|
-
var rowBetween = rowGap
|
|
797
|
-
var rowExtra =
|
|
796
|
+
var rowLeading = 0f
|
|
797
|
+
var rowBetween = rowGap.toFloat()
|
|
798
|
+
var rowExtra = 0f
|
|
798
799
|
when (alignContentCode()) {
|
|
799
|
-
1 -> rowLeading = freeRows /
|
|
800
|
+
1 -> rowLeading = freeRows / 2f
|
|
800
801
|
2 -> rowLeading = freeRows
|
|
801
|
-
3 -> if (rowCount > 1) rowBetween += freeRows / (rowCount - 1)
|
|
802
|
+
3 -> if (rowCount > 1) rowBetween += freeRows / (rowCount - 1).toFloat()
|
|
802
803
|
4 -> {
|
|
803
|
-
rowLeading = freeRows / (rowCount * 2)
|
|
804
|
-
rowBetween += freeRows / rowCount
|
|
804
|
+
rowLeading = freeRows / (rowCount * 2).toFloat()
|
|
805
|
+
rowBetween += freeRows / rowCount.toFloat()
|
|
805
806
|
}
|
|
806
|
-
|
|
807
|
+
6 -> {
|
|
808
|
+
rowLeading = freeRows / (rowCount + 1).toFloat()
|
|
809
|
+
rowBetween += freeRows / (rowCount + 1).toFloat()
|
|
810
|
+
}
|
|
811
|
+
5 -> rowExtra = freeRows / rowCount.toFloat()
|
|
807
812
|
}
|
|
808
|
-
var rowTop = paddingTop + rowLeading
|
|
813
|
+
var rowTop = paddingTop.toFloat() + rowLeading
|
|
809
814
|
for ((rowIndex, row) in layout.rows.withIndex()) {
|
|
810
|
-
val rowHeight = layout.rowHeights[rowIndex] + rowExtra
|
|
815
|
+
val rowHeight = layout.rowHeights[rowIndex].toFloat() + rowExtra
|
|
811
816
|
for ((column, entry) in row.withIndex()) {
|
|
812
817
|
val align = entry.style.alignSelf ?: alignItems
|
|
813
818
|
val lp = entry.view.layoutParams as? MarginLayoutParams
|
|
@@ -816,7 +821,7 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
816
821
|
val marginTop = lp?.topMargin ?: 0
|
|
817
822
|
val marginBottom = lp?.bottomMargin ?: 0
|
|
818
823
|
val availableWidth = max(0, layout.cellWidth - marginLeft - marginRight)
|
|
819
|
-
val availableHeight = max(0, rowHeight - marginTop - marginBottom)
|
|
824
|
+
val availableHeight = max(0, (rowHeight - marginTop - marginBottom).roundToInt())
|
|
820
825
|
val childWidth = if (align == "stretch" && entry.style.width == null) availableWidth else min(availableWidth, entry.width)
|
|
821
826
|
val childHeight = if (align == "stretch" && entry.style.height == null) availableHeight else min(availableHeight, entry.height)
|
|
822
827
|
val x = paddingLeft + column * (layout.cellWidth + columnGap) + marginLeft + when (align) {
|
|
@@ -824,11 +829,11 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
824
829
|
"flex-end" -> availableWidth - childWidth
|
|
825
830
|
else -> 0
|
|
826
831
|
}
|
|
827
|
-
val y = rowTop + marginTop + when (align) {
|
|
832
|
+
val y = (rowTop + marginTop + when (align) {
|
|
828
833
|
"center" -> (availableHeight - childHeight) / 2
|
|
829
834
|
"flex-end" -> availableHeight - childHeight
|
|
830
835
|
else -> 0
|
|
831
|
-
}
|
|
836
|
+
}).roundToInt()
|
|
832
837
|
entry.view.layout(x, y, x + childWidth, y + childHeight)
|
|
833
838
|
}
|
|
834
839
|
rowTop += rowHeight + rowBetween
|
|
@@ -871,6 +876,10 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
871
876
|
crossBetween = crossFree / lines.size + crossGap
|
|
872
877
|
crossLeading = crossFree / (lines.size * 2)
|
|
873
878
|
}
|
|
879
|
+
"space-evenly" -> {
|
|
880
|
+
crossBetween = crossFree / (lines.size + 1) + crossGap
|
|
881
|
+
crossLeading = crossFree / (lines.size + 1)
|
|
882
|
+
}
|
|
874
883
|
"stretch" -> {
|
|
875
884
|
val extra = crossFree / lines.size
|
|
876
885
|
lines.forEach { it.cross += extra }
|
|
@@ -921,8 +930,7 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
921
930
|
}
|
|
922
931
|
val free = max(0, availableMain - distributedMain)
|
|
923
932
|
val (leading, between) = distribution(free, line.entries.size)
|
|
924
|
-
var mainOffset = if (orientation == HORIZONTAL) paddingLeft else paddingTop
|
|
925
|
-
mainOffset += leading
|
|
933
|
+
var mainOffset = (if (orientation == HORIZONTAL) paddingLeft else paddingTop).toFloat() + leading
|
|
926
934
|
for ((index, entry) in line.entries.withIndex()) {
|
|
927
935
|
val lp = entry.view.layoutParams as? MarginLayoutParams
|
|
928
936
|
val marginStart = if (orientation == HORIZONTAL) lp?.leftMargin ?: 0 else lp?.topMargin ?: 0
|
|
@@ -949,10 +957,10 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
949
957
|
// local main-axis rule remains the fallback for old runtimes
|
|
950
958
|
// that return widths only.
|
|
951
959
|
val sharedPosition = if (!reverse) sharedPositions?.get(index)?.roundToInt() else null
|
|
952
|
-
val positionedMain = sharedPosition?.let { (if (orientation == HORIZONTAL) paddingLeft else paddingTop) + it }
|
|
960
|
+
val positionedMain = sharedPosition?.let { (if (orientation == HORIZONTAL) paddingLeft else paddingTop).toFloat() + it }
|
|
953
961
|
?: mainOffset + marginStart
|
|
954
|
-
val x = if (orientation == HORIZONTAL) positionedMain else lineOffset + crossPosition
|
|
955
|
-
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()
|
|
956
964
|
val distributedPrimary = sharedPrimary?.get(index)?.roundToInt() ?: fallbackWidths[index]
|
|
957
965
|
val w = if (orientation == HORIZONTAL) distributedPrimary else crossSize
|
|
958
966
|
val h = if (orientation == HORIZONTAL) crossSize else distributedPrimary
|
|
@@ -972,13 +980,16 @@ private class CraftNativeFlexLayout(context: Context) : LinearLayout(context) {
|
|
|
972
980
|
onLayoutChanged?.invoke()
|
|
973
981
|
}
|
|
974
982
|
|
|
975
|
-
private fun distribution(free: Int, count: Int): Pair<
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
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
|
+
}
|
|
982
993
|
}
|
|
983
994
|
}
|
|
984
995
|
|