@expo/ui 58.0.21 → 58.0.23
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/CHANGELOG.md +34 -0
- package/README.md +86 -2
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/ui/ComposeViews.kt +53 -29
- package/android/src/main/java/expo/modules/ui/CompositionLocalProviderView.kt +26 -0
- package/android/src/main/java/expo/modules/ui/ExpoUIModule.kt +12 -0
- package/android/src/main/java/expo/modules/ui/HostView.kt +56 -9
- package/android/src/main/java/expo/modules/ui/MaskView.kt +3 -2
- package/android/src/main/java/expo/modules/ui/ModifierRegistry.kt +43 -13
- package/android/src/main/java/expo/modules/ui/RNHostView.kt +11 -7
- package/android/src/main/java/expo/modules/ui/SwitchView.kt +6 -1
- package/android/src/main/java/expo/modules/ui/TopAppBarView.kt +62 -0
- package/android/src/main/java/expo/modules/ui/UniversalLayout.kt +610 -0
- package/android/src/main/java/expo/modules/ui/colors/MaterialColors.kt +61 -0
- package/android/src/main/java/expo/modules/ui/state/ObservableState.kt +2 -0
- package/android/src/main/java/expo/modules/ui/state/WorkletCallback.kt +2 -0
- package/build/community/bottom-sheet/BottomSheet.ios.js +8 -3
- package/build/community/bottom-sheet/BottomSheet.ios.js.map +1 -1
- package/build/community/pager-view/PagerView.ios.js +25 -8
- package/build/community/pager-view/PagerView.ios.js.map +1 -1
- package/build/community/segmented-control/SegmentedControl.ios.js +11 -2
- package/build/community/segmented-control/SegmentedControl.ios.js.map +1 -1
- package/build/community/segmented-control/types.d.ts +5 -1
- package/build/community/segmented-control/types.js.map +1 -1
- package/build/jetpack-compose/Column/index.d.ts +5 -0
- package/build/jetpack-compose/Column/index.js.map +1 -1
- package/build/jetpack-compose/CompositionLocalProvider/index.d.ts +28 -0
- package/build/jetpack-compose/CompositionLocalProvider/index.js +15 -0
- package/build/jetpack-compose/CompositionLocalProvider/index.js.map +1 -0
- package/build/jetpack-compose/Host/index.d.ts +8 -0
- package/build/jetpack-compose/Host/index.js +38 -5
- package/build/jetpack-compose/Host/index.js.map +1 -1
- package/build/jetpack-compose/Row/index.d.ts +5 -0
- package/build/jetpack-compose/Row/index.js.map +1 -1
- package/build/jetpack-compose/Switch/index.d.ts +2 -0
- package/build/jetpack-compose/Switch/index.js +1 -0
- package/build/jetpack-compose/Switch/index.js.map +1 -1
- package/build/jetpack-compose/TopAppBar/index.d.ts +72 -0
- package/build/jetpack-compose/TopAppBar/index.js +45 -0
- package/build/jetpack-compose/TopAppBar/index.js.map +1 -0
- package/build/jetpack-compose/index.d.ts +2 -0
- package/build/jetpack-compose/index.js +2 -0
- package/build/jetpack-compose/index.js.map +1 -1
- package/build/jetpack-compose/modifiers/index.d.ts +5 -1
- package/build/jetpack-compose/modifiers/index.js +6 -2
- package/build/jetpack-compose/modifiers/index.js.map +1 -1
- package/build/recycling/useRecycledRows.d.ts +2 -0
- package/build/recycling/useRecycledRows.js +1 -0
- package/build/recycling/useRecycledRows.js.map +1 -1
- package/build/swift-ui/BottomSheet/index.d.ts +6 -0
- package/build/swift-ui/BottomSheet/index.js +9 -3
- package/build/swift-ui/BottomSheet/index.js.map +1 -1
- package/build/swift-ui/HStack/index.d.ts +6 -0
- package/build/swift-ui/HStack/index.js.map +1 -1
- package/build/swift-ui/VStack/index.d.ts +6 -0
- package/build/swift-ui/VStack/index.js.map +1 -1
- package/build/universal/Button/index.android.js +3 -1
- package/build/universal/Button/index.android.js.map +1 -1
- package/build/universal/Button/index.ios.js +3 -1
- package/build/universal/Button/index.ios.js.map +1 -1
- package/build/universal/Checkbox/index.android.js +16 -4
- package/build/universal/Checkbox/index.android.js.map +1 -1
- package/build/universal/Collapsible/index.ios.js +1 -0
- package/build/universal/Collapsible/index.ios.js.map +1 -1
- package/build/universal/Column/index.android.js +4 -1
- package/build/universal/Column/index.android.js.map +1 -1
- package/build/universal/Column/index.ios.js +2 -0
- package/build/universal/Column/index.ios.js.map +1 -1
- package/build/universal/Column/index.js +13 -4
- package/build/universal/Column/index.js.map +1 -1
- package/build/universal/FieldGroup/FieldGroup.android.js +3 -1
- package/build/universal/FieldGroup/FieldGroup.android.js.map +1 -1
- package/build/universal/FieldGroup/FieldGroup.ios.js +3 -1
- package/build/universal/FieldGroup/FieldGroup.ios.js.map +1 -1
- package/build/universal/FieldGroup/FieldSection.android.js +13 -4
- package/build/universal/FieldGroup/FieldSection.android.js.map +1 -1
- package/build/universal/FieldGroup/FieldSection.ios.js +3 -1
- package/build/universal/FieldGroup/FieldSection.ios.js.map +1 -1
- package/build/universal/Icon/index.android.js +3 -1
- package/build/universal/Icon/index.android.js.map +1 -1
- package/build/universal/Icon/index.ios.js +3 -1
- package/build/universal/Icon/index.ios.js.map +1 -1
- package/build/universal/List/ListForEach.android.d.ts +7 -0
- package/build/universal/List/ListForEach.android.js +6 -0
- package/build/universal/List/ListForEach.android.js.map +1 -0
- package/build/universal/List/ListForEach.d.ts +5 -0
- package/build/universal/List/ListForEach.ios.d.ts +5 -0
- package/build/universal/List/ListForEach.ios.js +11 -0
- package/build/universal/List/ListForEach.ios.js.map +1 -0
- package/build/universal/List/ListForEach.js +263 -0
- package/build/universal/List/ListForEach.js.map +1 -0
- package/build/universal/List/ListScrollContext.d.ts +5 -0
- package/build/universal/List/ListScrollContext.js +6 -0
- package/build/universal/List/ListScrollContext.js.map +1 -0
- package/build/universal/List/index.android.d.ts +5 -0
- package/build/universal/List/index.android.js +3 -0
- package/build/universal/List/index.android.js.map +1 -1
- package/build/universal/List/index.d.ts +5 -0
- package/build/universal/List/index.ios.d.ts +5 -0
- package/build/universal/List/index.ios.js +3 -0
- package/build/universal/List/index.ios.js.map +1 -1
- package/build/universal/List/index.js +12 -1
- package/build/universal/List/index.js.map +1 -1
- package/build/universal/List/types.d.ts +42 -1
- package/build/universal/List/types.js +1 -3
- package/build/universal/List/types.js.map +1 -1
- package/build/universal/RNHostView/index.android.js +3 -1
- package/build/universal/RNHostView/index.android.js.map +1 -1
- package/build/universal/Row/index.android.js +4 -1
- package/build/universal/Row/index.android.js.map +1 -1
- package/build/universal/Row/index.ios.js +2 -0
- package/build/universal/Row/index.ios.js.map +1 -1
- package/build/universal/Row/index.js +13 -7
- package/build/universal/Row/index.js.map +1 -1
- package/build/universal/ScrollView/index.android.js +8 -1
- package/build/universal/ScrollView/index.android.js.map +1 -1
- package/build/universal/ScrollView/index.ios.js +15 -7
- package/build/universal/ScrollView/index.ios.js.map +1 -1
- package/build/universal/Spacer/index.android.js +3 -1
- package/build/universal/Spacer/index.android.js.map +1 -1
- package/build/universal/Spacer/index.ios.js +3 -1
- package/build/universal/Spacer/index.ios.js.map +1 -1
- package/build/universal/Switch/index.android.js +17 -4
- package/build/universal/Switch/index.android.js.map +1 -1
- package/build/universal/Switch/index.js +1 -0
- package/build/universal/Switch/index.js.map +1 -1
- package/build/universal/Text/index.android.js +3 -1
- package/build/universal/Text/index.android.js.map +1 -1
- package/build/universal/Text/index.ios.js +3 -1
- package/build/universal/Text/index.ios.js.map +1 -1
- package/build/universal/Text/index.js +2 -2
- package/build/universal/Text/index.js.map +1 -1
- package/build/universal/TextInput/index.android.js +22 -7
- package/build/universal/TextInput/index.android.js.map +1 -1
- package/build/universal/TextInput/index.ios.js +1 -0
- package/build/universal/TextInput/index.ios.js.map +1 -1
- package/build/universal/index.d.ts +1 -1
- package/build/universal/modifierUtils.d.ts +34 -1
- package/build/universal/modifierUtils.js +98 -2
- package/build/universal/modifierUtils.js.map +1 -1
- package/build/universal/stackAxis.d.ts +9 -0
- package/build/universal/stackAxis.js +11 -0
- package/build/universal/stackAxis.js.map +1 -0
- package/build/universal/transformStyle.android.d.ts +6 -2
- package/build/universal/transformStyle.android.js +18 -11
- package/build/universal/transformStyle.android.js.map +1 -1
- package/build/universal/transformStyle.ios.d.ts +5 -1
- package/build/universal/transformStyle.ios.js +29 -11
- package/build/universal/transformStyle.ios.js.map +1 -1
- package/build/universal/types.d.ts +26 -1
- package/build/universal/types.js.map +1 -1
- package/build/universal/webUtils.js +4 -0
- package/build/universal/webUtils.js.map +1 -1
- package/ios/BottomSheetView.swift +11 -2
- package/ios/DatePickerView.swift +134 -9
- package/ios/GroupView.swift +3 -0
- package/ios/HStackView.swift +26 -2
- package/ios/HostView.swift +21 -12
- package/ios/Modifiers/SelectedSegmentTintColorModifier.swift +86 -0
- package/ios/Modifiers/ViewModifierRegistry.swift +8 -0
- package/ios/RNHostView.swift +34 -16
- package/ios/ScrollViewComponent.swift +20 -0
- package/ios/UIBaseView.swift +4 -1
- package/ios/UniversalLayout.swift +691 -0
- package/ios/VStackView.swift +26 -2
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.21/expo.modules.ui-58.0.21-sources.jar → 58.0.23/expo.modules.ui-58.0.23-sources.jar} +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.sha512 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.sha512 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.21/expo.modules.ui-58.0.21.module → 58.0.23/expo.modules.ui-58.0.23.module} +22 -22
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.sha512 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.21/expo.modules.ui-58.0.21.pom → 58.0.23/expo.modules.ui-58.0.23.pom} +1 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.sha512 +1 -0
- package/package.json +2 -2
- package/src/community/bottom-sheet/BottomSheet.ios.tsx +7 -3
- package/src/community/pager-view/PagerView.ios.tsx +25 -8
- package/src/community/segmented-control/SegmentedControl.ios.tsx +13 -1
- package/src/community/segmented-control/types.tsx +5 -1
- package/src/jetpack-compose/Column/index.tsx +5 -0
- package/src/jetpack-compose/CompositionLocalProvider/index.tsx +43 -0
- package/src/jetpack-compose/Host/index.tsx +50 -4
- package/src/jetpack-compose/Row/index.tsx +5 -0
- package/src/jetpack-compose/Switch/index.tsx +4 -0
- package/src/jetpack-compose/TopAppBar/index.tsx +113 -0
- package/src/jetpack-compose/index.ts +2 -0
- package/src/jetpack-compose/modifiers/index.ts +11 -3
- package/src/recycling/useRecycledRows.tsx +3 -0
- package/src/swift-ui/BottomSheet/index.tsx +24 -3
- package/src/swift-ui/HStack/index.tsx +6 -0
- package/src/swift-ui/VStack/index.tsx +6 -0
- package/src/universal/Button/index.android.tsx +3 -1
- package/src/universal/Button/index.ios.tsx +2 -1
- package/src/universal/Checkbox/index.android.tsx +24 -5
- package/src/universal/Collapsible/index.ios.tsx +4 -1
- package/src/universal/Column/index.android.tsx +3 -1
- package/src/universal/Column/index.ios.tsx +2 -1
- package/src/universal/Column/index.tsx +9 -4
- package/src/universal/FieldGroup/FieldGroup.android.tsx +8 -1
- package/src/universal/FieldGroup/FieldGroup.ios.tsx +2 -1
- package/src/universal/FieldGroup/FieldSection.android.tsx +17 -4
- package/src/universal/FieldGroup/FieldSection.ios.tsx +2 -1
- package/src/universal/Icon/index.android.tsx +2 -1
- package/src/universal/Icon/index.ios.tsx +2 -1
- package/src/universal/List/ListForEach.android.tsx +6 -0
- package/src/universal/List/ListForEach.ios.tsx +9 -0
- package/src/universal/List/ListForEach.tsx +246 -0
- package/src/universal/List/ListScrollContext.ts +6 -0
- package/src/universal/List/index.android.tsx +5 -0
- package/src/universal/List/index.ios.tsx +5 -0
- package/src/universal/List/index.tsx +11 -2
- package/src/universal/List/types.ts +45 -1
- package/src/universal/RNHostView/index.android.tsx +2 -1
- package/src/universal/Row/index.android.tsx +3 -1
- package/src/universal/Row/index.ios.tsx +2 -1
- package/src/universal/Row/index.tsx +9 -10
- package/src/universal/ScrollView/index.android.tsx +15 -3
- package/src/universal/ScrollView/index.ios.tsx +16 -4
- package/src/universal/Spacer/index.android.tsx +6 -4
- package/src/universal/Spacer/index.ios.tsx +2 -1
- package/src/universal/Switch/index.android.tsx +23 -4
- package/src/universal/Switch/index.tsx +1 -0
- package/src/universal/Text/index.android.tsx +2 -1
- package/src/universal/Text/index.ios.tsx +2 -1
- package/src/universal/Text/index.tsx +2 -2
- package/src/universal/TextInput/index.android.tsx +26 -5
- package/src/universal/TextInput/index.ios.tsx +1 -1
- package/src/universal/index.ts +6 -1
- package/src/universal/modifierUtils.ts +159 -2
- package/src/universal/stackAxis.ts +17 -0
- package/src/universal/transformStyle.android.ts +30 -12
- package/src/universal/transformStyle.ios.ts +41 -13
- package/src/universal/types.ts +27 -3
- package/src/universal/webUtils.ts +4 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.sha512 +0 -1
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
package expo.modules.ui
|
|
2
|
+
|
|
3
|
+
import androidx.compose.foundation.layout.Arrangement
|
|
4
|
+
import androidx.compose.runtime.Composable
|
|
5
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
6
|
+
import androidx.compose.runtime.compositionLocalOf
|
|
7
|
+
import androidx.compose.runtime.remember
|
|
8
|
+
import androidx.compose.ui.Alignment
|
|
9
|
+
import androidx.compose.ui.Modifier
|
|
10
|
+
import androidx.compose.ui.layout.IntrinsicMeasurable
|
|
11
|
+
import androidx.compose.ui.layout.IntrinsicMeasureScope
|
|
12
|
+
import androidx.compose.ui.layout.Layout
|
|
13
|
+
import androidx.compose.ui.layout.Measurable
|
|
14
|
+
import androidx.compose.ui.layout.MeasurePolicy
|
|
15
|
+
import androidx.compose.ui.layout.MeasureResult
|
|
16
|
+
import androidx.compose.ui.layout.MeasureScope
|
|
17
|
+
import androidx.compose.ui.layout.Placeable
|
|
18
|
+
import androidx.compose.ui.node.ModifierNodeElement
|
|
19
|
+
import androidx.compose.ui.node.ParentDataModifierNode
|
|
20
|
+
import androidx.compose.ui.platform.InspectorInfo
|
|
21
|
+
import androidx.compose.ui.unit.Constraints
|
|
22
|
+
import androidx.compose.ui.unit.Density
|
|
23
|
+
import androidx.compose.ui.unit.constrainHeight
|
|
24
|
+
import androidx.compose.ui.unit.constrainWidth
|
|
25
|
+
import expo.modules.kotlin.records.Field
|
|
26
|
+
import expo.modules.kotlin.records.Record
|
|
27
|
+
import expo.modules.kotlin.types.OptimizedRecord
|
|
28
|
+
import kotlin.math.max
|
|
29
|
+
import kotlin.math.min
|
|
30
|
+
import kotlin.math.roundToInt
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Row and Column in Compose size children from incoming constraints.
|
|
34
|
+
* They cannot resolve a percentage of the parent's content box, so universal
|
|
35
|
+
* `width` and `height` are measured by these layouts instead.
|
|
36
|
+
*/
|
|
37
|
+
internal enum class UniversalStackAxis {
|
|
38
|
+
Horizontal,
|
|
39
|
+
Vertical
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
internal val LocalUniversalStackAxis = compositionLocalOf<UniversalStackAxis?> { null }
|
|
43
|
+
|
|
44
|
+
internal data class UniversalLayoutParentData(
|
|
45
|
+
val dimensions: UniversalLayoutDimensions = UniversalLayoutDimensions(),
|
|
46
|
+
val weight: Float = 0f,
|
|
47
|
+
val horizontalAlignment: Alignment.Horizontal? = null,
|
|
48
|
+
val verticalAlignment: Alignment.Vertical? = null
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
internal fun Any?.asUniversalLayoutParentData(): UniversalLayoutParentData =
|
|
52
|
+
this as? UniversalLayoutParentData ?: UniversalLayoutParentData()
|
|
53
|
+
|
|
54
|
+
@OptimizedRecord
|
|
55
|
+
internal data class UniversalLayoutParams(
|
|
56
|
+
@Field val widthPoints: Double? = null,
|
|
57
|
+
@Field val widthFraction: Double? = null,
|
|
58
|
+
@Field val heightPoints: Double? = null,
|
|
59
|
+
@Field val heightFraction: Double? = null
|
|
60
|
+
) : Record
|
|
61
|
+
|
|
62
|
+
internal data class UniversalLayoutDimensions(
|
|
63
|
+
val widthPoints: Float? = null,
|
|
64
|
+
val widthFraction: Float? = null,
|
|
65
|
+
val heightPoints: Float? = null,
|
|
66
|
+
val heightFraction: Float? = null
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
internal fun UniversalLayoutParams.toDimensions(): UniversalLayoutDimensions =
|
|
70
|
+
UniversalLayoutDimensions(
|
|
71
|
+
widthPoints = widthPoints.validatedUniversalDimension(),
|
|
72
|
+
widthFraction = widthFraction.validatedUniversalDimension(),
|
|
73
|
+
heightPoints = heightPoints.validatedUniversalDimension(),
|
|
74
|
+
heightFraction = heightFraction.validatedUniversalDimension()
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
private fun Double?.validatedUniversalDimension(): Float? =
|
|
78
|
+
this?.toFloat()?.takeIf { it.isFinite() && it >= 0f }
|
|
79
|
+
|
|
80
|
+
internal data class UniversalLayoutElement(
|
|
81
|
+
val dimensions: UniversalLayoutDimensions
|
|
82
|
+
) : ModifierNodeElement<UniversalLayoutNode>() {
|
|
83
|
+
override fun create() = UniversalLayoutNode(dimensions)
|
|
84
|
+
|
|
85
|
+
override fun update(node: UniversalLayoutNode) {
|
|
86
|
+
node.dimensions = dimensions
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
override fun InspectorInfo.inspectableProperties() {
|
|
90
|
+
name = "universalLayout"
|
|
91
|
+
properties["dimensions"] = dimensions
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
internal class UniversalLayoutNode(
|
|
96
|
+
var dimensions: UniversalLayoutDimensions
|
|
97
|
+
) : Modifier.Node(), ParentDataModifierNode {
|
|
98
|
+
override fun Density.modifyParentData(parentData: Any?): Any {
|
|
99
|
+
// This node is outer, and Compose walks parent data from inner to outer.
|
|
100
|
+
// A platform Row, Column, FlowRow, or Box already stored weight or align.
|
|
101
|
+
// Those parents do not read this data, so keep theirs.
|
|
102
|
+
if (parentData != null && parentData !is UniversalLayoutParentData) {
|
|
103
|
+
return parentData
|
|
104
|
+
}
|
|
105
|
+
return parentData.asUniversalLayoutParentData().copy(dimensions = dimensions)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
internal data class UniversalWeightElement(val weight: Float) : ModifierNodeElement<UniversalWeightNode>() {
|
|
110
|
+
override fun create() = UniversalWeightNode(weight)
|
|
111
|
+
|
|
112
|
+
override fun update(node: UniversalWeightNode) {
|
|
113
|
+
node.weight = weight
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override fun InspectorInfo.inspectableProperties() {
|
|
117
|
+
name = "universalWeight"
|
|
118
|
+
properties["weight"] = weight
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
internal class UniversalWeightNode(var weight: Float) : Modifier.Node(), ParentDataModifierNode {
|
|
123
|
+
override fun Density.modifyParentData(parentData: Any?): Any =
|
|
124
|
+
parentData.asUniversalLayoutParentData().copy(weight = weight)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
internal data class UniversalAlignElement(
|
|
128
|
+
val horizontal: Alignment.Horizontal? = null,
|
|
129
|
+
val vertical: Alignment.Vertical? = null
|
|
130
|
+
) : ModifierNodeElement<UniversalAlignNode>() {
|
|
131
|
+
override fun create() = UniversalAlignNode(horizontal, vertical)
|
|
132
|
+
|
|
133
|
+
override fun update(node: UniversalAlignNode) {
|
|
134
|
+
node.horizontal = horizontal
|
|
135
|
+
node.vertical = vertical
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
override fun InspectorInfo.inspectableProperties() {
|
|
139
|
+
name = "universalAlign"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
internal class UniversalAlignNode(
|
|
144
|
+
var horizontal: Alignment.Horizontal?,
|
|
145
|
+
var vertical: Alignment.Vertical?
|
|
146
|
+
) : Modifier.Node(), ParentDataModifierNode {
|
|
147
|
+
override fun Density.modifyParentData(parentData: Any?): Any =
|
|
148
|
+
parentData.asUniversalLayoutParentData().copy(
|
|
149
|
+
horizontalAlignment = horizontal,
|
|
150
|
+
verticalAlignment = vertical
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private fun Float.toSafeFractionPixels(parentSize: Int): Int =
|
|
155
|
+
(this * parentSize).roundToInt().coerceIn(0, Constraints.Infinity)
|
|
156
|
+
|
|
157
|
+
private fun Float.toSafePixels(density: Float): Int =
|
|
158
|
+
(this * density).roundToInt().coerceIn(0, Constraints.Infinity)
|
|
159
|
+
|
|
160
|
+
private fun UniversalLayoutDimensions.resolveWidthFraction(parentWidth: Int?): Int? =
|
|
161
|
+
parentWidth?.let { widthFraction?.toSafeFractionPixels(it) }
|
|
162
|
+
|
|
163
|
+
private fun UniversalLayoutDimensions.resolveHeightFraction(parentHeight: Int?): Int? =
|
|
164
|
+
parentHeight?.let { heightFraction?.toSafeFractionPixels(it) }
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* An explicit size becomes a tight constraint, clamped so `min` never exceeds `max`.
|
|
168
|
+
* An unspecified axis keeps [maxWidth] or [maxHeight] as a loose upper bound.
|
|
169
|
+
*/
|
|
170
|
+
private fun fixedOrBoundedConstraints(
|
|
171
|
+
width: Int?,
|
|
172
|
+
height: Int?,
|
|
173
|
+
maxWidth: Int,
|
|
174
|
+
maxHeight: Int
|
|
175
|
+
): Constraints {
|
|
176
|
+
val resolvedWidth = width?.coerceIn(0, maxWidth.coerceAtLeast(0))
|
|
177
|
+
val resolvedHeight = height?.coerceIn(0, maxHeight.coerceAtLeast(0))
|
|
178
|
+
return Constraints(
|
|
179
|
+
minWidth = resolvedWidth ?: 0,
|
|
180
|
+
maxWidth = resolvedWidth ?: maxWidth,
|
|
181
|
+
minHeight = resolvedHeight ?: 0,
|
|
182
|
+
maxHeight = resolvedHeight ?: maxHeight
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Measures a host child.
|
|
188
|
+
* Axes without a universal size keep the incoming constraints, so a tight host
|
|
189
|
+
* still stretches unsized children.
|
|
190
|
+
*/
|
|
191
|
+
internal fun MeasureScope.measureUniversalChild(
|
|
192
|
+
measurable: Measurable,
|
|
193
|
+
constraints: Constraints,
|
|
194
|
+
parentWidth: Int?,
|
|
195
|
+
parentHeight: Int?
|
|
196
|
+
): Placeable {
|
|
197
|
+
val dimensions = measurable.parentData.asUniversalLayoutParentData().dimensions
|
|
198
|
+
// A host gives its children exact constraints, which would override a `width()` or `height()` modifier.
|
|
199
|
+
val width = dimensions.widthPoints?.toSafePixels(density) ?: dimensions.resolveWidthFraction(parentWidth)
|
|
200
|
+
val height = dimensions.heightPoints?.toSafePixels(density) ?: dimensions.resolveHeightFraction(parentHeight)
|
|
201
|
+
if (width == null && height == null) {
|
|
202
|
+
return measurable.measure(constraints)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
val resolved = fixedOrBoundedConstraints(width, height, constraints.maxWidth, constraints.maxHeight)
|
|
206
|
+
return measurable.measure(
|
|
207
|
+
Constraints(
|
|
208
|
+
minWidth = if (width != null) {
|
|
209
|
+
resolved.minWidth
|
|
210
|
+
} else {
|
|
211
|
+
constraints.minWidth
|
|
212
|
+
},
|
|
213
|
+
maxWidth = if (width != null) {
|
|
214
|
+
resolved.maxWidth
|
|
215
|
+
} else {
|
|
216
|
+
constraints.maxWidth
|
|
217
|
+
},
|
|
218
|
+
minHeight = if (height != null) {
|
|
219
|
+
resolved.minHeight
|
|
220
|
+
} else {
|
|
221
|
+
constraints.minHeight
|
|
222
|
+
},
|
|
223
|
+
maxHeight = if (height != null) {
|
|
224
|
+
resolved.maxHeight
|
|
225
|
+
} else {
|
|
226
|
+
constraints.maxHeight
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@Composable
|
|
233
|
+
internal fun UniversalRow(
|
|
234
|
+
modifier: Modifier,
|
|
235
|
+
horizontalArrangement: Arrangement.Horizontal,
|
|
236
|
+
verticalAlignment: Alignment.Vertical,
|
|
237
|
+
content: @Composable () -> Unit
|
|
238
|
+
) {
|
|
239
|
+
val measurePolicy = remember(horizontalArrangement, verticalAlignment) {
|
|
240
|
+
UniversalStackMeasurePolicy(
|
|
241
|
+
UniversalStackAxis.Horizontal,
|
|
242
|
+
horizontalArrangement,
|
|
243
|
+
Arrangement.Top,
|
|
244
|
+
Alignment.Start,
|
|
245
|
+
verticalAlignment
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
CompositionLocalProvider(LocalUniversalStackAxis provides UniversalStackAxis.Horizontal) {
|
|
249
|
+
Layout(content = content, modifier = modifier, measurePolicy = measurePolicy)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@Composable
|
|
254
|
+
internal fun UniversalColumn(
|
|
255
|
+
modifier: Modifier,
|
|
256
|
+
verticalArrangement: Arrangement.Vertical,
|
|
257
|
+
horizontalAlignment: Alignment.Horizontal,
|
|
258
|
+
content: @Composable () -> Unit
|
|
259
|
+
) {
|
|
260
|
+
val measurePolicy = remember(verticalArrangement, horizontalAlignment) {
|
|
261
|
+
UniversalStackMeasurePolicy(
|
|
262
|
+
UniversalStackAxis.Vertical,
|
|
263
|
+
Arrangement.Start,
|
|
264
|
+
verticalArrangement,
|
|
265
|
+
horizontalAlignment,
|
|
266
|
+
Alignment.Top
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
CompositionLocalProvider(LocalUniversalStackAxis provides UniversalStackAxis.Vertical) {
|
|
270
|
+
Layout(content = content, modifier = modifier, measurePolicy = measurePolicy)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private class UniversalStackMeasurePolicy(
|
|
275
|
+
private val axis: UniversalStackAxis,
|
|
276
|
+
private val horizontalArrangement: Arrangement.Horizontal,
|
|
277
|
+
private val verticalArrangement: Arrangement.Vertical,
|
|
278
|
+
private val horizontalAlignment: Alignment.Horizontal,
|
|
279
|
+
private val verticalAlignment: Alignment.Vertical
|
|
280
|
+
) : MeasurePolicy {
|
|
281
|
+
private val horizontal = axis == UniversalStackAxis.Horizontal
|
|
282
|
+
|
|
283
|
+
override fun MeasureScope.measure(measurables: List<Measurable>, constraints: Constraints): MeasureResult =
|
|
284
|
+
measureUniversalStack(
|
|
285
|
+
measurables,
|
|
286
|
+
constraints,
|
|
287
|
+
axis,
|
|
288
|
+
horizontalArrangement,
|
|
289
|
+
verticalArrangement,
|
|
290
|
+
horizontalAlignment,
|
|
291
|
+
verticalAlignment
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
// The intrinsics follow Compose `Row` and `Column`, which size weighted children by their weight.
|
|
295
|
+
override fun IntrinsicMeasureScope.minIntrinsicWidth(measurables: List<IntrinsicMeasurable>, height: Int): Int =
|
|
296
|
+
if (horizontal) {
|
|
297
|
+
intrinsicMainSize(measurables, height, spacingPx()) { minIntrinsicWidth(it) }
|
|
298
|
+
} else {
|
|
299
|
+
intrinsicCrossSize(measurables, height, spacingPx(), { minIntrinsicHeight(it) }, { minIntrinsicWidth(it) })
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
override fun IntrinsicMeasureScope.maxIntrinsicWidth(measurables: List<IntrinsicMeasurable>, height: Int): Int =
|
|
303
|
+
if (horizontal) {
|
|
304
|
+
intrinsicMainSize(measurables, height, spacingPx()) { maxIntrinsicWidth(it) }
|
|
305
|
+
} else {
|
|
306
|
+
intrinsicCrossSize(measurables, height, spacingPx(), { maxIntrinsicHeight(it) }, { maxIntrinsicWidth(it) })
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
override fun IntrinsicMeasureScope.minIntrinsicHeight(measurables: List<IntrinsicMeasurable>, width: Int): Int =
|
|
310
|
+
if (horizontal) {
|
|
311
|
+
intrinsicCrossSize(measurables, width, spacingPx(), { minIntrinsicWidth(it) }, { minIntrinsicHeight(it) })
|
|
312
|
+
} else {
|
|
313
|
+
intrinsicMainSize(measurables, width, spacingPx()) { minIntrinsicHeight(it) }
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
override fun IntrinsicMeasureScope.maxIntrinsicHeight(measurables: List<IntrinsicMeasurable>, width: Int): Int =
|
|
317
|
+
if (horizontal) {
|
|
318
|
+
intrinsicCrossSize(measurables, width, spacingPx(), { maxIntrinsicWidth(it) }, { maxIntrinsicHeight(it) })
|
|
319
|
+
} else {
|
|
320
|
+
intrinsicMainSize(measurables, width, spacingPx()) { maxIntrinsicHeight(it) }
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private fun Density.spacingPx(): Int =
|
|
324
|
+
(
|
|
325
|
+
if (horizontal) {
|
|
326
|
+
horizontalArrangement.spacing
|
|
327
|
+
} else {
|
|
328
|
+
verticalArrangement.spacing
|
|
329
|
+
}
|
|
330
|
+
).roundToPx().coerceAtLeast(0)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private inline fun intrinsicMainSize(
|
|
334
|
+
children: List<IntrinsicMeasurable>,
|
|
335
|
+
crossAvailable: Int,
|
|
336
|
+
spacing: Int,
|
|
337
|
+
mainSize: IntrinsicMeasurable.(Int) -> Int
|
|
338
|
+
): Int {
|
|
339
|
+
if (children.isEmpty()) {
|
|
340
|
+
return 0
|
|
341
|
+
}
|
|
342
|
+
var fixedSpace = 0
|
|
343
|
+
var weightUnitSpace = 0
|
|
344
|
+
var totalWeight = 0f
|
|
345
|
+
children.forEach { child ->
|
|
346
|
+
val weight = child.parentData.asUniversalLayoutParentData().weight
|
|
347
|
+
val size = child.mainSize(crossAvailable)
|
|
348
|
+
if (weight > 0f) {
|
|
349
|
+
totalWeight += weight
|
|
350
|
+
weightUnitSpace = max(weightUnitSpace, (size / weight).roundToInt())
|
|
351
|
+
} else {
|
|
352
|
+
fixedSpace += size
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return (weightUnitSpace * totalWeight).roundToInt() + fixedSpace + spacing * (children.size - 1)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private inline fun intrinsicCrossSize(
|
|
359
|
+
children: List<IntrinsicMeasurable>,
|
|
360
|
+
mainAvailable: Int,
|
|
361
|
+
spacing: Int,
|
|
362
|
+
mainSize: IntrinsicMeasurable.(Int) -> Int,
|
|
363
|
+
crossSize: IntrinsicMeasurable.(Int) -> Int
|
|
364
|
+
): Int {
|
|
365
|
+
if (children.isEmpty()) {
|
|
366
|
+
return 0
|
|
367
|
+
}
|
|
368
|
+
var fixedSpace = min(spacing * (children.size - 1), mainAvailable)
|
|
369
|
+
var crossMax = 0
|
|
370
|
+
var totalWeight = 0f
|
|
371
|
+
children.forEach { child ->
|
|
372
|
+
val weight = child.parentData.asUniversalLayoutParentData().weight
|
|
373
|
+
if (weight > 0f) {
|
|
374
|
+
totalWeight += weight
|
|
375
|
+
return@forEach
|
|
376
|
+
}
|
|
377
|
+
val preferredMain = child.mainSize(Constraints.Infinity)
|
|
378
|
+
val main = if (mainAvailable == Constraints.Infinity) {
|
|
379
|
+
preferredMain
|
|
380
|
+
} else {
|
|
381
|
+
min(preferredMain, (mainAvailable - fixedSpace).coerceAtLeast(0))
|
|
382
|
+
}
|
|
383
|
+
fixedSpace += main
|
|
384
|
+
crossMax = max(crossMax, child.crossSize(main))
|
|
385
|
+
}
|
|
386
|
+
val weightUnitSpace = when {
|
|
387
|
+
totalWeight == 0f -> 0
|
|
388
|
+
mainAvailable == Constraints.Infinity -> Constraints.Infinity
|
|
389
|
+
else -> ((mainAvailable - fixedSpace).coerceAtLeast(0) / totalWeight).roundToInt()
|
|
390
|
+
}
|
|
391
|
+
children.forEach { child ->
|
|
392
|
+
val weight = child.parentData.asUniversalLayoutParentData().weight
|
|
393
|
+
if (weight > 0f) {
|
|
394
|
+
val main = if (weightUnitSpace == Constraints.Infinity) {
|
|
395
|
+
Constraints.Infinity
|
|
396
|
+
} else {
|
|
397
|
+
(weightUnitSpace * weight).roundToInt()
|
|
398
|
+
}
|
|
399
|
+
crossMax = max(crossMax, child.crossSize(main))
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return crossMax
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
private fun MeasureScope.measureUniversalStack(
|
|
406
|
+
measurables: List<Measurable>,
|
|
407
|
+
constraints: Constraints,
|
|
408
|
+
axis: UniversalStackAxis,
|
|
409
|
+
horizontalArrangement: Arrangement.Horizontal,
|
|
410
|
+
verticalArrangement: Arrangement.Vertical,
|
|
411
|
+
horizontalAlignment: Alignment.Horizontal,
|
|
412
|
+
verticalAlignment: Alignment.Vertical
|
|
413
|
+
): MeasureResult {
|
|
414
|
+
val horizontal = axis == UniversalStackAxis.Horizontal
|
|
415
|
+
// A size is definite only when the parent gave this stack an exact constraint.
|
|
416
|
+
// A loose max is an upper bound, not a content box to take a percentage of.
|
|
417
|
+
val definiteWidth = constraints.maxWidth.takeIf {
|
|
418
|
+
it != Constraints.Infinity && constraints.minWidth == it
|
|
419
|
+
}
|
|
420
|
+
val definiteHeight = constraints.maxHeight.takeIf {
|
|
421
|
+
it != Constraints.Infinity && constraints.minHeight == it
|
|
422
|
+
}
|
|
423
|
+
val maxMain = if (horizontal) {
|
|
424
|
+
constraints.maxWidth
|
|
425
|
+
} else {
|
|
426
|
+
constraints.maxHeight
|
|
427
|
+
}
|
|
428
|
+
val maxCross = if (horizontal) {
|
|
429
|
+
constraints.maxHeight
|
|
430
|
+
} else {
|
|
431
|
+
constraints.maxWidth
|
|
432
|
+
}
|
|
433
|
+
val spacing = (
|
|
434
|
+
if (horizontal) {
|
|
435
|
+
horizontalArrangement.spacing.roundToPx()
|
|
436
|
+
} else {
|
|
437
|
+
verticalArrangement.spacing.roundToPx()
|
|
438
|
+
}
|
|
439
|
+
).coerceAtLeast(0)
|
|
440
|
+
val placeables = arrayOfNulls<Placeable>(measurables.size)
|
|
441
|
+
// Like Compose `Row` and `Column`, count only the spacing used so far, plus the gap after each child.
|
|
442
|
+
var occupiedMain = 0
|
|
443
|
+
var spaceAfterLastFixed = 0
|
|
444
|
+
|
|
445
|
+
measurables.forEachIndexed { index, measurable ->
|
|
446
|
+
val parentData = measurable.parentData.asUniversalLayoutParentData()
|
|
447
|
+
if (parentData.weight > 0f) {
|
|
448
|
+
return@forEachIndexed
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// A fixed size comes from the child's `width()` or `height()`, so it can shrink to the space left, as in Compose `Row`.
|
|
452
|
+
val width = parentData.dimensions.resolveWidthFraction(definiteWidth)
|
|
453
|
+
val height = parentData.dimensions.resolveHeightFraction(definiteHeight)
|
|
454
|
+
val resolvedMain = if (horizontal) {
|
|
455
|
+
width
|
|
456
|
+
} else {
|
|
457
|
+
height
|
|
458
|
+
}
|
|
459
|
+
val remainingMain = if (maxMain == Constraints.Infinity) {
|
|
460
|
+
Constraints.Infinity
|
|
461
|
+
} else {
|
|
462
|
+
(maxMain - occupiedMain).coerceAtLeast(0)
|
|
463
|
+
}
|
|
464
|
+
// The percentage uses the whole stack.
|
|
465
|
+
// The tight constraint is then limited to the incoming max, so 150% cannot paint past the parent.
|
|
466
|
+
val mainLimit = if (resolvedMain == null || maxMain == Constraints.Infinity) {
|
|
467
|
+
resolvedMain ?: remainingMain
|
|
468
|
+
} else {
|
|
469
|
+
resolvedMain.coerceAtMost(maxMain.coerceAtLeast(0))
|
|
470
|
+
}
|
|
471
|
+
val childConstraints = if (horizontal) {
|
|
472
|
+
fixedOrBoundedConstraints(width, height, mainLimit, maxCross)
|
|
473
|
+
} else {
|
|
474
|
+
fixedOrBoundedConstraints(width, height, maxCross, mainLimit)
|
|
475
|
+
}
|
|
476
|
+
val placeable = measurable.measure(childConstraints)
|
|
477
|
+
placeables[index] = placeable
|
|
478
|
+
val childMain = if (horizontal) {
|
|
479
|
+
placeable.width
|
|
480
|
+
} else {
|
|
481
|
+
placeable.height
|
|
482
|
+
}
|
|
483
|
+
spaceAfterLastFixed = if (remainingMain == Constraints.Infinity) {
|
|
484
|
+
spacing
|
|
485
|
+
} else {
|
|
486
|
+
min(spacing, (remainingMain - childMain).coerceAtLeast(0))
|
|
487
|
+
}
|
|
488
|
+
occupiedMain += childMain + spaceAfterLastFixed
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
var totalWeight = 0f
|
|
492
|
+
var weightedCount = 0
|
|
493
|
+
measurables.forEach { measurable ->
|
|
494
|
+
val weight = measurable.parentData.asUniversalLayoutParentData().weight
|
|
495
|
+
if (weight > 0f) {
|
|
496
|
+
totalWeight += weight
|
|
497
|
+
weightedCount++
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
val weightedSpacing = spacing * (weightedCount - 1).coerceAtLeast(0)
|
|
501
|
+
if (totalWeight == 0f) {
|
|
502
|
+
occupiedMain -= spaceAfterLastFixed
|
|
503
|
+
} else {
|
|
504
|
+
val targetMain = when {
|
|
505
|
+
maxMain != Constraints.Infinity -> maxMain
|
|
506
|
+
horizontal -> constraints.minWidth
|
|
507
|
+
else -> constraints.minHeight
|
|
508
|
+
}
|
|
509
|
+
var remaining = (targetMain - occupiedMain - weightedSpacing).coerceAtLeast(0)
|
|
510
|
+
var remainingWeight = totalWeight
|
|
511
|
+
measurables.forEachIndexed { index, measurable ->
|
|
512
|
+
val parentData = measurable.parentData.asUniversalLayoutParentData()
|
|
513
|
+
if (parentData.weight <= 0f) {
|
|
514
|
+
return@forEachIndexed
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
val laterWeight = measurables.drop(index + 1).any {
|
|
518
|
+
it.parentData.asUniversalLayoutParentData().weight > 0f
|
|
519
|
+
}
|
|
520
|
+
val share = if (!laterWeight) {
|
|
521
|
+
remaining
|
|
522
|
+
} else {
|
|
523
|
+
(remaining * (parentData.weight / remainingWeight)).roundToInt()
|
|
524
|
+
}
|
|
525
|
+
remaining -= share
|
|
526
|
+
remainingWeight -= parentData.weight
|
|
527
|
+
val width = if (horizontal) {
|
|
528
|
+
share
|
|
529
|
+
} else {
|
|
530
|
+
parentData.dimensions.resolveWidthFraction(definiteWidth)
|
|
531
|
+
}
|
|
532
|
+
val height = if (horizontal) {
|
|
533
|
+
parentData.dimensions.resolveHeightFraction(definiteHeight)
|
|
534
|
+
} else {
|
|
535
|
+
share
|
|
536
|
+
}
|
|
537
|
+
placeables[index] = measurable.measure(
|
|
538
|
+
fixedOrBoundedConstraints(width, height, constraints.maxWidth, constraints.maxHeight)
|
|
539
|
+
)
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
val childMainSizes = IntArray(placeables.size) { index ->
|
|
544
|
+
placeables[index]?.let {
|
|
545
|
+
if (horizontal) {
|
|
546
|
+
it.width
|
|
547
|
+
} else {
|
|
548
|
+
it.height
|
|
549
|
+
}
|
|
550
|
+
} ?: 0
|
|
551
|
+
}
|
|
552
|
+
var weightedMain = 0
|
|
553
|
+
measurables.forEachIndexed { index, measurable ->
|
|
554
|
+
if (measurable.parentData.asUniversalLayoutParentData().weight > 0f) {
|
|
555
|
+
weightedMain += childMainSizes[index]
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
val contentMain = occupiedMain + if (weightedCount > 0) {
|
|
559
|
+
weightedMain + weightedSpacing
|
|
560
|
+
} else {
|
|
561
|
+
0
|
|
562
|
+
}
|
|
563
|
+
val contentCross = placeables.maxOfOrNull {
|
|
564
|
+
it?.let { placeable ->
|
|
565
|
+
if (horizontal) {
|
|
566
|
+
placeable.height
|
|
567
|
+
} else {
|
|
568
|
+
placeable.width
|
|
569
|
+
}
|
|
570
|
+
} ?: 0
|
|
571
|
+
} ?: 0
|
|
572
|
+
val width = constraints.constrainWidth(
|
|
573
|
+
if (horizontal) {
|
|
574
|
+
contentMain
|
|
575
|
+
} else {
|
|
576
|
+
contentCross
|
|
577
|
+
}
|
|
578
|
+
)
|
|
579
|
+
val height = constraints.constrainHeight(
|
|
580
|
+
if (horizontal) {
|
|
581
|
+
contentCross
|
|
582
|
+
} else {
|
|
583
|
+
contentMain
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
val positions = IntArray(placeables.size)
|
|
587
|
+
if (horizontal) {
|
|
588
|
+
with(horizontalArrangement) {
|
|
589
|
+
arrange(width, childMainSizes, layoutDirection, positions)
|
|
590
|
+
}
|
|
591
|
+
} else {
|
|
592
|
+
with(verticalArrangement) {
|
|
593
|
+
arrange(height, childMainSizes, positions)
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return layout(width, height) {
|
|
598
|
+
placeables.forEachIndexed { index, placeable ->
|
|
599
|
+
placeable ?: return@forEachIndexed
|
|
600
|
+
val parentData = measurables[index].parentData.asUniversalLayoutParentData()
|
|
601
|
+
if (horizontal) {
|
|
602
|
+
val alignment = parentData.verticalAlignment ?: verticalAlignment
|
|
603
|
+
placeable.place(positions[index], alignment.align(placeable.height, height))
|
|
604
|
+
} else {
|
|
605
|
+
val alignment = parentData.horizontalAlignment ?: horizontalAlignment
|
|
606
|
+
placeable.place(alignment.align(placeable.width, width, layoutDirection), positions[index])
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
@@ -15,6 +15,7 @@ import expo.modules.kotlin.records.Field
|
|
|
15
15
|
import expo.modules.kotlin.records.Record
|
|
16
16
|
import expo.modules.kotlin.types.OptimizedRecord
|
|
17
17
|
import expo.modules.ui.ExpoColorScheme
|
|
18
|
+
import expo.modules.ui.composeOrNull
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Whether the current device supports Material You wallpaper-based dynamic
|
|
@@ -165,3 +166,63 @@ internal fun ColorScheme.toTokenMap(): Map<String, String> = mapOf(
|
|
|
165
166
|
"onTertiaryFixed" to onTertiaryFixed.toRgbaHex(),
|
|
166
167
|
"onTertiaryFixedVariant" to onTertiaryFixedVariant.toRgbaHex()
|
|
167
168
|
)
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Replaces the roles named in [overrides], keyed like [toTokenMap], and keeps the others.
|
|
172
|
+
*/
|
|
173
|
+
internal fun ColorScheme.withOverrides(overrides: Map<String, android.graphics.Color>): ColorScheme {
|
|
174
|
+
if (overrides.isEmpty()) {
|
|
175
|
+
return this
|
|
176
|
+
}
|
|
177
|
+
fun color(role: String, fallback: Color): Color = overrides[role]?.composeOrNull ?: fallback
|
|
178
|
+
return copy(
|
|
179
|
+
primary = color("primary", primary),
|
|
180
|
+
onPrimary = color("onPrimary", onPrimary),
|
|
181
|
+
primaryContainer = color("primaryContainer", primaryContainer),
|
|
182
|
+
onPrimaryContainer = color("onPrimaryContainer", onPrimaryContainer),
|
|
183
|
+
inversePrimary = color("inversePrimary", inversePrimary),
|
|
184
|
+
secondary = color("secondary", secondary),
|
|
185
|
+
onSecondary = color("onSecondary", onSecondary),
|
|
186
|
+
secondaryContainer = color("secondaryContainer", secondaryContainer),
|
|
187
|
+
onSecondaryContainer = color("onSecondaryContainer", onSecondaryContainer),
|
|
188
|
+
tertiary = color("tertiary", tertiary),
|
|
189
|
+
onTertiary = color("onTertiary", onTertiary),
|
|
190
|
+
tertiaryContainer = color("tertiaryContainer", tertiaryContainer),
|
|
191
|
+
onTertiaryContainer = color("onTertiaryContainer", onTertiaryContainer),
|
|
192
|
+
background = color("background", background),
|
|
193
|
+
onBackground = color("onBackground", onBackground),
|
|
194
|
+
surface = color("surface", surface),
|
|
195
|
+
onSurface = color("onSurface", onSurface),
|
|
196
|
+
surfaceVariant = color("surfaceVariant", surfaceVariant),
|
|
197
|
+
onSurfaceVariant = color("onSurfaceVariant", onSurfaceVariant),
|
|
198
|
+
surfaceTint = color("surfaceTint", surfaceTint),
|
|
199
|
+
inverseSurface = color("inverseSurface", inverseSurface),
|
|
200
|
+
inverseOnSurface = color("inverseOnSurface", inverseOnSurface),
|
|
201
|
+
error = color("error", error),
|
|
202
|
+
onError = color("onError", onError),
|
|
203
|
+
errorContainer = color("errorContainer", errorContainer),
|
|
204
|
+
onErrorContainer = color("onErrorContainer", onErrorContainer),
|
|
205
|
+
outline = color("outline", outline),
|
|
206
|
+
outlineVariant = color("outlineVariant", outlineVariant),
|
|
207
|
+
scrim = color("scrim", scrim),
|
|
208
|
+
surfaceBright = color("surfaceBright", surfaceBright),
|
|
209
|
+
surfaceDim = color("surfaceDim", surfaceDim),
|
|
210
|
+
surfaceContainer = color("surfaceContainer", surfaceContainer),
|
|
211
|
+
surfaceContainerHigh = color("surfaceContainerHigh", surfaceContainerHigh),
|
|
212
|
+
surfaceContainerHighest = color("surfaceContainerHighest", surfaceContainerHighest),
|
|
213
|
+
surfaceContainerLow = color("surfaceContainerLow", surfaceContainerLow),
|
|
214
|
+
surfaceContainerLowest = color("surfaceContainerLowest", surfaceContainerLowest),
|
|
215
|
+
primaryFixed = color("primaryFixed", primaryFixed),
|
|
216
|
+
primaryFixedDim = color("primaryFixedDim", primaryFixedDim),
|
|
217
|
+
onPrimaryFixed = color("onPrimaryFixed", onPrimaryFixed),
|
|
218
|
+
onPrimaryFixedVariant = color("onPrimaryFixedVariant", onPrimaryFixedVariant),
|
|
219
|
+
secondaryFixed = color("secondaryFixed", secondaryFixed),
|
|
220
|
+
secondaryFixedDim = color("secondaryFixedDim", secondaryFixedDim),
|
|
221
|
+
onSecondaryFixed = color("onSecondaryFixed", onSecondaryFixed),
|
|
222
|
+
onSecondaryFixedVariant = color("onSecondaryFixedVariant", onSecondaryFixedVariant),
|
|
223
|
+
tertiaryFixed = color("tertiaryFixed", tertiaryFixed),
|
|
224
|
+
tertiaryFixedDim = color("tertiaryFixedDim", tertiaryFixedDim),
|
|
225
|
+
onTertiaryFixed = color("onTertiaryFixed", onTertiaryFixed),
|
|
226
|
+
onTertiaryFixedVariant = color("onTertiaryFixedVariant", onTertiaryFixedVariant)
|
|
227
|
+
)
|
|
228
|
+
}
|
|
@@ -10,6 +10,8 @@ import expo.modules.kotlin.sharedobjects.SharedObject
|
|
|
10
10
|
* recomposes automatically when the value changes.
|
|
11
11
|
*/
|
|
12
12
|
class ObservableState(initialValue: Any? = null) : SharedObject() {
|
|
13
|
+
override val releasesAfterPendingViewUpdates = true
|
|
14
|
+
|
|
13
15
|
private val _state: MutableState<Any?> = mutableStateOf(initialValue)
|
|
14
16
|
internal var onChange: WorkletCallback? = null
|
|
15
17
|
private var isNotifying = false
|
|
@@ -10,6 +10,8 @@ import expo.modules.kotlin.sharedobjects.SharedObject
|
|
|
10
10
|
* The view resolves it and executes the worklet on the UI runtime.
|
|
11
11
|
*/
|
|
12
12
|
class WorkletCallback : SharedObject() {
|
|
13
|
+
override val releasesAfterPendingViewUpdates = true
|
|
14
|
+
|
|
13
15
|
var worklet: Worklet? = null
|
|
14
16
|
|
|
15
17
|
fun invoke(vararg arguments: Any?) {
|