-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDividerView.kt
More file actions
73 lines (63 loc) · 2.51 KB
/
Copy pathDividerView.kt
File metadata and controls
73 lines (63 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package expo.modules.jetpackcomposereactnative.views.divider
import android.content.Context
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.compose.material3.DividerDefaults
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.unit.dp
import androidx.core.graphics.toColorInt
import expo.modules.jetpackcomposereactnative.common.ModifierProp
import expo.modules.jetpackcomposereactnative.common.toModifier
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.views.ExpoView
data class DividerProps(
var direction: String = "horizontal",
var thickness: Double? = null,
var color: String? = null,
var modifier: ModifierProp = emptyList()
)
class DividerView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(DividerProps())
private val onDividerClick by EventDispatcher()
init {
ComposeView(context).also {
it.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT) // Allow the content to wrap
it.setContent {
DividerComposable(props = props.value)
}
addView(it)
}
}
fun updateThickness(thickness: Double?) {
props.value = props.value.copy(thickness = thickness)
}
fun updateModifier(modifier: ModifierProp) {
props.value = props.value.copy(modifier = modifier)
}
fun updateColor(color: String?) {
props.value = props.value.copy(color = color)
}
fun updateDirection(direction: String) {
props.value = props.value.copy(direction = direction)
}
}
@Composable
fun DividerComposable(props: DividerProps) {
when(props.direction) {
"horizontal" -> HorizontalDivider(
thickness = props.thickness?.dp ?: DividerDefaults.Thickness,
color = props.color?.toColorInt()?.let { Color(it) } ?: DividerDefaults.color,
modifier = props.modifier.toModifier()
)
"vertical" -> VerticalDivider(
thickness = props.thickness?.dp ?: DividerDefaults.Thickness,
color = props.color?.toColorInt()?.let { Color(it) } ?: DividerDefaults.color,
modifier = props.modifier.toModifier()
)
}
}