-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathImageView.kt
More file actions
61 lines (52 loc) · 1.9 KB
/
Copy pathImageView.kt
File metadata and controls
61 lines (52 loc) · 1.9 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
package expo.modules.jetpackcomposereactnative.views.image
import android.content.Context
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.ComposeView
import coil3.compose.rememberAsyncImagePainter
import expo.modules.jetpackcomposereactnative.common.ModifierProp
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.views.ExpoView
import expo.modules.jetpackcomposereactnative.common.toModifier
data class ImageProps(
var source: String? = null,
var modifier: ModifierProp = emptyList(),
)
class ImageView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
private var props = mutableStateOf(ImageProps())
private var composeView: ComposeView? = null
init {
ComposeView(context).also {
it.layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT)
it.setContent {
ImageComposable(props = props.value)
}
addView(it)
composeView = it
}
}
// http://10.0.2.1:8081/assets/?unstable_path=.%2Fassets/gingerbread.webp?platform=android&hash=3e0202d3694da5a068df36861901ee00
fun updateSource(source: String) {
props.value = props.value.copy(source = source)
}
fun updateModifier(modifier: ModifierProp) {
props.value = props.value.copy(modifier = modifier)
}
}
@Composable
fun ImageComposable(props: ImageProps) {
props.source?.let {
val painter = rememberAsyncImagePainter(model = it)
Image(
painter = painter,
contentDescription = null,
modifier = props.modifier
.toModifier()
.fillMaxWidth()
.fillMaxWidth()
)
}
}