jasu
06/22/2022, 9:49 AMAndroidView(
factory = {
CropImageView(it).apply {
setCenterMoveEnabled(true)
setSnapRadius(16f)
setBackgroundColor(Color.Black.toArgb())
with(density) {
layoutParams = ViewGroup.LayoutParams(maxWidth.roundToPx(), maxHeight.roundToPx())
}
}
},
update = { cropView ->
// how to call cropView.rotateImage(90) }
)
myanmarking
06/22/2022, 10:39 AMjasu
06/22/2022, 10:41 AMjasu
06/22/2022, 10:42 AMmyanmarking
06/22/2022, 10:43 AMmyanmarking
06/22/2022, 10:43 AMjasu
06/22/2022, 10:44 AMmyanmarking
06/22/2022, 10:46 AM@Composable
fun MainComposable(){
var rotation by remember{mutableStateOf(90)}
MyAndroidView(rotation)
// somewhere around here, you have a lambda with a click
// just call rotation = otherValue
}
@Composable
fun MyAndroidView(rotation: Float){
AndroidView(
factory = {
CropImageView(it).apply {
setCenterMoveEnabled(true)
setSnapRadius(16f)
setBackgroundColor(Color.Black.toArgb())
with(density) {
layoutParams = ViewGroup.LayoutParams(maxWidth.roundToPx(), maxHeight.roundToPx())
}
}
},
update = { cropView ->
cropView.rotateImage(rotation) }
)
}
jasu
06/22/2022, 10:47 AMmyanmarking
06/22/2022, 10:47 AMmyanmarking
06/22/2022, 10:50 AMjasu
06/22/2022, 10:51 AMmyanmarking
06/22/2022, 10:52 AMjasu
06/22/2022, 10:56 AMmyanmarking
06/22/2022, 10:57 AMenum class CropState {
START,
END,
NONE
}
@Composable
fun MainComposable() {
var rotation by remember {
mutableStateOf(90f)
}
var scropState by remember {
mutableStateOf(CropState.NONE)
}
MyAndroidView(
rotation = rotation,
cropState = scropState
)
// somewhere here updated rotation
// somewhere here change your cropState
}
@Composable
fun MyAndroidView(
modifier: Modifier = Modifier,
rotation: Float,
cropState: CropState
) {
AndroidView(
factory = { context ->
// your view here
View(context)
},
update = {
// some property updated
when (cropState) {
CropState.START -> TODO()
CropState.END -> TODO()
CropState.NONE -> TODO()
}
},
modifier = modifier
)
}
jasu
06/22/2022, 11:00 AMmyanmarking
06/22/2022, 11:02 AMmyanmarking
06/22/2022, 11:03 AMandrew
06/22/2022, 6:40 PMjasu
06/23/2022, 5:07 PMandrew
06/23/2022, 5:10 PMandrew
06/23/2022, 5:12 PMandrew
06/23/2022, 5:14 PMandrew
06/23/2022, 5:14 PMandrew
06/23/2022, 5:15 PMandrew
06/23/2022, 5:22 PM@Composable
fun CropView(
centerMoveEnabled: Boolean = true,
snapRadius: Float: 16F,
rotation: Float = 0F,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val view = remember { CropImageView(context) }
AndroidView(
modifier = Modifier,
factory = { view },
update = { view ->
view.setCenterMoveEnabled(centerMoveEnabled)
view.setSnapRadius(snapRadius)
view.rotateImage(rotation)
// or if rotate is based on a delta
// view.rotateImage(rotation - view.rotation)
}
)
}
andrew
06/23/2022, 5:23 PMandrew
06/23/2022, 5:23 PMjasu
06/23/2022, 5:25 PM