@momo-kits/native-kits 0.113.3-beta.6 → 0.113.3-pu.1
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/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +25 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +1 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +38 -99
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +33 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +7 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +9 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +8 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +24 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +1 -1
- package/ios/Application/ApplicationEnvironment.swift +11 -3
- package/ios/Application/Components.swift +1 -3
- package/ios/Application/HeaderRight.swift +27 -22
- package/ios/Application/Screen.swift +1 -1
- package/ios/Popup/PopupDisplay.swift +2 -2
- package/ios/Swipeable/SwipeCell.swift +39 -31
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
package vn.momo.kits.application
|
|
2
|
+
|
|
3
|
+
import androidx.compose.foundation.background
|
|
4
|
+
import androidx.compose.foundation.layout.Box
|
|
5
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
6
|
+
import androidx.compose.foundation.layout.height
|
|
7
|
+
import androidx.compose.foundation.layout.offset
|
|
8
|
+
import androidx.compose.foundation.layout.padding
|
|
9
|
+
import androidx.compose.foundation.layout.width
|
|
10
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
11
|
+
import androidx.compose.runtime.Composable
|
|
12
|
+
import androidx.compose.ui.Modifier
|
|
13
|
+
import androidx.compose.ui.graphics.Color
|
|
14
|
+
import androidx.compose.ui.unit.dp
|
|
15
|
+
import androidx.compose.ui.zIndex
|
|
16
|
+
import vn.momo.kits.components.InputSearch
|
|
17
|
+
import vn.momo.kits.components.InputSearchProps
|
|
18
|
+
import vn.momo.kits.const.Radius
|
|
19
|
+
import vn.momo.kits.const.Spacing
|
|
20
|
+
|
|
21
|
+
@Composable
|
|
22
|
+
fun AnimationSearchInput(
|
|
23
|
+
animations: HeaderAnimations,
|
|
24
|
+
inputSearchProps: InputSearchProps
|
|
25
|
+
) {
|
|
26
|
+
Box(
|
|
27
|
+
modifier = Modifier
|
|
28
|
+
.fillMaxWidth()
|
|
29
|
+
.offset(
|
|
30
|
+
x = animations.translateX.dp,
|
|
31
|
+
y = animations.translateY.dp
|
|
32
|
+
)
|
|
33
|
+
) {
|
|
34
|
+
Box(
|
|
35
|
+
modifier = Modifier
|
|
36
|
+
.height(HEADER_HEIGHT.dp)
|
|
37
|
+
.padding(vertical = Spacing.S)
|
|
38
|
+
.zIndex(1f)
|
|
39
|
+
) {
|
|
40
|
+
Box(
|
|
41
|
+
modifier = Modifier
|
|
42
|
+
.width(animations.width.dp)
|
|
43
|
+
.background(
|
|
44
|
+
color = animations.backgroundSearch,
|
|
45
|
+
shape = RoundedCornerShape(Radius.XL)
|
|
46
|
+
)
|
|
47
|
+
) {
|
|
48
|
+
InputSearch(
|
|
49
|
+
inputSearchProps = inputSearchProps.copy(
|
|
50
|
+
showButtonText = false,
|
|
51
|
+
backgroundColor = Color.Transparent
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
@@ -26,6 +26,7 @@ import androidx.compose.ui.Modifier
|
|
|
26
26
|
import androidx.compose.ui.graphics.graphicsLayer
|
|
27
27
|
import androidx.compose.ui.semantics.semantics
|
|
28
28
|
import androidx.compose.ui.semantics.testTag
|
|
29
|
+
import androidx.compose.ui.unit.Dp
|
|
29
30
|
import androidx.compose.ui.unit.dp
|
|
30
31
|
import androidx.compose.ui.zIndex
|
|
31
32
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
@@ -47,10 +48,11 @@ fun Header(
|
|
|
47
48
|
title: String,
|
|
48
49
|
headerRight: @Composable (() -> Unit)? = null,
|
|
49
50
|
goBack: (() -> Unit)? = null,
|
|
50
|
-
opacity: Float
|
|
51
|
+
opacity: Float = 1f,
|
|
51
52
|
animatedHeader: AnimatedHeader? = null,
|
|
52
53
|
scrollState: Int = 0,
|
|
53
54
|
inputSearchProps: InputSearchProps? = null,
|
|
55
|
+
headerRightWidth: Dp = 0.dp,
|
|
54
56
|
useAnimationSearch: Boolean = false
|
|
55
57
|
) {
|
|
56
58
|
val statusBarHeight = AppStatusBar.current ?: getStatusBarHeight()
|
|
@@ -65,6 +67,12 @@ fun Header(
|
|
|
65
67
|
.distinctUntilChanged()
|
|
66
68
|
.collect { fraction -> colorFraction = fraction }
|
|
67
69
|
}
|
|
70
|
+
val animations = useHeaderSearchAnimation(
|
|
71
|
+
opacityAni = opacity,
|
|
72
|
+
scrollState = scrollState,
|
|
73
|
+
headerRightWidth = headerRightWidth,
|
|
74
|
+
isBack = goBack != null
|
|
75
|
+
)
|
|
68
76
|
|
|
69
77
|
val backgroundSearch = animateColor(
|
|
70
78
|
Colors.black_01,
|
|
@@ -72,15 +80,18 @@ fun Header(
|
|
|
72
80
|
colorFraction
|
|
73
81
|
)
|
|
74
82
|
|
|
83
|
+
val searchAnimationEnable =
|
|
84
|
+
inputSearchProps != null && useAnimationSearch && headerType == HeaderType.EXTENDED
|
|
85
|
+
|
|
75
86
|
if (headerType != HeaderType.NONE) {
|
|
76
87
|
BoxWithConstraints(
|
|
77
|
-
Modifier.height(statusBarHeight +
|
|
88
|
+
Modifier.height(statusBarHeight + HEADER_HEIGHT.dp)
|
|
78
89
|
.fillMaxWidth()
|
|
79
90
|
.zIndex(10f),
|
|
80
91
|
contentAlignment = Alignment.BottomCenter
|
|
81
92
|
) {
|
|
82
93
|
Row(
|
|
83
|
-
modifier = Modifier.height(
|
|
94
|
+
modifier = Modifier.height(HEADER_HEIGHT.dp)
|
|
84
95
|
.fillMaxWidth()
|
|
85
96
|
.padding(horizontal = Spacing.M),
|
|
86
97
|
verticalAlignment = Alignment.CenterVertically,
|
|
@@ -120,7 +131,7 @@ fun Header(
|
|
|
120
131
|
|
|
121
132
|
if (useAnimationSearch || inputSearchProps == null) {
|
|
122
133
|
Box(Modifier.graphicsLayer {
|
|
123
|
-
alpha = if (animatedHeader !== null) opacity
|
|
134
|
+
alpha = if (animatedHeader !== null) opacity else 1f
|
|
124
135
|
}) {
|
|
125
136
|
headerRight?.invoke()
|
|
126
137
|
}
|
|
@@ -129,7 +140,7 @@ fun Header(
|
|
|
129
140
|
|
|
130
141
|
// Title
|
|
131
142
|
Row(
|
|
132
|
-
modifier = Modifier.height(
|
|
143
|
+
modifier = Modifier.height(HEADER_HEIGHT.dp)
|
|
133
144
|
.fillMaxWidth()
|
|
134
145
|
.padding(horizontal = Spacing.M),
|
|
135
146
|
verticalAlignment = Alignment.CenterVertically,
|
|
@@ -143,9 +154,9 @@ fun Header(
|
|
|
143
154
|
Box(
|
|
144
155
|
Modifier.weight(1f).graphicsLayer {
|
|
145
156
|
alpha = if (useAnimationSearch) {
|
|
146
|
-
1f - (opacity
|
|
157
|
+
1f - (opacity)
|
|
147
158
|
} else {
|
|
148
|
-
if (animatedHeader !== null) opacity
|
|
159
|
+
if (animatedHeader !== null) opacity else 1f
|
|
149
160
|
}
|
|
150
161
|
},
|
|
151
162
|
contentAlignment = if (titlePosition == TitlePosition.LEFT) Alignment.TopStart else Alignment.Center
|
|
@@ -161,6 +172,13 @@ fun Header(
|
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
174
|
}
|
|
175
|
+
|
|
176
|
+
if (searchAnimationEnable) {
|
|
177
|
+
AnimationSearchInput(
|
|
178
|
+
animations = animations,
|
|
179
|
+
inputSearchProps = inputSearchProps!!
|
|
180
|
+
)
|
|
181
|
+
}
|
|
164
182
|
}
|
|
165
183
|
}
|
|
166
184
|
}
|
|
@@ -8,9 +8,6 @@ import androidx.compose.runtime.Composable
|
|
|
8
8
|
import androidx.compose.runtime.getValue
|
|
9
9
|
import androidx.compose.ui.Modifier
|
|
10
10
|
import androidx.compose.ui.graphics.Color
|
|
11
|
-
import androidx.compose.ui.unit.Dp
|
|
12
|
-
import androidx.compose.ui.unit.dp
|
|
13
|
-
import vn.momo.kits.components.InputSearchProps
|
|
14
11
|
import vn.momo.kits.const.AppStatusBar
|
|
15
12
|
import vn.momo.kits.const.AppTheme
|
|
16
13
|
import vn.momo.kits.platform.getStatusBarHeight
|
|
@@ -35,17 +32,13 @@ fun animateColor(start: Color, stop: Color, fraction: Float): Color {
|
|
|
35
32
|
|
|
36
33
|
@Composable
|
|
37
34
|
fun HeaderBackground(
|
|
38
|
-
isBack: Boolean = true,
|
|
39
35
|
headerType: HeaderType = HeaderType.DEFAULT,
|
|
40
36
|
scrollState: Int,
|
|
41
|
-
inputSearchProps: InputSearchProps? = null,
|
|
42
|
-
headerRightWidth: Dp = 0.dp,
|
|
43
|
-
useAnimationSearch: Boolean = false
|
|
44
37
|
) {
|
|
45
38
|
val statusBarHeight = AppStatusBar.current ?: getStatusBarHeight()
|
|
46
39
|
|
|
47
40
|
val opacityAni by animateFloatAsState(
|
|
48
|
-
targetValue = (1 - (scrollState /
|
|
41
|
+
targetValue = (1 - (scrollState / HEADER_HEIGHT*1f)).coerceIn(0f, 1f),
|
|
49
42
|
)
|
|
50
43
|
|
|
51
44
|
val backgroundColor by animateColorAsState(
|
|
@@ -66,12 +59,7 @@ fun HeaderBackground(
|
|
|
66
59
|
|
|
67
60
|
HeaderType.EXTENDED -> {
|
|
68
61
|
HeaderExtended(
|
|
69
|
-
scrollState = scrollState,
|
|
70
|
-
inputSearchProps = inputSearchProps,
|
|
71
|
-
headerRightWidth = headerRightWidth,
|
|
72
|
-
useAnimationSearch = useAnimationSearch,
|
|
73
62
|
opacityAni = opacityAni,
|
|
74
|
-
isBack = isBack,
|
|
75
63
|
statusBarHeight = statusBarHeight,
|
|
76
64
|
backgroundColor = backgroundColor,
|
|
77
65
|
)
|
|
@@ -24,7 +24,7 @@ fun HeaderDefault(
|
|
|
24
24
|
opacityAni: Float,
|
|
25
25
|
statusBarHeight: Dp,
|
|
26
26
|
) {
|
|
27
|
-
val height = statusBarHeight +
|
|
27
|
+
val height = statusBarHeight + HEADER_HEIGHT.dp
|
|
28
28
|
Box(
|
|
29
29
|
modifier = Modifier.fillMaxWidth().height(height)
|
|
30
30
|
.background(AppTheme.current.colors.background.surface)
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
package vn.momo.kits.application
|
|
2
2
|
|
|
3
|
-
import androidx.compose.animation.animateColorAsState
|
|
4
|
-
import androidx.compose.animation.core.animateFloatAsState
|
|
5
3
|
import androidx.compose.foundation.background
|
|
6
4
|
import androidx.compose.foundation.layout.Box
|
|
7
5
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
8
6
|
import androidx.compose.foundation.layout.height
|
|
9
|
-
import androidx.compose.foundation.layout.offset
|
|
10
|
-
import androidx.compose.foundation.layout.padding
|
|
11
|
-
import androidx.compose.foundation.layout.width
|
|
12
|
-
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
13
7
|
import androidx.compose.runtime.Composable
|
|
14
|
-
import androidx.compose.runtime.getValue
|
|
15
|
-
import androidx.compose.ui.Alignment
|
|
16
8
|
import androidx.compose.ui.Modifier
|
|
17
9
|
import androidx.compose.ui.draw.alpha
|
|
18
10
|
import androidx.compose.ui.geometry.Offset
|
|
@@ -22,115 +14,62 @@ import androidx.compose.ui.layout.ContentScale
|
|
|
22
14
|
import androidx.compose.ui.platform.LocalDensity
|
|
23
15
|
import androidx.compose.ui.unit.Dp
|
|
24
16
|
import androidx.compose.ui.unit.dp
|
|
25
|
-
import androidx.compose.ui.zIndex
|
|
26
17
|
import vn.momo.kits.components.Image
|
|
27
|
-
import vn.momo.kits.components.InputSearch
|
|
28
|
-
import vn.momo.kits.components.InputSearchProps
|
|
29
18
|
import vn.momo.kits.components.Options
|
|
30
19
|
import vn.momo.kits.const.AppTheme
|
|
31
|
-
import vn.momo.kits.const.Colors
|
|
32
|
-
import vn.momo.kits.const.Radius
|
|
33
|
-
import vn.momo.kits.const.Spacing
|
|
34
|
-
import vn.momo.kits.platform.getScreenDimensions
|
|
35
20
|
import vn.momo.kits.utils.bottomBorder
|
|
36
21
|
|
|
37
22
|
@Composable
|
|
38
23
|
fun HeaderExtended(
|
|
39
24
|
opacityAni: Float,
|
|
40
|
-
inputSearchProps: InputSearchProps?,
|
|
41
|
-
useAnimationSearch: Boolean = true,
|
|
42
|
-
scrollState: Int,
|
|
43
|
-
headerRightWidth: Dp,
|
|
44
|
-
isBack: Boolean,
|
|
45
25
|
statusBarHeight: Dp,
|
|
46
26
|
backgroundColor: Color
|
|
47
27
|
) {
|
|
48
|
-
val animations = useHeaderSearchAnimation(
|
|
49
|
-
opacityAni = opacityAni,
|
|
50
|
-
scrollState = scrollState,
|
|
51
|
-
headerRightWidth = headerRightWidth,
|
|
52
|
-
statusBarHeight = statusBarHeight,
|
|
53
|
-
isBack = isBack
|
|
54
|
-
)
|
|
55
|
-
|
|
56
28
|
Box(
|
|
57
|
-
modifier = Modifier
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Color(0x00FDCADE)
|
|
70
|
-
),
|
|
71
|
-
start = Offset(0f, 0f),
|
|
72
|
-
end = Offset(0f, with(LocalDensity.current) { 154.dp.toPx() })
|
|
73
|
-
)
|
|
74
|
-
)
|
|
75
|
-
) {
|
|
76
|
-
if (AppTheme.current.assets.headerBackground != null) {
|
|
77
|
-
Box(
|
|
78
|
-
modifier = Modifier
|
|
79
|
-
.fillMaxWidth()
|
|
80
|
-
.background(backgroundColor)
|
|
81
|
-
) {
|
|
82
|
-
Image(
|
|
83
|
-
loading = false,
|
|
84
|
-
source = AppTheme.current.assets.headerBackground!!,
|
|
85
|
-
modifier = Modifier.fillMaxWidth().height(154.dp),
|
|
86
|
-
options = Options(
|
|
87
|
-
contentScale = ContentScale.FillWidth
|
|
88
|
-
)
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
Box(
|
|
95
|
-
modifier = Modifier
|
|
96
|
-
.fillMaxWidth()
|
|
97
|
-
.alpha(1f - opacityAni)
|
|
98
|
-
.height(statusBarHeight + 52.dp)
|
|
99
|
-
.background(
|
|
100
|
-
AppTheme.current.colors.background.surface
|
|
101
|
-
)
|
|
102
|
-
.bottomBorder(
|
|
103
|
-
strokeWidth = 1.dp,
|
|
104
|
-
color = AppTheme.current.colors.border.default
|
|
29
|
+
modifier = Modifier
|
|
30
|
+
.fillMaxWidth()
|
|
31
|
+
.height(154.dp)
|
|
32
|
+
.alpha(opacityAni)
|
|
33
|
+
.background(
|
|
34
|
+
Brush.linearGradient(
|
|
35
|
+
colors = listOf(
|
|
36
|
+
Color(0xFFFDCADE),
|
|
37
|
+
Color(0x00FDCADE)
|
|
38
|
+
),
|
|
39
|
+
start = Offset(0f, 0f),
|
|
40
|
+
end = Offset(0f, with(LocalDensity.current) { 154.dp.toPx() })
|
|
105
41
|
)
|
|
106
|
-
|
|
107
|
-
|
|
42
|
+
)
|
|
43
|
+
) {
|
|
44
|
+
if (AppTheme.current.assets.headerBackground != null) {
|
|
108
45
|
Box(
|
|
109
46
|
modifier = Modifier
|
|
110
|
-
.
|
|
111
|
-
.
|
|
112
|
-
x = animations.translateX.dp
|
|
113
|
-
)
|
|
114
|
-
.padding(vertical = Spacing.S)
|
|
115
|
-
.align(Alignment.BottomStart)
|
|
116
|
-
.zIndex(1f)
|
|
47
|
+
.fillMaxWidth()
|
|
48
|
+
.background(backgroundColor)
|
|
117
49
|
) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
) {
|
|
126
|
-
InputSearch(
|
|
127
|
-
inputSearchProps = inputSearchProps.copy(
|
|
128
|
-
showButtonText = false,
|
|
129
|
-
backgroundColor = Color.Transparent
|
|
130
|
-
)
|
|
50
|
+
Image(
|
|
51
|
+
loading = false,
|
|
52
|
+
source = AppTheme.current.assets.headerBackground!!,
|
|
53
|
+
modifier = Modifier.fillMaxWidth().height(154.dp),
|
|
54
|
+
options = Options(
|
|
55
|
+
contentScale = ContentScale.FillWidth
|
|
131
56
|
)
|
|
132
|
-
|
|
57
|
+
)
|
|
133
58
|
}
|
|
134
59
|
}
|
|
135
60
|
}
|
|
61
|
+
|
|
62
|
+
Box(
|
|
63
|
+
modifier = Modifier
|
|
64
|
+
.fillMaxWidth()
|
|
65
|
+
.alpha(1f - opacityAni)
|
|
66
|
+
.height(statusBarHeight + HEADER_HEIGHT.dp)
|
|
67
|
+
.background(
|
|
68
|
+
AppTheme.current.colors.background.surface
|
|
69
|
+
)
|
|
70
|
+
.bottomBorder(
|
|
71
|
+
strokeWidth = 1.dp,
|
|
72
|
+
color = AppTheme.current.colors.border.default
|
|
73
|
+
)
|
|
74
|
+
)
|
|
136
75
|
}
|
|
@@ -115,11 +115,12 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
fun onPressClose() {
|
|
118
|
-
api?.request("dismiss", "", {_ -> })
|
|
118
|
+
api?.request("dismiss", "", { _ -> })
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
fun onPressMore() {
|
|
122
|
-
api?.request(
|
|
122
|
+
api?.request(
|
|
123
|
+
"showTools",
|
|
123
124
|
mapOf(
|
|
124
125
|
"tools" to headerRight?.tools?.map { it.toMap() },
|
|
125
126
|
"context" to mapOf(
|
|
@@ -127,7 +128,11 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
127
128
|
"code" to context?.appCode,
|
|
128
129
|
"name" to context?.appName,
|
|
129
130
|
"icon" to context?.appIcon,
|
|
130
|
-
"description" to context?.description
|
|
131
|
+
"description" to context?.description,
|
|
132
|
+
"support" to context?.support,
|
|
133
|
+
"toolkitConfig" to context?.toolkitConfig,
|
|
134
|
+
"providerId" to context?.providerId,
|
|
135
|
+
"permissions" to context?.permissions
|
|
131
136
|
)
|
|
132
137
|
)
|
|
133
138
|
) { response ->
|
|
@@ -180,10 +185,18 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
180
185
|
group.items.any { it.showBadge }
|
|
181
186
|
}
|
|
182
187
|
|
|
188
|
+
val toolkitWidth = if (context !== null) 65.dp else 28.dp
|
|
189
|
+
|
|
190
|
+
var isShowShortcut = headerRight?.useShortcut == true
|
|
191
|
+
//backup case context null of more icon
|
|
192
|
+
if (headerRight?.useMore == true && context == null) {
|
|
193
|
+
isShowShortcut = false
|
|
194
|
+
}
|
|
195
|
+
|
|
183
196
|
Row(
|
|
184
197
|
verticalAlignment = Alignment.CenterVertically
|
|
185
198
|
) {
|
|
186
|
-
if (
|
|
199
|
+
if (isShowShortcut) {
|
|
187
200
|
NavigationButton(
|
|
188
201
|
disabled = isLoading,
|
|
189
202
|
icon = navButtonConfig.icon,
|
|
@@ -197,20 +210,26 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
197
210
|
modifier = Modifier
|
|
198
211
|
.padding(start = Spacing.S)
|
|
199
212
|
.border(0.2.dp, Color(0x33000000), shape = RoundedCornerShape(14.dp))
|
|
200
|
-
.width(
|
|
213
|
+
.width(toolkitWidth)
|
|
201
214
|
.height(28.dp)
|
|
202
215
|
.clip(shape = RoundedCornerShape(14.dp))
|
|
203
216
|
.background(Color(0x99FFFFFF))
|
|
204
217
|
) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
218
|
+
if (context != null) {
|
|
219
|
+
Icon(
|
|
220
|
+
source = "help_center",
|
|
221
|
+
size = 20.dp,
|
|
222
|
+
modifier = Modifier.padding(4.dp).clickable {
|
|
223
|
+
onPressHelpCenter()
|
|
224
|
+
})
|
|
225
|
+
Box(
|
|
226
|
+
modifier = Modifier
|
|
227
|
+
.width(0.5.dp)
|
|
228
|
+
.height(12.dp)
|
|
229
|
+
.background(Colors.black_20)
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
214
233
|
Icon(
|
|
215
234
|
source = "16_navigation_close_circle",
|
|
216
235
|
size = 20.dp,
|
|
@@ -9,6 +9,7 @@ import androidx.compose.runtime.remember
|
|
|
9
9
|
import androidx.compose.runtime.setValue
|
|
10
10
|
import androidx.compose.runtime.staticCompositionLocalOf
|
|
11
11
|
import androidx.compose.ui.unit.Dp
|
|
12
|
+
import kotlinx.serialization.Serializable
|
|
12
13
|
import vn.momo.kits.components.TrustBannerData
|
|
13
14
|
import vn.momo.kits.const.AppStatusBar
|
|
14
15
|
import vn.momo.kits.const.AppTheme
|
|
@@ -48,12 +49,16 @@ data class MiniAppContext(
|
|
|
48
49
|
val appId: String = "",
|
|
49
50
|
val appCode: String = "",
|
|
50
51
|
val description: Any? = null,
|
|
52
|
+
val support: Map<String, Any?> = emptyMap(),
|
|
53
|
+
val toolkitConfig: Map<String, Any?> = emptyMap(),
|
|
54
|
+
val providerId: String = "",
|
|
55
|
+
val permissions: List<Map<String, Any>>? = emptyList()
|
|
51
56
|
)
|
|
52
57
|
|
|
53
58
|
val PlatformApi = staticCompositionLocalOf<Any?> { null }
|
|
54
59
|
|
|
55
|
-
val AppNavigator = staticCompositionLocalOf<Navigator
|
|
56
|
-
|
|
60
|
+
val AppNavigator = staticCompositionLocalOf<Navigator?> {
|
|
61
|
+
null
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
val ApplicationContext = staticCompositionLocalOf<MiniAppContext?> {
|
|
@@ -47,6 +47,8 @@ enum class HeaderType {
|
|
|
47
47
|
NONE
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const val HEADER_HEIGHT = 52
|
|
51
|
+
|
|
50
52
|
@Composable
|
|
51
53
|
fun Screen(
|
|
52
54
|
backgroundColor: Color? = null,
|
|
@@ -85,7 +87,7 @@ fun Screen(
|
|
|
85
87
|
val bottomPadding = min(indicator, 21.dp)
|
|
86
88
|
|
|
87
89
|
val opacity by animateFloatAsState(
|
|
88
|
-
targetValue = ((scrollState.value /
|
|
90
|
+
targetValue = ((scrollState.value / HEADER_HEIGHT*1f)).coerceIn(0f, 1f),
|
|
89
91
|
)
|
|
90
92
|
|
|
91
93
|
val headerAnimated =
|
|
@@ -101,10 +103,7 @@ fun Screen(
|
|
|
101
103
|
if (animatedHeader === null) {
|
|
102
104
|
HeaderBackground(
|
|
103
105
|
headerType = headerType,
|
|
104
|
-
scrollState = scrollState.value
|
|
105
|
-
inputSearchProps= inputSearchProps,
|
|
106
|
-
useAnimationSearch = useAnimationSearch,
|
|
107
|
-
headerRightWidth = headerRightWidth
|
|
106
|
+
scrollState = scrollState.value
|
|
108
107
|
)
|
|
109
108
|
} else {
|
|
110
109
|
Box(
|
|
@@ -113,21 +112,17 @@ fun Screen(
|
|
|
113
112
|
.graphicsLayer { alpha = opacity }
|
|
114
113
|
) {
|
|
115
114
|
HeaderBackground(
|
|
116
|
-
isBack = isBack,
|
|
117
115
|
headerType = headerType,
|
|
118
|
-
scrollState = scrollState.value
|
|
119
|
-
inputSearchProps= inputSearchProps,
|
|
120
|
-
useAnimationSearch = useAnimationSearch,
|
|
121
|
-
headerRightWidth = headerRightWidth
|
|
116
|
+
scrollState = scrollState.value
|
|
122
117
|
)
|
|
123
118
|
}
|
|
124
119
|
}
|
|
125
|
-
|
|
126
120
|
Header(
|
|
127
121
|
headerType = headerType,
|
|
128
122
|
title = title,
|
|
129
123
|
titlePosition = titlePosition,
|
|
130
124
|
headerRight = headerRight,
|
|
125
|
+
headerRightWidth = headerRightWidth,
|
|
131
126
|
goBack = goBack,
|
|
132
127
|
opacity = opacity,
|
|
133
128
|
animatedHeader = animatedHeader,
|
|
@@ -138,7 +133,7 @@ fun Screen(
|
|
|
138
133
|
|
|
139
134
|
Column(
|
|
140
135
|
modifier = Modifier.fillMaxSize()
|
|
141
|
-
.padding(top = if (animatedHeader === null && headerType !== HeaderType.NONE) statusBarHeight +
|
|
136
|
+
.padding(top = if (animatedHeader === null && headerType !== HeaderType.NONE) statusBarHeight + HEADER_HEIGHT.dp else 0.dp)
|
|
142
137
|
.pointerInput(Unit) {
|
|
143
138
|
detectTapGestures(onTap = {
|
|
144
139
|
keyboardController?.hide()
|
|
@@ -162,11 +157,11 @@ fun Screen(
|
|
|
162
157
|
headerAnimated()
|
|
163
158
|
Column {
|
|
164
159
|
if (animatedHeader !== null) {
|
|
165
|
-
Spacer(modifier = Modifier.padding(top = statusBarHeight +
|
|
160
|
+
Spacer(modifier = Modifier.padding(top = statusBarHeight + HEADER_HEIGHT.dp + layoutOffset))
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
if (useAnimationSearch && inputSearchProps != null && headerType == HeaderType.EXTENDED) {
|
|
169
|
-
Spacer(modifier = Modifier.padding(top =
|
|
164
|
+
Spacer(modifier = Modifier.padding(top = (HEADER_HEIGHT.dp + Spacing.S)))
|
|
170
165
|
}
|
|
171
166
|
content()
|
|
172
167
|
}
|
|
@@ -16,7 +16,7 @@ data class HeaderAnimations(
|
|
|
16
16
|
val backgroundSearch: Color,
|
|
17
17
|
val translateX: Float,
|
|
18
18
|
val width: Float,
|
|
19
|
-
val
|
|
19
|
+
val translateY: Float
|
|
20
20
|
)
|
|
21
21
|
|
|
22
22
|
private const val SCREEN_PADDING = 12
|
|
@@ -27,43 +27,39 @@ fun useHeaderSearchAnimation(
|
|
|
27
27
|
opacityAni: Float,
|
|
28
28
|
scrollState: Int,
|
|
29
29
|
headerRightWidth: Dp,
|
|
30
|
-
statusBarHeight: Dp,
|
|
31
30
|
isBack: Boolean
|
|
32
31
|
): HeaderAnimations {
|
|
33
32
|
val screenWidth = getScreenDimensions().width
|
|
34
|
-
val leftPosition = if (isBack) (BACK_WIDTH + 20).dp else
|
|
33
|
+
val leftPosition = if (isBack) (BACK_WIDTH + 20).dp else 12.dp
|
|
35
34
|
val searchWidth = screenWidth - (SCREEN_PADDING * 2)
|
|
36
35
|
|
|
37
36
|
val backgroundSearch by animateColorAsState(
|
|
38
37
|
targetValue = animateColor(
|
|
39
|
-
AppTheme.current.colors.background.default,
|
|
40
38
|
Colors.black_01,
|
|
39
|
+
AppTheme.current.colors.background.default,
|
|
41
40
|
opacityAni
|
|
42
41
|
),
|
|
43
42
|
)
|
|
44
43
|
|
|
45
44
|
val animatedTranslateX by animateFloatAsState(
|
|
46
|
-
targetValue = (scrollState /
|
|
45
|
+
targetValue = (scrollState / HEADER_HEIGHT*1f).coerceIn(0f, 1f) * (leftPosition.value - 12) + 12,
|
|
47
46
|
)
|
|
48
47
|
|
|
49
48
|
val animatedWidth by animateFloatAsState(
|
|
50
|
-
targetValue = (scrollState /
|
|
49
|
+
targetValue = (scrollState / HEADER_HEIGHT*1f).coerceIn(
|
|
51
50
|
0f,
|
|
52
51
|
1f
|
|
53
52
|
) * ((searchWidth - leftPosition.value - headerRightWidth.value + 12) - searchWidth) + searchWidth,
|
|
54
53
|
)
|
|
55
54
|
|
|
56
|
-
val
|
|
57
|
-
targetValue = (1 - (scrollState /
|
|
58
|
-
0f,
|
|
59
|
-
1f
|
|
60
|
-
)) * (statusBarHeight.value + 94 - (statusBarHeight.value + 52)) + (statusBarHeight.value + 52),
|
|
55
|
+
val animatedTranslateY by animateFloatAsState(
|
|
56
|
+
targetValue = (1 - (scrollState / HEADER_HEIGHT* 1f).coerceIn(0f, 1f)) * HEADER_HEIGHT
|
|
61
57
|
)
|
|
62
58
|
return HeaderAnimations(
|
|
63
59
|
opacity = opacityAni,
|
|
64
60
|
backgroundSearch = backgroundSearch,
|
|
65
61
|
translateX = animatedTranslateX,
|
|
66
62
|
width = animatedWidth,
|
|
67
|
-
|
|
63
|
+
translateY = animatedTranslateY
|
|
68
64
|
)
|
|
69
65
|
}
|
|
@@ -21,6 +21,7 @@ import androidx.compose.foundation.text.KeyboardOptions
|
|
|
21
21
|
import androidx.compose.material3.CircularProgressIndicator
|
|
22
22
|
import androidx.compose.runtime.Composable
|
|
23
23
|
import androidx.compose.runtime.MutableState
|
|
24
|
+
import androidx.compose.runtime.SideEffect
|
|
24
25
|
import androidx.compose.runtime.getValue
|
|
25
26
|
import androidx.compose.runtime.mutableStateOf
|
|
26
27
|
import androidx.compose.runtime.remember
|
|
@@ -36,6 +37,7 @@ import androidx.compose.ui.text.TextStyle
|
|
|
36
37
|
import androidx.compose.ui.text.font.FontWeight
|
|
37
38
|
import androidx.compose.ui.text.input.KeyboardType
|
|
38
39
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
40
|
+
import androidx.compose.ui.text.input.TextFieldValue
|
|
39
41
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
40
42
|
import androidx.compose.ui.unit.Dp
|
|
41
43
|
import androidx.compose.ui.unit.dp
|
|
@@ -154,7 +156,7 @@ fun ErrorView(errorMessage: String, errorSpacing: Boolean, hintText: String) {
|
|
|
154
156
|
|
|
155
157
|
@Composable
|
|
156
158
|
fun Input(
|
|
157
|
-
text:
|
|
159
|
+
text: String = "",
|
|
158
160
|
floatingValue: String = "",
|
|
159
161
|
floatingValueColor: Color = AppTheme.current.colors.text.hint,
|
|
160
162
|
floatingIcon: String = "",
|
|
@@ -181,6 +183,11 @@ fun Input(
|
|
|
181
183
|
keyboardType: KeyboardType = KeyboardType.Text,
|
|
182
184
|
modifier: Modifier = Modifier,
|
|
183
185
|
) {
|
|
186
|
+
// Handling state based on the `BasicTextField` concept
|
|
187
|
+
var textFieldValueState by remember { mutableStateOf(TextFieldValue(text = text)) }
|
|
188
|
+
val textFieldValue = textFieldValueState.copy(text = text)
|
|
189
|
+
var lastTextValue by remember(text) { mutableStateOf(text) }
|
|
190
|
+
|
|
184
191
|
var isFocused by remember { mutableStateOf(false) }
|
|
185
192
|
var passHidden by remember { mutableStateOf(false) }
|
|
186
193
|
var isBlurred = false
|
|
@@ -209,10 +216,10 @@ fun Input(
|
|
|
209
216
|
setAutomationId(testId)
|
|
210
217
|
) {
|
|
211
218
|
BasicTextField(
|
|
219
|
+
value = text,
|
|
212
220
|
enabled = !disabled,
|
|
213
221
|
readOnly = readOnly,
|
|
214
222
|
singleLine = true,
|
|
215
|
-
value = text.value,
|
|
216
223
|
textStyle = TextStyle(
|
|
217
224
|
color = textColor,
|
|
218
225
|
fontSize = 16.sp,
|
|
@@ -229,7 +236,15 @@ fun Input(
|
|
|
229
236
|
if (!it.isFocused && isBlurred) onBlur()
|
|
230
237
|
if (it.isFocused && !isBlurred) isBlurred = true
|
|
231
238
|
},
|
|
232
|
-
onValueChange =
|
|
239
|
+
onValueChange = { newValue ->
|
|
240
|
+
textFieldValueState.copy(text = newValue)
|
|
241
|
+
val stringChangedSinceLastInvocation = lastTextValue != newValue
|
|
242
|
+
lastTextValue = newValue
|
|
243
|
+
|
|
244
|
+
if (stringChangedSinceLastInvocation) {
|
|
245
|
+
onChangeText(newValue)
|
|
246
|
+
}
|
|
247
|
+
},
|
|
233
248
|
decorationBox = { innerTextField ->
|
|
234
249
|
// Floating Icon
|
|
235
250
|
if (floatingValue.isNotEmpty() || floatingIcon.isNotEmpty()) {
|
|
@@ -291,7 +306,7 @@ fun Input(
|
|
|
291
306
|
)
|
|
292
307
|
}
|
|
293
308
|
Box(Modifier.weight(1f)) {
|
|
294
|
-
if (text.
|
|
309
|
+
if (textFieldValue.text.isEmpty()) {
|
|
295
310
|
Text(
|
|
296
311
|
text = placeholder,
|
|
297
312
|
style = TextStyle(
|
|
@@ -304,7 +319,7 @@ fun Input(
|
|
|
304
319
|
}
|
|
305
320
|
innerTextField()
|
|
306
321
|
}
|
|
307
|
-
if (isFocused && text.
|
|
322
|
+
if (isFocused && textFieldValue.text.isNotEmpty()) {
|
|
308
323
|
Row {
|
|
309
324
|
Spacer(Modifier.width(Spacing.XS))
|
|
310
325
|
Icon(
|
|
@@ -312,7 +327,10 @@ fun Input(
|
|
|
312
327
|
size = 16.dp,
|
|
313
328
|
color = AppTheme.current.colors.text.hint,
|
|
314
329
|
modifier = Modifier.clickable(
|
|
315
|
-
onClick = {
|
|
330
|
+
onClick = {
|
|
331
|
+
onChangeText("")
|
|
332
|
+
textFieldValueState = TextFieldValue(text = "")
|
|
333
|
+
},
|
|
316
334
|
interactionSource = remember { MutableInteractionSource() },
|
|
317
335
|
indication = null
|
|
318
336
|
)
|
|
@@ -143,7 +143,7 @@ fun PopupNotify(
|
|
|
143
143
|
Modifier
|
|
144
144
|
.width(22.dp)
|
|
145
145
|
.height(22.dp)
|
|
146
|
-
.offset(x =
|
|
146
|
+
.offset(x = -(1).dp, y = (-11).dp)
|
|
147
147
|
.background(
|
|
148
148
|
color = AppTheme.current.colors.text.default,
|
|
149
149
|
shape = RoundedCornerShape(Radius.M)
|
|
@@ -13,20 +13,28 @@ public class MiniAppContext {
|
|
|
13
13
|
public var appName: Any? = nil
|
|
14
14
|
public var appIcon: String = ""
|
|
15
15
|
public var description: Any? = nil
|
|
16
|
-
|
|
17
|
-
public
|
|
16
|
+
public var support: Any? = nil
|
|
17
|
+
public var toolkitConfig: Any? = nil
|
|
18
|
+
public var providerId: String = ""
|
|
19
|
+
public var permissions: Any? = nil
|
|
20
|
+
|
|
21
|
+
public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: Any? = nil, toolkitConfig: Any? = nil, providerId: String, permissions: Any? = nil) {
|
|
18
22
|
self.appId = appId
|
|
19
23
|
self.appCode = appCode
|
|
20
24
|
self.appName = appName
|
|
21
25
|
self.appIcon = appIcon
|
|
22
26
|
self.description = description
|
|
27
|
+
self.support = support
|
|
28
|
+
self.toolkitConfig = toolkitConfig
|
|
29
|
+
self.providerId = providerId
|
|
30
|
+
self.permissions = permissions
|
|
23
31
|
}
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
public class ApplicationEnvironment: ObservableObject {
|
|
27
35
|
let applicationContext: MiniAppContext?
|
|
28
36
|
let composeApi: KitComposeApi
|
|
29
|
-
|
|
37
|
+
|
|
30
38
|
public init(applicationContext: MiniAppContext?, composeApi: KitComposeApi) {
|
|
31
39
|
self.applicationContext = applicationContext
|
|
32
40
|
self.composeApi = composeApi
|
|
@@ -203,9 +203,7 @@ public struct Header: View {
|
|
|
203
203
|
Text(title)
|
|
204
204
|
.font(.headline)
|
|
205
205
|
.foregroundColor(tintIconColor)
|
|
206
|
-
.frame(maxWidth: titlePosition == .center ?
|
|
207
|
-
.frame(maxWidth: titlePosition == .center ? .infinity : UIScreen.main.bounds.width - 172, alignment: titlePosition == .center ? .center : .leading)
|
|
208
|
-
.lineLimit(1)
|
|
206
|
+
.frame(maxWidth: titlePosition == .center ? .infinity : nil, alignment: titlePosition == .center ? .center : .leading)
|
|
209
207
|
}
|
|
210
208
|
Spacer()
|
|
211
209
|
}
|
|
@@ -6,7 +6,7 @@ public struct HeaderRightData {
|
|
|
6
6
|
var useMore: Bool
|
|
7
7
|
var tools: [ToolGroup]
|
|
8
8
|
var toolCallback: ((String) -> Void)?
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
public init(
|
|
11
11
|
useShortcut: Bool = false,
|
|
12
12
|
useMore: Bool = false,
|
|
@@ -25,7 +25,7 @@ public struct Tool {
|
|
|
25
25
|
var icon: String
|
|
26
26
|
var showBadge: Bool
|
|
27
27
|
var name: [String: String]
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
public init(
|
|
30
30
|
key: String,
|
|
31
31
|
icon: String,
|
|
@@ -37,7 +37,7 @@ public struct Tool {
|
|
|
37
37
|
self.showBadge = showBadge
|
|
38
38
|
self.name = name
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
func toMap() -> [String: Any] {
|
|
42
42
|
return [
|
|
43
43
|
"key": key,
|
|
@@ -51,7 +51,7 @@ public struct Tool {
|
|
|
51
51
|
public struct ToolGroup {
|
|
52
52
|
var title: [String: String]
|
|
53
53
|
var items: [Tool]
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
public init(
|
|
56
56
|
title: [String: String] = [:],
|
|
57
57
|
items: [Tool]
|
|
@@ -59,7 +59,7 @@ public struct ToolGroup {
|
|
|
59
59
|
self.title = title
|
|
60
60
|
self.items = items
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
func toMap() -> [String: Any] {
|
|
64
64
|
return [
|
|
65
65
|
"title": title,
|
|
@@ -79,7 +79,7 @@ public struct HeaderRight: View {
|
|
|
79
79
|
self.headerRight = headerRight
|
|
80
80
|
}
|
|
81
81
|
var headerRight: HeaderRightData?
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
public var body: some View {
|
|
84
84
|
HStack(alignment: .center) {
|
|
85
85
|
ToolkitHeaderRight(headerRight: headerRight)
|
|
@@ -92,7 +92,7 @@ struct ToolkitHeaderRight: View {
|
|
|
92
92
|
@State private var isFavorite: Bool = false
|
|
93
93
|
@State private var isLoading: Bool = false
|
|
94
94
|
@EnvironmentObject private var environment: ApplicationEnvironment
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
// MARK: - Actions
|
|
97
97
|
private func onPressShortcut() {
|
|
98
98
|
environment.composeApi.request(
|
|
@@ -102,7 +102,7 @@ struct ToolkitHeaderRight: View {
|
|
|
102
102
|
isFavorite.toggle()
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
private func onPressHelpCenter() {
|
|
107
107
|
let context = environment.applicationContext
|
|
108
108
|
let paramMap: [String: Any] = [
|
|
@@ -117,14 +117,15 @@ struct ToolkitHeaderRight: View {
|
|
|
117
117
|
params: paramMap
|
|
118
118
|
) { _ in }
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
private func onPressClose() {
|
|
122
122
|
environment.composeApi.request(
|
|
123
123
|
funcName: "dismiss",
|
|
124
124
|
params: ""
|
|
125
125
|
) { _ in }
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
|
|
128
|
+
|
|
128
129
|
private func onPressMore() {
|
|
129
130
|
let context = environment.applicationContext
|
|
130
131
|
let params: [String: Any] = [
|
|
@@ -134,7 +135,11 @@ struct ToolkitHeaderRight: View {
|
|
|
134
135
|
"code": context?.appCode,
|
|
135
136
|
"name": context?.appName,
|
|
136
137
|
"icon": context?.appIcon,
|
|
137
|
-
"description": context?.description
|
|
138
|
+
"description": context?.description,
|
|
139
|
+
"support": context?.support,
|
|
140
|
+
"toolkitConfig": context?.toolkitConfig,
|
|
141
|
+
"providerId": context?.providerId,
|
|
142
|
+
"permissions": context?.permissions
|
|
138
143
|
]
|
|
139
144
|
]
|
|
140
145
|
environment.composeApi.request(
|
|
@@ -152,12 +157,12 @@ struct ToolkitHeaderRight: View {
|
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
|
-
|
|
160
|
+
|
|
156
161
|
private func getNavigationButtonConfig() -> NavigationButtonConfig {
|
|
157
162
|
let totalTools = headerRight?.tools.reduce(0) { $0 + $1.items.count } ?? 0
|
|
158
163
|
var icon = isFavorite ? "pin_star_checked" : "pin_star"
|
|
159
164
|
var onClickHandler: () -> Void = onPressShortcut
|
|
160
|
-
|
|
165
|
+
|
|
161
166
|
if totalTools > 1 || headerRight?.useMore == true {
|
|
162
167
|
icon = "navigation_more_icon"
|
|
163
168
|
onClickHandler = onPressMore
|
|
@@ -167,16 +172,16 @@ struct ToolkitHeaderRight: View {
|
|
|
167
172
|
headerRight?.toolCallback?(singleTool.key)
|
|
168
173
|
}
|
|
169
174
|
}
|
|
170
|
-
|
|
175
|
+
|
|
171
176
|
return NavigationButtonConfig(icon: icon, onPress: onClickHandler)
|
|
172
177
|
}
|
|
173
|
-
|
|
178
|
+
|
|
174
179
|
var body: some View {
|
|
175
180
|
let navButtonConfig = getNavigationButtonConfig()
|
|
176
181
|
let showBadge = headerRight?.tools.contains { group in
|
|
177
182
|
group.items.contains { $0.showBadge }
|
|
178
183
|
} ?? false
|
|
179
|
-
|
|
184
|
+
|
|
180
185
|
HStack(alignment: .center) {
|
|
181
186
|
if headerRight?.useShortcut == true {
|
|
182
187
|
NavigationButton(
|
|
@@ -186,18 +191,18 @@ struct ToolkitHeaderRight: View {
|
|
|
186
191
|
onClick: navButtonConfig.onPress
|
|
187
192
|
)
|
|
188
193
|
}
|
|
189
|
-
|
|
194
|
+
|
|
190
195
|
HStack(alignment: .center, spacing: 0) {
|
|
191
196
|
Icon(source: "help_center", size: 20)
|
|
192
197
|
.padding(4)
|
|
193
198
|
.onTapGesture {
|
|
194
199
|
onPressHelpCenter()
|
|
195
200
|
}
|
|
196
|
-
|
|
201
|
+
|
|
197
202
|
Rectangle()
|
|
198
203
|
.fill(Colors.black20)
|
|
199
204
|
.frame(width: 0.5, height: 12)
|
|
200
|
-
|
|
205
|
+
|
|
201
206
|
Icon(source: "16_navigation_close_circle", size: 20, color: Colors.black17)
|
|
202
207
|
.padding(4)
|
|
203
208
|
.onTapGesture {
|
|
@@ -221,7 +226,7 @@ struct NavigationButton: View {
|
|
|
221
226
|
var icon: String
|
|
222
227
|
var showBadge: Bool
|
|
223
228
|
var onClick: () -> Void
|
|
224
|
-
|
|
229
|
+
|
|
225
230
|
var body: some View {
|
|
226
231
|
ZStack {
|
|
227
232
|
Circle()
|
|
@@ -230,9 +235,9 @@ struct NavigationButton: View {
|
|
|
230
235
|
Circle()
|
|
231
236
|
.stroke(Color.black.opacity(0.2), lineWidth: 0.2)
|
|
232
237
|
)
|
|
233
|
-
|
|
238
|
+
|
|
234
239
|
Icon(source: icon, size: 16)
|
|
235
|
-
|
|
240
|
+
|
|
236
241
|
if showBadge {
|
|
237
242
|
BadgeDot(size: .small)
|
|
238
243
|
.offset(x: -2, y: -2)
|
|
@@ -34,7 +34,7 @@ public struct Screen<Content: View>: View {
|
|
|
34
34
|
verticalAlignment: VerticalAlignment = .top,
|
|
35
35
|
horizontalAlignment: HorizontalAlignment = .leading,
|
|
36
36
|
title: String = "Stack",
|
|
37
|
-
titlePosition: TitlePosition = .
|
|
37
|
+
titlePosition: TitlePosition = .center,
|
|
38
38
|
goBack: (() -> Void)? = nil,
|
|
39
39
|
scrollable: Bool = true,
|
|
40
40
|
onContentLayout: ((CGRect) -> Void)? = nil,
|
|
@@ -46,8 +46,8 @@ public struct PopupDisplay: View {
|
|
|
46
46
|
.overlay(RoundedRectangle(cornerRadius: Radius.L).stroke(Colors.black01, lineWidth: 1))
|
|
47
47
|
}.foregroundColor(Colors.black20)
|
|
48
48
|
.background(Colors.black01.cornerRadius(15))
|
|
49
|
-
.padding(.trailing, -
|
|
50
|
-
.padding(.top, -
|
|
49
|
+
.padding(.trailing, -11)
|
|
50
|
+
.padding(.top, -11)
|
|
51
51
|
.zIndex(1)
|
|
52
52
|
.accessibility(identifier: "ic_popup_close")
|
|
53
53
|
|
|
@@ -10,9 +10,9 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
10
10
|
var trailingSideGroup: [SwipeCellActionItem] = []
|
|
11
11
|
@Binding var currentUserInteractionCellID: String?
|
|
12
12
|
var settings: SwipeCellSettings = .init()
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
@State private var offsetX: CGFloat = 0
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
let generator = UINotificationFeedbackGenerator()
|
|
17
17
|
@State private var hapticFeedbackOccurred: Bool = false
|
|
18
18
|
@State private var openSideLock: SwipeGroupSide?
|
|
@@ -22,15 +22,23 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
22
22
|
if self.leadingSideGroup.isEmpty == false && self.offsetX != 0 {
|
|
23
23
|
self.swipeToRevealArea(swipeItemGroup: self.leadingSideGroup, side: .leading)
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
if self.trailingSideGroup.isEmpty == false && self.offsetX != 0 {
|
|
27
27
|
self.swipeToRevealArea(swipeItemGroup: self.trailingSideGroup, side: .trailing)
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
content
|
|
31
31
|
.offset(x: self.offsetX)
|
|
32
|
-
.
|
|
33
|
-
|
|
32
|
+
.simultaneousGesture(
|
|
33
|
+
DragGesture(minimumDistance: 30, coordinateSpace: .local)
|
|
34
|
+
.onChanged { value in
|
|
35
|
+
self.dragOnChanged(value: value)
|
|
36
|
+
}
|
|
37
|
+
.onEnded { value in
|
|
38
|
+
self.dragOnEnded(value: value)
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
|
|
34
42
|
}.frame(width: cellWidth)
|
|
35
43
|
.edgesIgnoringSafeArea(.horizontal)
|
|
36
44
|
.clipped()
|
|
@@ -43,7 +51,7 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
|
-
|
|
54
|
+
|
|
47
55
|
internal func swipeToRevealArea(swipeItemGroup: [SwipeCellActionItem], side: SwipeGroupSide)->some View {
|
|
48
56
|
HStack {
|
|
49
57
|
if side == .trailing {
|
|
@@ -63,17 +71,17 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
}.opacity(self.swipeRevealAreaOpacity(side: side))
|
|
66
|
-
|
|
74
|
+
|
|
67
75
|
if side == .leading {
|
|
68
76
|
Spacer()
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
|
-
|
|
80
|
+
|
|
73
81
|
internal func buttonContentView(item: SwipeCellActionItem, group: [SwipeCellActionItem], side: SwipeGroupSide)->some View {
|
|
74
82
|
ZStack {
|
|
75
83
|
item.backgroundColor
|
|
76
|
-
|
|
84
|
+
|
|
77
85
|
HStack {
|
|
78
86
|
if self.warnSwipeOutCondition(side: side, hasSwipeOut: item.swipeOutAction) && item.swipeOutButtonView != nil {
|
|
79
87
|
item.swipeOutButtonView!()
|
|
@@ -81,28 +89,28 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
81
89
|
item.buttonView()
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
|
-
|
|
92
|
+
|
|
85
93
|
}.frame(width: self.itemButtonWidth(item: item, itemGroup: group, side: side))
|
|
86
94
|
}
|
|
87
|
-
|
|
95
|
+
|
|
88
96
|
internal func menuWidth(side: SwipeGroupSide)->CGFloat {
|
|
89
97
|
switch side {
|
|
90
98
|
case .leading:
|
|
91
99
|
return self.leadingSideGroup.map { $0.buttonWidth }.reduce(0, +)
|
|
92
|
-
|
|
100
|
+
|
|
93
101
|
case .trailing:
|
|
94
102
|
return self.trailingSideGroup.map { $0.buttonWidth }.reduce(0, +)
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
|
-
|
|
105
|
+
|
|
98
106
|
// MARK: drag gesture
|
|
99
|
-
|
|
107
|
+
|
|
100
108
|
internal func dragOnChanged(value: DragGesture.Value) {
|
|
101
109
|
let horizontalTranslation = value.translation.width
|
|
102
110
|
if self.nonDraggableCondition(horizontalTranslation: horizontalTranslation) {
|
|
103
111
|
return
|
|
104
112
|
}
|
|
105
|
-
|
|
113
|
+
|
|
106
114
|
if self.openSideLock != nil {
|
|
107
115
|
// if one side is open, we need to add the menu width!
|
|
108
116
|
let menuWidth = self.openSideLock == .leading ? self.menuWidth(side: .leading) : self.menuWidth(side: .trailing)
|
|
@@ -110,9 +118,9 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
110
118
|
self.triggerHapticFeedbackIfNeeded(horizontalTranslation: horizontalTranslation)
|
|
111
119
|
return
|
|
112
120
|
}
|
|
113
|
-
|
|
121
|
+
|
|
114
122
|
self.triggerHapticFeedbackIfNeeded(horizontalTranslation: horizontalTranslation)
|
|
115
|
-
|
|
123
|
+
|
|
116
124
|
if horizontalTranslation > 8 || horizontalTranslation < -8 { // makes sure the swipe cell doesn't open too easily
|
|
117
125
|
self.currentUserInteractionCellID = self.id
|
|
118
126
|
self.offsetX = horizontalTranslation
|
|
@@ -120,11 +128,11 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
120
128
|
self.offsetX = 0
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
|
-
|
|
131
|
+
|
|
124
132
|
internal func nonDraggableCondition(horizontalTranslation: CGFloat)->Bool {
|
|
125
133
|
return self.offsetX == 0 && (self.leadingSideGroup.isEmpty && horizontalTranslation > 0 || self.trailingSideGroup.isEmpty && horizontalTranslation < 0)
|
|
126
134
|
}
|
|
127
|
-
|
|
135
|
+
|
|
128
136
|
internal func dragOnEnded(value: DragGesture.Value) {
|
|
129
137
|
let swipeOutTriggerValue = self.cellWidth * self.settings.swipeOutTriggerRatio
|
|
130
138
|
|
|
@@ -139,7 +147,7 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
139
147
|
} else {
|
|
140
148
|
self.lockSideMenu(side: .leading)
|
|
141
149
|
}
|
|
142
|
-
|
|
150
|
+
|
|
143
151
|
} else {
|
|
144
152
|
// leading group emtpy
|
|
145
153
|
self.setOffsetX(value: 0)
|
|
@@ -160,7 +168,7 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
160
168
|
}
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
|
-
|
|
171
|
+
|
|
164
172
|
internal func triggerHapticFeedbackIfNeeded(horizontalTranslation: CGFloat) {
|
|
165
173
|
let side: SwipeGroupSide = horizontalTranslation > 0 ? .leading : .trailing
|
|
166
174
|
let group = side == .leading ? self.leadingSideGroup : self.trailingSideGroup
|
|
@@ -170,7 +178,7 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
170
178
|
self.hapticFeedbackOccurred = true
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
|
-
|
|
181
|
+
|
|
174
182
|
internal func swipeOutItemWithHapticFeedback(group: [SwipeCellActionItem])->SwipeCellActionItem? {
|
|
175
183
|
if let item = group.filter({ $0.swipeOutAction == true }).first {
|
|
176
184
|
if item.swipeOutHapticFeedbackType != nil {
|
|
@@ -179,7 +187,7 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
179
187
|
}
|
|
180
188
|
return nil
|
|
181
189
|
}
|
|
182
|
-
|
|
190
|
+
|
|
183
191
|
internal func swipeOutAction(item: SwipeCellActionItem, sideFactor: CGFloat) {
|
|
184
192
|
if item.swipeOutIsDestructive {
|
|
185
193
|
let swipeOutWidth = cellWidth + 10
|
|
@@ -188,12 +196,12 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
188
196
|
} else {
|
|
189
197
|
self.setOffsetX(value: 0) // open side lock set in function!
|
|
190
198
|
}
|
|
191
|
-
|
|
199
|
+
|
|
192
200
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
193
201
|
item.actionCallback()
|
|
194
202
|
}
|
|
195
203
|
}
|
|
196
|
-
|
|
204
|
+
|
|
197
205
|
internal func lockSideMenu(side: SwipeGroupSide) {
|
|
198
206
|
self.setOffsetX(value: side.sideFactor * self.menuWidth(side: side))
|
|
199
207
|
self.openSideLock = side
|
|
@@ -214,7 +222,7 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
214
222
|
let dynamicButtonWidth = self.dynamicButtonWidth(item: item, itemCount: itemGroup.count, side: side)
|
|
215
223
|
let triggerValue = self.cellWidth * settings.swipeOutTriggerRatio
|
|
216
224
|
let swipeOutActionCondition = side == .leading ? self.offsetX > triggerValue : self.offsetX < -triggerValue
|
|
217
|
-
|
|
225
|
+
|
|
218
226
|
if item.swipeOutAction && swipeOutActionCondition {
|
|
219
227
|
return self.offsetX.magnitude + settings.addWidthMargin
|
|
220
228
|
} else if swipeOutActionCondition && item.swipeOutAction == false && itemGroup.contains(where: { $0.swipeOutAction == true }) {
|
|
@@ -223,12 +231,12 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
223
231
|
return dynamicButtonWidth
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
|
-
|
|
234
|
+
|
|
227
235
|
internal func dynamicButtonWidth(item: SwipeCellActionItem, itemCount: Int, side: SwipeGroupSide)->CGFloat {
|
|
228
236
|
let menuWidth = self.menuWidth(side: side)
|
|
229
237
|
return (self.offsetX.magnitude + settings.addWidthMargin) * (item.buttonWidth / menuWidth)
|
|
230
238
|
}
|
|
231
|
-
|
|
239
|
+
|
|
232
240
|
internal func warnSwipeOutCondition(side: SwipeGroupSide, hasSwipeOut: Bool)->Bool {
|
|
233
241
|
if hasSwipeOut == false {
|
|
234
242
|
return false
|
|
@@ -236,11 +244,11 @@ public struct SwipeCellModifier: ViewModifier {
|
|
|
236
244
|
let triggerValue = self.cellWidth * settings.swipeOutTriggerRatio
|
|
237
245
|
return (side == .trailing && self.offsetX < -triggerValue) || (side == .leading && self.offsetX > triggerValue)
|
|
238
246
|
}
|
|
239
|
-
|
|
247
|
+
|
|
240
248
|
internal func swipeRevealAreaOpacity(side: SwipeGroupSide)->Double {
|
|
241
249
|
switch side {
|
|
242
250
|
case .leading:
|
|
243
|
-
|
|
251
|
+
|
|
244
252
|
return self.offsetX > 5 ? 1 : 0
|
|
245
253
|
case .trailing:
|
|
246
254
|
return self.offsetX < -5 ? 1 : 0
|