werewolf-ui 0.1.0-beta.2 → 0.1.0-beta.3
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 +9 -5
- package/data/manifest.json +3779 -484
- package/data/native/android/WerewolfAlert.kt +1 -1
- package/data/native/android/WerewolfAlertDialog.kt +156 -0
- package/data/native/android/WerewolfAvatar.kt +393 -0
- package/data/native/android/WerewolfBackdropBlur.kt +89 -0
- package/data/native/android/WerewolfBadge.kt +1 -1
- package/data/native/android/WerewolfBottomNav.kt +333 -0
- package/data/native/android/WerewolfButton.kt +1 -1
- package/data/native/android/WerewolfButtonGroup.kt +54 -0
- package/data/native/android/WerewolfCard.kt +1 -1
- package/data/native/android/WerewolfCheckbox.kt +387 -0
- package/data/native/android/WerewolfCounter.kt +640 -0
- package/data/native/android/WerewolfDialog.kt +131 -0
- package/data/native/android/WerewolfEmptyState.kt +1 -1
- package/data/native/android/WerewolfField.kt +66 -0
- package/data/native/android/WerewolfIcons.kt +39 -1
- package/data/native/android/WerewolfInput.kt +1 -1
- package/data/native/android/WerewolfKbd.kt +1 -1
- package/data/native/android/WerewolfLabel.kt +2 -2
- package/data/native/android/WerewolfLayers.kt +385 -0
- package/data/native/android/WerewolfLink.kt +163 -0
- package/data/native/android/WerewolfList.kt +504 -0
- package/data/native/android/WerewolfListRuntime.kt +384 -0
- package/data/native/android/WerewolfMetadata.kt +180 -0
- package/data/native/android/WerewolfMeter.kt +189 -0
- package/data/native/android/WerewolfModifiers.kt +58 -4
- package/data/native/android/WerewolfProgress.kt +281 -0
- package/data/native/android/WerewolfRadioGroup.kt +382 -0
- package/data/native/android/WerewolfSelect.kt +330 -0
- package/data/native/android/WerewolfSeparator.kt +1 -1
- package/data/native/android/WerewolfSheet.kt +204 -0
- package/data/native/android/WerewolfSkeleton.kt +1 -1
- package/data/native/android/WerewolfSpinner.kt +1 -1
- package/data/native/android/WerewolfSwitch.kt +9 -57
- package/data/native/android/WerewolfTabs.kt +591 -0
- package/data/native/android/WerewolfTextarea.kt +329 -0
- package/data/native/android/WerewolfTheme.kt +3 -2
- package/data/native/android/WerewolfToast.kt +226 -0
- package/data/native/android/WerewolfToaster.kt +282 -0
- package/data/native/android/WerewolfToggle.kt +395 -0
- package/data/native/android/WerewolfToggleGroup.kt +427 -0
- package/data/native/android/WerewolfToken.kt +1 -1
- package/data/native/ios/WerewolfAlert.swift +1 -1
- package/data/native/ios/WerewolfAlertDialog.swift +185 -0
- package/data/native/ios/WerewolfAvatar.swift +552 -0
- package/data/native/ios/WerewolfBadge.swift +1 -1
- package/data/native/ios/WerewolfBottomNav.swift +422 -0
- package/data/native/ios/WerewolfButton.swift +1 -1
- package/data/native/ios/WerewolfButtonGroup.swift +62 -0
- package/data/native/ios/WerewolfCard.swift +1 -1
- package/data/native/ios/WerewolfCheckbox.swift +621 -0
- package/data/native/ios/WerewolfCounter.swift +768 -0
- package/data/native/ios/WerewolfDialog.swift +170 -0
- package/data/native/ios/WerewolfEmptyState.swift +1 -1
- package/data/native/ios/WerewolfField.swift +103 -0
- package/data/native/ios/WerewolfIcons.swift +13 -1
- package/data/native/ios/WerewolfInput.swift +1 -1
- package/data/native/ios/WerewolfKbd.swift +1 -1
- package/data/native/ios/WerewolfLabel.swift +2 -2
- package/data/native/ios/WerewolfLayers.swift +376 -0
- package/data/native/ios/WerewolfLink.swift +188 -0
- package/data/native/ios/WerewolfList.swift +603 -0
- package/data/native/ios/WerewolfListRuntime.swift +414 -0
- package/data/native/ios/WerewolfMetadata.swift +205 -0
- package/data/native/ios/WerewolfMeter.swift +186 -0
- package/data/native/ios/WerewolfModifiers.swift +106 -1
- package/data/native/ios/WerewolfProgress.swift +338 -0
- package/data/native/ios/WerewolfRadioGroup.swift +483 -0
- package/data/native/ios/WerewolfSelect.swift +418 -0
- package/data/native/ios/WerewolfSeparator.swift +1 -1
- package/data/native/ios/WerewolfSheet.swift +208 -0
- package/data/native/ios/WerewolfSkeleton.swift +1 -1
- package/data/native/ios/WerewolfSpinner.swift +1 -1
- package/data/native/ios/WerewolfSwitch.swift +18 -77
- package/data/native/ios/WerewolfTabs.swift +756 -0
- package/data/native/ios/WerewolfTextarea.swift +403 -0
- package/data/native/ios/WerewolfTheme.swift +1 -1
- package/data/native/ios/WerewolfToast.swift +278 -0
- package/data/native/ios/WerewolfToaster.swift +269 -0
- package/data/native/ios/WerewolfToggle.swift +647 -0
- package/data/native/ios/WerewolfToggleGroup.swift +511 -0
- package/data/native/ios/WerewolfToken.swift +1 -1
- package/dist/cli.mjs +2212 -352
- package/dist/core.mjs +2121 -308
- package/dist/lint.mjs +142 -18
- package/dist/project.mjs +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/dialog.spec.json (werewolf-ui 0.1.0-beta.3).
|
|
2
|
+
package dev.werewolfui
|
|
3
|
+
|
|
4
|
+
import androidx.compose.foundation.background
|
|
5
|
+
import androidx.compose.foundation.border
|
|
6
|
+
import androidx.compose.foundation.layout.Arrangement
|
|
7
|
+
import androidx.compose.foundation.layout.Box
|
|
8
|
+
import androidx.compose.foundation.layout.Column
|
|
9
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
10
|
+
import androidx.compose.foundation.layout.padding
|
|
11
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
12
|
+
import androidx.compose.foundation.text.BasicText
|
|
13
|
+
import androidx.compose.runtime.Composable
|
|
14
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
15
|
+
import androidx.compose.ui.Alignment
|
|
16
|
+
import androidx.compose.ui.Modifier
|
|
17
|
+
import androidx.compose.ui.graphics.Color
|
|
18
|
+
import androidx.compose.ui.text.TextStyle
|
|
19
|
+
import androidx.compose.ui.unit.Dp
|
|
20
|
+
import androidx.compose.ui.unit.TextUnit
|
|
21
|
+
import dev.werewolfui.runtime.LocalWerewolf
|
|
22
|
+
import dev.werewolfui.runtime.LocalWerewolfContentColor
|
|
23
|
+
import dev.werewolfui.runtime.LocalWerewolfFonts
|
|
24
|
+
import dev.werewolfui.runtime.WerewolfFontRole
|
|
25
|
+
import dev.werewolfui.runtime.WerewolfLayer
|
|
26
|
+
import dev.werewolfui.runtime.WerewolfPresent
|
|
27
|
+
import dev.werewolfui.runtime.werewolfFontWeight
|
|
28
|
+
import dev.werewolfui.runtime.werewolfShadow
|
|
29
|
+
import dev.werewolfui.tokens.WerewolfShadowLayer
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@Composable
|
|
33
|
+
fun WerewolfDialog(
|
|
34
|
+
open: Boolean,
|
|
35
|
+
onOpenChange: (Boolean) -> Unit,
|
|
36
|
+
title: String,
|
|
37
|
+
modifier: Modifier = Modifier,
|
|
38
|
+
description: String = "",
|
|
39
|
+
content: (@Composable () -> Unit)? = null,
|
|
40
|
+
footer: (@Composable () -> Unit)? = null,
|
|
41
|
+
) {
|
|
42
|
+
WerewolfPresent(
|
|
43
|
+
open = open,
|
|
44
|
+
layer = WerewolfLayer.Dialog,
|
|
45
|
+
title = title,
|
|
46
|
+
onDismissRequest = { onOpenChange(false) },
|
|
47
|
+
dismissOnScrim = true,
|
|
48
|
+
) {
|
|
49
|
+
val t = LocalWerewolf.current
|
|
50
|
+
// werewolf:property=content.background-color
|
|
51
|
+
val contentBackgroundColor = t.colorBackgroundRaised
|
|
52
|
+
// werewolf:property=content.border-color
|
|
53
|
+
val contentBorderColor = t.colorBorder
|
|
54
|
+
// werewolf:property=content.border-radius
|
|
55
|
+
val contentBorderRadius = t.radiusPage
|
|
56
|
+
// werewolf:property=content.border-width
|
|
57
|
+
val contentBorderWidth = t.borderWidth
|
|
58
|
+
// werewolf:property=content.box-shadow
|
|
59
|
+
val contentBoxShadow = t.shadowHigh
|
|
60
|
+
// werewolf:property=content.color
|
|
61
|
+
val contentColor = t.colorTextPrimary
|
|
62
|
+
// werewolf:property=content.font-family
|
|
63
|
+
val contentFontFamily = t.fontFamilySans
|
|
64
|
+
// werewolf:property=content.gap
|
|
65
|
+
val contentGap = t.spacingLg
|
|
66
|
+
// werewolf:property=content.padding
|
|
67
|
+
val contentPadding = t.spacingXl
|
|
68
|
+
// werewolf:property=header.gap
|
|
69
|
+
val headerGap = t.spacingSm
|
|
70
|
+
// werewolf:property=title.color
|
|
71
|
+
val titleColor = t.colorTextPrimary
|
|
72
|
+
// werewolf:property=title.font-size
|
|
73
|
+
val titleFontSize = t.fontSizeMd
|
|
74
|
+
// werewolf:property=title.font-weight
|
|
75
|
+
val titleFontWeight = t.fontWeightMedium
|
|
76
|
+
// werewolf:property=description.color
|
|
77
|
+
val descriptionColor = t.colorTextSecondary
|
|
78
|
+
// werewolf:property=description.font-size
|
|
79
|
+
val descriptionFontSize = t.fontSizeSm
|
|
80
|
+
// werewolf:property=footer.gap
|
|
81
|
+
val footerGap = t.spacingSm
|
|
82
|
+
val contentShape = RoundedCornerShape(contentBorderRadius)
|
|
83
|
+
CompositionLocalProvider(LocalWerewolfContentColor provides contentColor) {
|
|
84
|
+
Column(
|
|
85
|
+
modifier = modifier
|
|
86
|
+
.fillMaxWidth()
|
|
87
|
+
.fillMaxWidth()
|
|
88
|
+
.background(contentBackgroundColor, contentShape)
|
|
89
|
+
.border(contentBorderWidth, contentBorderColor, contentShape)
|
|
90
|
+
.padding(contentPadding)
|
|
91
|
+
.werewolfShadow(contentBoxShadow),
|
|
92
|
+
verticalArrangement = Arrangement.spacedBy(contentGap, Alignment.CenterVertically),
|
|
93
|
+
horizontalAlignment = Alignment.CenterHorizontally,
|
|
94
|
+
) {
|
|
95
|
+
Column(
|
|
96
|
+
verticalArrangement = Arrangement.spacedBy(headerGap, Alignment.CenterVertically),
|
|
97
|
+
horizontalAlignment = Alignment.Start,
|
|
98
|
+
) {
|
|
99
|
+
BasicText(
|
|
100
|
+
text = title,
|
|
101
|
+
style = TextStyle(
|
|
102
|
+
color = titleColor,
|
|
103
|
+
fontSize = titleFontSize,
|
|
104
|
+
fontWeight = werewolfFontWeight(titleFontWeight),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
if (description.isNotEmpty()) {
|
|
108
|
+
BasicText(
|
|
109
|
+
text = description,
|
|
110
|
+
style = TextStyle(
|
|
111
|
+
color = descriptionColor,
|
|
112
|
+
fontSize = descriptionFontSize,
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (content != null) {
|
|
118
|
+
Box(
|
|
119
|
+
) {
|
|
120
|
+
CompositionLocalProvider(LocalWerewolfContentColor provides contentColor) {
|
|
121
|
+
content()
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (footer != null) {
|
|
126
|
+
footer?.invoke()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated file, must not be edited by hand. Source: components/empty-state.spec.json (werewolf-ui 0.1.0-beta.
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/empty-state.spec.json (werewolf-ui 0.1.0-beta.3).
|
|
2
2
|
package dev.werewolfui
|
|
3
3
|
|
|
4
4
|
import androidx.compose.foundation.layout.Arrangement
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/field.spec.json (werewolf-ui 0.1.0-beta.3).
|
|
2
|
+
package dev.werewolfui
|
|
3
|
+
|
|
4
|
+
import androidx.compose.foundation.layout.Arrangement
|
|
5
|
+
import androidx.compose.foundation.layout.Column
|
|
6
|
+
import androidx.compose.runtime.Composable
|
|
7
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
8
|
+
import androidx.compose.ui.Alignment
|
|
9
|
+
import androidx.compose.ui.Modifier
|
|
10
|
+
import androidx.compose.ui.graphics.Color
|
|
11
|
+
import androidx.compose.ui.text.TextStyle
|
|
12
|
+
import androidx.compose.ui.unit.Dp
|
|
13
|
+
import androidx.compose.ui.unit.TextUnit
|
|
14
|
+
import dev.werewolfui.runtime.LocalWerewolf
|
|
15
|
+
import dev.werewolfui.runtime.LocalWerewolfContentColor
|
|
16
|
+
import dev.werewolfui.runtime.LocalWerewolfFonts
|
|
17
|
+
import dev.werewolfui.runtime.LocalWerewolfTextStyle
|
|
18
|
+
import dev.werewolfui.runtime.WerewolfFontRole
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@Composable
|
|
22
|
+
fun WerewolfField(
|
|
23
|
+
modifier: Modifier = Modifier,
|
|
24
|
+
description: (@Composable () -> Unit)? = null,
|
|
25
|
+
error: (@Composable () -> Unit)? = null,
|
|
26
|
+
label: @Composable () -> Unit,
|
|
27
|
+
control: @Composable () -> Unit,
|
|
28
|
+
) {
|
|
29
|
+
val t = LocalWerewolf.current
|
|
30
|
+
// werewolf:property=root.gap
|
|
31
|
+
val rootGap = t.spacingXs
|
|
32
|
+
// werewolf:property=description.color
|
|
33
|
+
val descriptionColor = t.colorTextSecondary
|
|
34
|
+
// werewolf:property=description.font-family
|
|
35
|
+
val descriptionFontFamily = t.fontFamilySans
|
|
36
|
+
// werewolf:property=description.font-size
|
|
37
|
+
val descriptionFontSize = t.fontSizeXs
|
|
38
|
+
// werewolf:property=error.color
|
|
39
|
+
val errorColor = t.colorTextDanger
|
|
40
|
+
// werewolf:property=error.font-family
|
|
41
|
+
val errorFontFamily = t.fontFamilySans
|
|
42
|
+
// werewolf:property=error.font-size
|
|
43
|
+
val errorFontSize = t.fontSizeXs
|
|
44
|
+
// werewolf:property=error.gap
|
|
45
|
+
val errorGap = t.spacingXs
|
|
46
|
+
CompositionLocalProvider(LocalWerewolfContentColor provides descriptionColor) {
|
|
47
|
+
Column(
|
|
48
|
+
modifier = modifier,
|
|
49
|
+
verticalArrangement = Arrangement.spacedBy(rootGap, Alignment.CenterVertically),
|
|
50
|
+
horizontalAlignment = Alignment.Start,
|
|
51
|
+
) {
|
|
52
|
+
label()
|
|
53
|
+
control()
|
|
54
|
+
CompositionLocalProvider(
|
|
55
|
+
LocalWerewolfTextStyle provides TextStyle(color = descriptionColor, fontFamily = LocalWerewolfFonts.current.resolve(when (descriptionFontFamily) { t.fontFamilySans -> WerewolfFontRole.Sans; else -> WerewolfFontRole.Mono }), fontSize = descriptionFontSize),
|
|
56
|
+
) {
|
|
57
|
+
description?.invoke()
|
|
58
|
+
}
|
|
59
|
+
CompositionLocalProvider(
|
|
60
|
+
LocalWerewolfTextStyle provides TextStyle(color = errorColor, fontFamily = LocalWerewolfFonts.current.resolve(when (errorFontFamily) { t.fontFamilySans -> WerewolfFontRole.Sans; else -> WerewolfFontRole.Mono }), fontSize = errorFontSize),
|
|
61
|
+
) {
|
|
62
|
+
error?.invoke()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -11,9 +11,10 @@ import androidx.compose.ui.graphics.vector.PathBuilder
|
|
|
11
11
|
import androidx.compose.ui.graphics.vector.path
|
|
12
12
|
import androidx.compose.ui.unit.dp
|
|
13
13
|
|
|
14
|
-
private fun glyph(name: String, draw: PathBuilder.() -> Unit): ImageVector =
|
|
14
|
+
private fun glyph(name: String, autoMirror: Boolean = false, draw: PathBuilder.() -> Unit): ImageVector =
|
|
15
15
|
ImageVector.Builder(
|
|
16
16
|
name = name,
|
|
17
|
+
autoMirror = autoMirror,
|
|
17
18
|
defaultWidth = 24.dp,
|
|
18
19
|
defaultHeight = 24.dp,
|
|
19
20
|
viewportWidth = 24f,
|
|
@@ -74,6 +75,14 @@ object WerewolfIconDefaults {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
val chevronEnd: ImageVector by lazy {
|
|
79
|
+
glyph("WerewolfChevronEnd", autoMirror = true) {
|
|
80
|
+
moveTo(9f, 6f)
|
|
81
|
+
lineTo(15f, 12f)
|
|
82
|
+
lineTo(9f, 18f)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
val check: ImageVector by lazy {
|
|
78
87
|
glyph("WerewolfCheck") {
|
|
79
88
|
moveTo(5f, 12.5f)
|
|
@@ -81,6 +90,31 @@ object WerewolfIconDefaults {
|
|
|
81
90
|
lineTo(19f, 7f)
|
|
82
91
|
}
|
|
83
92
|
}
|
|
93
|
+
|
|
94
|
+
val minus: ImageVector by lazy {
|
|
95
|
+
glyph("WerewolfMinus") {
|
|
96
|
+
moveTo(5f, 12f)
|
|
97
|
+
lineTo(19f, 12f)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
val plus: ImageVector by lazy {
|
|
102
|
+
glyph("WerewolfPlus") {
|
|
103
|
+
moveTo(5f, 12f)
|
|
104
|
+
lineTo(19f, 12f)
|
|
105
|
+
moveTo(12f, 5f)
|
|
106
|
+
lineTo(12f, 19f)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
val x: ImageVector by lazy {
|
|
111
|
+
glyph("WerewolfX") {
|
|
112
|
+
moveTo(6f, 6f)
|
|
113
|
+
lineTo(18f, 18f)
|
|
114
|
+
moveTo(18f, 6f)
|
|
115
|
+
lineTo(6f, 18f)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
84
118
|
}
|
|
85
119
|
|
|
86
120
|
class WerewolfIcons(
|
|
@@ -88,7 +122,11 @@ class WerewolfIcons(
|
|
|
88
122
|
val eye: ImageVector = WerewolfIconDefaults.eye,
|
|
89
123
|
val eyeOff: ImageVector = WerewolfIconDefaults.eyeOff,
|
|
90
124
|
val chevronDown: ImageVector = WerewolfIconDefaults.chevronDown,
|
|
125
|
+
val chevronEnd: ImageVector = WerewolfIconDefaults.chevronEnd,
|
|
91
126
|
val check: ImageVector = WerewolfIconDefaults.check,
|
|
127
|
+
val minus: ImageVector = WerewolfIconDefaults.minus,
|
|
128
|
+
val plus: ImageVector = WerewolfIconDefaults.plus,
|
|
129
|
+
val x: ImageVector = WerewolfIconDefaults.x,
|
|
92
130
|
)
|
|
93
131
|
|
|
94
132
|
val LocalWerewolfIcons = staticCompositionLocalOf { WerewolfIcons() }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated file, must not be edited by hand. Source: components/input.spec.json (werewolf-ui 0.1.0-beta.
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/input.spec.json (werewolf-ui 0.1.0-beta.3).
|
|
2
2
|
package dev.werewolfui
|
|
3
3
|
|
|
4
4
|
import androidx.compose.animation.animateColorAsState
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated file, must not be edited by hand. Source: components/kbd.spec.json (werewolf-ui 0.1.0-beta.
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/kbd.spec.json (werewolf-ui 0.1.0-beta.3).
|
|
2
2
|
package dev.werewolfui
|
|
3
3
|
|
|
4
4
|
import androidx.compose.foundation.background
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated file, must not be edited by hand. Source: components/label.spec.json (werewolf-ui 0.1.0-beta.
|
|
1
|
+
// Generated file, must not be edited by hand. Source: components/label.spec.json (werewolf-ui 0.1.0-beta.3).
|
|
2
2
|
package dev.werewolfui
|
|
3
3
|
|
|
4
4
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
@@ -56,7 +56,7 @@ fun WerewolfLabel(
|
|
|
56
56
|
return@run t.colorTextDisabled
|
|
57
57
|
}
|
|
58
58
|
// werewolf:state=default
|
|
59
|
-
t.
|
|
59
|
+
t.colorTextSecondary
|
|
60
60
|
}
|
|
61
61
|
// werewolf:property=root.font-family
|
|
62
62
|
val rootFontFamily = t.fontFamilySans
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// Werewolf native runtime. Hand-written, independent of the seed.
|
|
2
|
+
package dev.werewolfui.runtime
|
|
3
|
+
|
|
4
|
+
import androidx.activity.compose.BackHandler
|
|
5
|
+
import androidx.compose.animation.core.Animatable
|
|
6
|
+
import androidx.compose.animation.core.AnimationSpec
|
|
7
|
+
import androidx.compose.animation.core.AnimationVector1D
|
|
8
|
+
import androidx.compose.animation.core.animateFloatAsState
|
|
9
|
+
import androidx.compose.animation.core.tween
|
|
10
|
+
import androidx.compose.foundation.background
|
|
11
|
+
import androidx.compose.foundation.clickable
|
|
12
|
+
import androidx.compose.foundation.gestures.detectTapGestures
|
|
13
|
+
import androidx.compose.foundation.gestures.detectVerticalDragGestures
|
|
14
|
+
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
15
|
+
import androidx.compose.foundation.layout.Box
|
|
16
|
+
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
17
|
+
import androidx.compose.foundation.layout.Column
|
|
18
|
+
import androidx.compose.foundation.layout.Spacer
|
|
19
|
+
import androidx.compose.foundation.layout.WindowInsets
|
|
20
|
+
import androidx.compose.foundation.layout.fillMaxHeight
|
|
21
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
22
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
23
|
+
import androidx.compose.foundation.layout.heightIn
|
|
24
|
+
import androidx.compose.foundation.layout.ime
|
|
25
|
+
import androidx.compose.foundation.layout.navigationBars
|
|
26
|
+
import androidx.compose.foundation.layout.padding
|
|
27
|
+
import androidx.compose.foundation.layout.union
|
|
28
|
+
import androidx.compose.foundation.layout.widthIn
|
|
29
|
+
import androidx.compose.foundation.layout.windowInsetsBottomHeight
|
|
30
|
+
import androidx.compose.runtime.Composable
|
|
31
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
32
|
+
import androidx.compose.runtime.DisposableEffect
|
|
33
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
34
|
+
import androidx.compose.runtime.State
|
|
35
|
+
import androidx.compose.runtime.compositionLocalOf
|
|
36
|
+
import androidx.compose.runtime.getValue
|
|
37
|
+
import androidx.compose.runtime.key
|
|
38
|
+
import androidx.compose.runtime.mutableStateListOf
|
|
39
|
+
import androidx.compose.runtime.mutableStateOf
|
|
40
|
+
import androidx.compose.runtime.remember
|
|
41
|
+
import androidx.compose.runtime.rememberCoroutineScope
|
|
42
|
+
import androidx.compose.runtime.rememberUpdatedState
|
|
43
|
+
import androidx.compose.runtime.setValue
|
|
44
|
+
import androidx.compose.runtime.staticCompositionLocalOf
|
|
45
|
+
import androidx.compose.ui.Alignment
|
|
46
|
+
import androidx.compose.ui.Modifier
|
|
47
|
+
import androidx.compose.ui.graphics.graphicsLayer
|
|
48
|
+
import androidx.compose.ui.input.pointer.pointerInput
|
|
49
|
+
import androidx.compose.ui.input.pointer.util.VelocityTracker
|
|
50
|
+
import androidx.compose.ui.layout.onSizeChanged
|
|
51
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
52
|
+
import androidx.compose.ui.semantics.clearAndSetSemantics
|
|
53
|
+
import androidx.compose.ui.semantics.dismiss
|
|
54
|
+
import androidx.compose.ui.semantics.isTraversalGroup
|
|
55
|
+
import androidx.compose.ui.semantics.paneTitle
|
|
56
|
+
import androidx.compose.ui.semantics.semantics
|
|
57
|
+
import androidx.compose.ui.unit.Dp
|
|
58
|
+
import androidx.compose.ui.unit.dp
|
|
59
|
+
import dev.werewolfui.tokens.WerewolfTokens
|
|
60
|
+
import kotlinx.coroutines.delay
|
|
61
|
+
import kotlinx.coroutines.launch
|
|
62
|
+
|
|
63
|
+
enum class WerewolfLayer {
|
|
64
|
+
Sheet,
|
|
65
|
+
Dialog,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
object WerewolfLayerOrder {
|
|
69
|
+
const val Sheet = 0
|
|
70
|
+
const val Dialog = 1
|
|
71
|
+
const val Toast = 2
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
enum class WerewolfDetent(val fraction: Float) {
|
|
75
|
+
Sm(1f / 3f),
|
|
76
|
+
Md(1f / 2f),
|
|
77
|
+
Lg(3f / 4f),
|
|
78
|
+
Full(1f),
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
enum class WerewolfLayerSurface {
|
|
82
|
+
Scrim,
|
|
83
|
+
Sheet,
|
|
84
|
+
Dialog,
|
|
85
|
+
Toast,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
object WerewolfLayerMotion {
|
|
89
|
+
const val DialogScale = 0.95f
|
|
90
|
+
|
|
91
|
+
fun enterMillis(surface: WerewolfLayerSurface, theme: WerewolfTokens): Int = when (surface) {
|
|
92
|
+
WerewolfLayerSurface.Scrim, WerewolfLayerSurface.Sheet, WerewolfLayerSurface.Dialog -> theme.durationSlowMs
|
|
93
|
+
WerewolfLayerSurface.Toast -> theme.durationMediumMs
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fun exitMillis(surface: WerewolfLayerSurface, theme: WerewolfTokens): Int = when (surface) {
|
|
97
|
+
WerewolfLayerSurface.Scrim, WerewolfLayerSurface.Dialog -> theme.durationFastMs
|
|
98
|
+
WerewolfLayerSurface.Sheet, WerewolfLayerSurface.Toast -> theme.durationMediumMs
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fun hiddenScale(surface: WerewolfLayerSurface, reduced: Boolean): Float {
|
|
102
|
+
if (reduced) return 1f
|
|
103
|
+
return if (surface == WerewolfLayerSurface.Dialog) DialogScale else 1f
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fun hiddenOffsetFraction(surface: WerewolfLayerSurface, reduced: Boolean): Float {
|
|
107
|
+
if (reduced) return 0f
|
|
108
|
+
return if (surface == WerewolfLayerSurface.Sheet || surface == WerewolfLayerSurface.Toast) 1f else 0f
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fun spec(surface: WerewolfLayerSurface, shown: Boolean, theme: WerewolfTokens): AnimationSpec<Float> {
|
|
112
|
+
val easing = if (shown) theme.easeEnter else theme.easeExit
|
|
113
|
+
val millis = if (shown) enterMillis(surface, theme) else exitMillis(surface, theme)
|
|
114
|
+
return tween(durationMillis = millis, easing = easing.toCubicBezierEasing())
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
object WerewolfSheetDismiss {
|
|
119
|
+
const val HeightFraction = 0.25f
|
|
120
|
+
val Distance = 80.dp
|
|
121
|
+
val Velocity = 500.dp
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
val LocalWerewolfBottomInset = compositionLocalOf { 0.dp }
|
|
125
|
+
|
|
126
|
+
val LocalWerewolfBottomInsetReporter = compositionLocalOf<(Dp) -> Unit> { { } }
|
|
127
|
+
|
|
128
|
+
internal class WerewolfLayerSpec(
|
|
129
|
+
val layer: WerewolfLayer,
|
|
130
|
+
val title: String,
|
|
131
|
+
val detent: WerewolfDetent,
|
|
132
|
+
val dismissOnScrim: Boolean,
|
|
133
|
+
val swipeToDismiss: Boolean,
|
|
134
|
+
val dismissLabel: String,
|
|
135
|
+
val onDismissRequest: () -> Unit,
|
|
136
|
+
val content: @Composable () -> Unit,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
internal class WerewolfLayerEntry(val id: Long, val spec: State<WerewolfLayerSpec>) {
|
|
140
|
+
var closing by mutableStateOf(false)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
internal class WerewolfLayerCenter {
|
|
144
|
+
val entries = mutableStateListOf<WerewolfLayerEntry>()
|
|
145
|
+
private var next = 0L
|
|
146
|
+
|
|
147
|
+
val hasModal: Boolean get() = entries.any { !it.closing }
|
|
148
|
+
|
|
149
|
+
fun open(spec: State<WerewolfLayerSpec>): WerewolfLayerEntry {
|
|
150
|
+
val entry = WerewolfLayerEntry(next++, spec)
|
|
151
|
+
entries.add(entry)
|
|
152
|
+
return entry
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
fun close(entry: WerewolfLayerEntry) {
|
|
156
|
+
entry.closing = true
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fun remove(entry: WerewolfLayerEntry) {
|
|
160
|
+
entries.remove(entry)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
internal val LocalWerewolfLayerCenter = staticCompositionLocalOf<WerewolfLayerCenter?> { null }
|
|
165
|
+
|
|
166
|
+
@Composable
|
|
167
|
+
fun WerewolfLayerHost(content: @Composable () -> Unit) {
|
|
168
|
+
val center = remember { WerewolfLayerCenter() }
|
|
169
|
+
val toaster = remember { WerewolfToaster() }
|
|
170
|
+
var reported by remember { mutableStateOf(0.dp) }
|
|
171
|
+
CompositionLocalProvider(
|
|
172
|
+
LocalWerewolfLayerCenter provides center,
|
|
173
|
+
LocalWerewolfToaster provides toaster,
|
|
174
|
+
LocalWerewolfBottomInsetReporter provides { reported = it },
|
|
175
|
+
) {
|
|
176
|
+
Box(Modifier.fillMaxSize()) {
|
|
177
|
+
Box(
|
|
178
|
+
Modifier
|
|
179
|
+
.fillMaxSize()
|
|
180
|
+
.then(if (center.hasModal) Modifier.clearAndSetSemantics { } else Modifier),
|
|
181
|
+
) {
|
|
182
|
+
WerewolfBackdropSource(content)
|
|
183
|
+
}
|
|
184
|
+
for (entry in center.entries) {
|
|
185
|
+
key(entry.id) { WerewolfLayerView(entry, center) }
|
|
186
|
+
}
|
|
187
|
+
WerewolfToastHost(toaster, reported)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Composable
|
|
193
|
+
fun WerewolfPresent(
|
|
194
|
+
open: Boolean,
|
|
195
|
+
layer: WerewolfLayer,
|
|
196
|
+
title: String,
|
|
197
|
+
onDismissRequest: () -> Unit,
|
|
198
|
+
detent: WerewolfDetent = WerewolfDetent.Md,
|
|
199
|
+
dismissOnScrim: Boolean = true,
|
|
200
|
+
swipeToDismiss: Boolean = true,
|
|
201
|
+
dismissLabel: String = "Close",
|
|
202
|
+
content: @Composable () -> Unit,
|
|
203
|
+
) {
|
|
204
|
+
val center = LocalWerewolfLayerCenter.current
|
|
205
|
+
?: error("WerewolfPresent needs WerewolfTheme or WerewolfLayerHost above it.")
|
|
206
|
+
val spec = rememberUpdatedState(
|
|
207
|
+
WerewolfLayerSpec(layer, title, detent, dismissOnScrim, swipeToDismiss, dismissLabel, onDismissRequest, content),
|
|
208
|
+
)
|
|
209
|
+
DisposableEffect(open) {
|
|
210
|
+
val entry = if (open) center.open(spec) else null
|
|
211
|
+
onDispose { entry?.let { center.close(it) } }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@Composable
|
|
216
|
+
private fun WerewolfLayerView(entry: WerewolfLayerEntry, center: WerewolfLayerCenter) {
|
|
217
|
+
val theme = LocalWerewolf.current
|
|
218
|
+
val spec = entry.spec.value
|
|
219
|
+
val reduced = rememberReduceMotion()
|
|
220
|
+
var appeared by remember { mutableStateOf(false) }
|
|
221
|
+
LaunchedEffect(Unit) { appeared = true }
|
|
222
|
+
val shown = appeared && !entry.closing
|
|
223
|
+
val surface = if (spec.layer == WerewolfLayer.Sheet) WerewolfLayerSurface.Sheet else WerewolfLayerSurface.Dialog
|
|
224
|
+
val dragged = remember { Animatable(0f) }
|
|
225
|
+
var sheetHeight by remember { mutableStateOf(0) }
|
|
226
|
+
|
|
227
|
+
LaunchedEffect(entry.closing) {
|
|
228
|
+
if (entry.closing) {
|
|
229
|
+
val millis = maxOf(
|
|
230
|
+
WerewolfLayerMotion.exitMillis(WerewolfLayerSurface.Scrim, theme),
|
|
231
|
+
WerewolfLayerMotion.exitMillis(surface, theme),
|
|
232
|
+
)
|
|
233
|
+
delay(millis.toLong())
|
|
234
|
+
center.remove(entry)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
BackHandler(enabled = !entry.closing) { spec.onDismissRequest() }
|
|
239
|
+
|
|
240
|
+
val scrimProgress by animateFloatAsState(
|
|
241
|
+
targetValue = if (shown) 1f else 0f,
|
|
242
|
+
animationSpec = WerewolfLayerMotion.spec(WerewolfLayerSurface.Scrim, shown, theme),
|
|
243
|
+
label = "werewolfScrim",
|
|
244
|
+
)
|
|
245
|
+
val progress by animateFloatAsState(
|
|
246
|
+
targetValue = if (shown) 1f else 0f,
|
|
247
|
+
animationSpec = WerewolfLayerMotion.spec(surface, shown, theme),
|
|
248
|
+
label = "werewolfLayer",
|
|
249
|
+
)
|
|
250
|
+
val dragFade = if (sheetHeight > 0) (1f - dragged.value / sheetHeight).coerceIn(0f, 1f) else 1f
|
|
251
|
+
val hiddenOffset = WerewolfLayerMotion.hiddenOffsetFraction(surface, reduced)
|
|
252
|
+
val hiddenScale = WerewolfLayerMotion.hiddenScale(surface, reduced)
|
|
253
|
+
|
|
254
|
+
Box(Modifier.fillMaxSize()) {
|
|
255
|
+
Box(
|
|
256
|
+
Modifier
|
|
257
|
+
.fillMaxSize()
|
|
258
|
+
.graphicsLayer { alpha = scrimProgress * dragFade }
|
|
259
|
+
.background(theme.colorOverlayScrim)
|
|
260
|
+
.clickable(
|
|
261
|
+
interactionSource = remember { MutableInteractionSource() },
|
|
262
|
+
indication = null,
|
|
263
|
+
onClickLabel = if (spec.dismissOnScrim) spec.dismissLabel else null,
|
|
264
|
+
) { if (spec.dismissOnScrim) spec.onDismissRequest() },
|
|
265
|
+
)
|
|
266
|
+
if (spec.layer == WerewolfLayer.Sheet) {
|
|
267
|
+
WerewolfSheetSurface(
|
|
268
|
+
spec = spec,
|
|
269
|
+
dragged = dragged,
|
|
270
|
+
progress = progress,
|
|
271
|
+
hiddenOffset = hiddenOffset,
|
|
272
|
+
reduced = reduced,
|
|
273
|
+
onHeight = { sheetHeight = it },
|
|
274
|
+
)
|
|
275
|
+
} else {
|
|
276
|
+
Box(
|
|
277
|
+
Modifier
|
|
278
|
+
.fillMaxSize()
|
|
279
|
+
.padding(horizontal = theme.spacingLg),
|
|
280
|
+
contentAlignment = Alignment.Center,
|
|
281
|
+
) {
|
|
282
|
+
Box(
|
|
283
|
+
Modifier
|
|
284
|
+
.widthIn(max = theme.sizePanelLg)
|
|
285
|
+
.graphicsLayer {
|
|
286
|
+
alpha = progress
|
|
287
|
+
val scale = hiddenScale + (1f - hiddenScale) * progress
|
|
288
|
+
scaleX = scale
|
|
289
|
+
scaleY = scale
|
|
290
|
+
}
|
|
291
|
+
.pointerInput(Unit) { detectTapGestures { } }
|
|
292
|
+
.semantics {
|
|
293
|
+
paneTitle = spec.title
|
|
294
|
+
isTraversalGroup = true
|
|
295
|
+
dismiss { spec.onDismissRequest(); true }
|
|
296
|
+
},
|
|
297
|
+
) {
|
|
298
|
+
spec.content()
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
@Composable
|
|
306
|
+
private fun WerewolfSheetSurface(
|
|
307
|
+
spec: WerewolfLayerSpec,
|
|
308
|
+
dragged: Animatable<Float, AnimationVector1D>,
|
|
309
|
+
progress: Float,
|
|
310
|
+
hiddenOffset: Float,
|
|
311
|
+
reduced: Boolean,
|
|
312
|
+
onHeight: (Int) -> Unit,
|
|
313
|
+
) {
|
|
314
|
+
val theme = LocalWerewolf.current
|
|
315
|
+
val scope = rememberCoroutineScope()
|
|
316
|
+
val tracker = remember { VelocityTracker() }
|
|
317
|
+
var height by remember { mutableStateOf(0) }
|
|
318
|
+
val distancePx = with(LocalDensity.current) { WerewolfSheetDismiss.Distance.toPx() }
|
|
319
|
+
val velocityPx = with(LocalDensity.current) { WerewolfSheetDismiss.Velocity.toPx() }
|
|
320
|
+
val inset = WindowInsets.navigationBars.union(WindowInsets.ime)
|
|
321
|
+
val full = spec.detent == WerewolfDetent.Full
|
|
322
|
+
|
|
323
|
+
BoxWithConstraints(Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
|
|
324
|
+
val cap = if (full) maxHeight else maxHeight * spec.detent.fraction
|
|
325
|
+
Column(
|
|
326
|
+
Modifier
|
|
327
|
+
.fillMaxWidth()
|
|
328
|
+
.then(if (full) Modifier.fillMaxHeight() else Modifier.heightIn(max = cap))
|
|
329
|
+
.onSizeChanged {
|
|
330
|
+
height = it.height
|
|
331
|
+
onHeight(it.height)
|
|
332
|
+
}
|
|
333
|
+
.graphicsLayer {
|
|
334
|
+
alpha = progress
|
|
335
|
+
translationY = dragged.value + (1f - progress) * hiddenOffset * height
|
|
336
|
+
}
|
|
337
|
+
.pointerInput(spec.swipeToDismiss) {
|
|
338
|
+
detectTapGestures { }
|
|
339
|
+
}
|
|
340
|
+
.pointerInput(spec.swipeToDismiss) {
|
|
341
|
+
if (!spec.swipeToDismiss) return@pointerInput
|
|
342
|
+
detectVerticalDragGestures(
|
|
343
|
+
onDragStart = { tracker.resetTracking() },
|
|
344
|
+
onDragEnd = {
|
|
345
|
+
val velocity = tracker.calculateVelocity().y
|
|
346
|
+
val offset = dragged.value
|
|
347
|
+
val closes = offset >= WerewolfSheetDismiss.HeightFraction * height ||
|
|
348
|
+
offset >= distancePx ||
|
|
349
|
+
velocity >= velocityPx
|
|
350
|
+
scope.launch {
|
|
351
|
+
if (closes) {
|
|
352
|
+
spec.onDismissRequest()
|
|
353
|
+
} else if (reduced) {
|
|
354
|
+
dragged.snapTo(0f)
|
|
355
|
+
} else {
|
|
356
|
+
dragged.animateTo(
|
|
357
|
+
0f,
|
|
358
|
+
tween(durationMillis = theme.durationMediumMs, easing = theme.easeStandard.toCubicBezierEasing()),
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
onDragCancel = { scope.launch { dragged.snapTo(0f) } },
|
|
364
|
+
onVerticalDrag = { change, amount ->
|
|
365
|
+
tracker.addPosition(change.uptimeMillis, change.position)
|
|
366
|
+
scope.launch { dragged.snapTo((dragged.value + amount).coerceAtLeast(0f)) }
|
|
367
|
+
},
|
|
368
|
+
)
|
|
369
|
+
}
|
|
370
|
+
.semantics {
|
|
371
|
+
paneTitle = spec.title
|
|
372
|
+
isTraversalGroup = true
|
|
373
|
+
dismiss { spec.onDismissRequest(); true }
|
|
374
|
+
},
|
|
375
|
+
) {
|
|
376
|
+
Box(Modifier.weight(1f, fill = full)) { spec.content() }
|
|
377
|
+
Spacer(
|
|
378
|
+
Modifier
|
|
379
|
+
.fillMaxWidth()
|
|
380
|
+
.windowInsetsBottomHeight(inset)
|
|
381
|
+
.background(theme.colorBackgroundRaised),
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|