File tree 7 files changed +98
-15
lines changed
designsystem/src/main/kotlin/io/getstream/server/driven/core/designsystem/consumer
model/src/main/kotlin/io/getstream/server/driven/core/model
feature/timeline/src/main/kotlin/io/getstream/server/driven/feature/timeline
7 files changed +98
-15
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Designed and developed by 2024 skydoves (Jaewoong Eum)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package io.getstream.server.driven.core.designsystem.consumer
17
+
18
+ import androidx.compose.foundation.clickable
19
+ import androidx.compose.runtime.Composable
20
+ import androidx.compose.ui.Modifier
21
+ import io.getstream.server.driven.core.model.Handler
22
+ import io.getstream.server.driven.core.model.HandlerAction
23
+ import io.getstream.server.driven.core.model.HandlerType
24
+
25
+ @Composable
26
+ fun Handler?.consumeHandler (
27
+ navigator : () -> Unit
28
+ ): Modifier {
29
+ if (this == null ) return Modifier
30
+
31
+ val action = if (this .actions[HandlerAction .NAVIGATION .value] == " to" ) {
32
+ { navigator }
33
+ } else {
34
+ {}
35
+ }
36
+
37
+ return if (this .type == HandlerType .CLICK .value) {
38
+ Modifier .clickable { action.invoke() }
39
+ } else {
40
+ Modifier
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -30,20 +30,28 @@ import io.getstream.server.driven.core.designsystem.extension.size
30
30
import io.getstream.server.driven.core.designsystem.preview.MockUtils
31
31
import io.getstream.server.driven.core.designsystem.theme.ServerDrivenTheme
32
32
import io.getstream.server.driven.core.model.ImageUi
33
+ import io.getstream.server.driven.core.model.UiComponent
33
34
34
35
@Composable
35
36
fun ConsumeImageUi (
36
37
imageUi : ImageUi ,
37
38
modifier : Modifier = Modifier ,
38
39
version : Int ,
40
+ navigator : (UiComponent ) -> Unit = {},
39
41
imageOptions : ImageOptions ? = null
40
42
) {
43
+ val actionModifier = imageUi.handler.consumeHandler(
44
+ navigator = { navigator.invoke(imageUi) }
45
+ )
46
+
41
47
val newModifier = if (version == 1 ) {
42
48
modifier
49
+ .then(actionModifier)
43
50
.size(imageUi.size)
44
51
.clip(RoundedCornerShape (8 .dp))
45
52
} else {
46
53
modifier
54
+ .then(actionModifier)
47
55
.size(imageUi.size)
48
56
.clip(RoundedCornerShape (16 .dp))
49
57
.border(
Original file line number Diff line number Diff line change @@ -25,17 +25,23 @@ import io.getstream.server.driven.core.model.UiComponent
25
25
@Composable
26
26
fun UiComponent.Consume (
27
27
modifier : Modifier = Modifier ,
28
- version : Int = 0 ,
29
- onListItemClicked : (UiComponent ) -> Unit = {}
28
+ version : Int = 1 ,
29
+ navigator : (UiComponent ) -> Unit = {}
30
30
) {
31
31
when (this ) {
32
32
is TextUi -> ConsumeTextUi (textUi = this , modifier = modifier, version = version)
33
- is ImageUi -> ConsumeImageUi (imageUi = this , modifier = modifier, version = version)
33
+ is ImageUi -> ConsumeImageUi (
34
+ imageUi = this ,
35
+ modifier = modifier,
36
+ version = version,
37
+ navigator = navigator
38
+ )
39
+
34
40
is ListUi -> ConsumeList (
35
41
listUi = this ,
36
42
modifier = modifier,
37
43
version = version,
38
- onListItemClicked = onListItemClicked
44
+ onListItemClicked = navigator
39
45
)
40
46
41
47
else -> ConsumeDefaultUi (uiComponent = this , version = version)
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Designed and developed by 2024 skydoves (Jaewoong Eum)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package io.getstream.server.driven.core.model
17
+
18
+ import androidx.compose.runtime.Immutable
19
+ import kotlinx.serialization.Serializable
20
+
21
+ @Immutable
22
+ @Serializable
23
+ data class Handler (
24
+ val type : String ,
25
+ val actions : Map <String , String >
26
+ )
27
+
28
+ enum class HandlerType (val value : String ) {
29
+ CLICK (" click" )
30
+ }
31
+
32
+ enum class HandlerAction (val value : String ) {
33
+ NAVIGATION (" navigation" )
34
+ }
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ data class ImageUi(
24
24
val title : String = " " ,
25
25
val url : String ,
26
26
val size : DpSizeUi = DpSizeUi (0, 0),
27
- val scaleType : String
27
+ val scaleType : String ,
28
+ val handler : Handler ? = null
28
29
) : UiComponent {
29
30
30
31
fun toTextUi (
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ data class ListUi(
25
25
val layout : String ,
26
26
val itemSize : DpSizeUi ,
27
27
val items : List <ImageUi >,
28
+ val handler : Handler ? = null ,
28
29
val extra : Map <String , JsonElement > = mapOf()
29
30
) : UiComponent
30
31
Original file line number Diff line number Diff line change 16
16
package io.getstream.server.driven.feature.timeline
17
17
18
18
import androidx.compose.foundation.background
19
- import androidx.compose.foundation.clickable
20
19
import androidx.compose.foundation.layout.Arrangement
21
20
import androidx.compose.foundation.layout.Box
22
21
import androidx.compose.foundation.layout.Column
@@ -36,7 +35,6 @@ import io.getstream.server.driven.core.designsystem.consumer.Consume
36
35
import io.getstream.server.driven.core.designsystem.preview.DefaultPreview
37
36
import io.getstream.server.driven.core.designsystem.preview.MockUtils
38
37
import io.getstream.server.driven.core.designsystem.theme.ServerDrivenTheme
39
- import io.getstream.server.driven.core.model.ImageUi
40
38
import io.getstream.server.driven.core.model.ScreenUi
41
39
import io.getstream.server.driven.core.model.UiComponent
42
40
@@ -73,16 +71,9 @@ private fun ServerDrivenTimelineContent(
73
71
verticalArrangement = Arrangement .spacedBy(12 .dp)
74
72
) {
75
73
timelineUi.components.forEach { uiComponent ->
76
- val modifier = if (uiComponent is ImageUi ) {
77
- Modifier .clickable { navigateToDetails.invoke(uiComponent) }
78
- } else {
79
- Modifier
80
- }
81
-
82
74
uiComponent.Consume (
83
- modifier = modifier,
84
75
version = timelineUi.version,
85
- onListItemClicked = { clickedComponent ->
76
+ navigator = { clickedComponent ->
86
77
navigateToDetails.invoke(clickedComponent)
87
78
}
88
79
)
You can’t perform that action at this time.
0 commit comments