Compose interop bug? AndroidView does not get redrawn on Android 25 and lower

Viewed 168

I tried implementing a screen using Compose, but I had a custom Android View that don't fancy reimplementing in Compose yet. Think of it as a chessboard (but it's for the game of GO instead). I have the following code:

            val context = AmbientContext.current
            val boardView = remember {
                BoardView(context).apply {
                    onTapMove = { listener(BoardCellHovered(it)) }
                    onTapUp = { listener(BoardCellTapped(it)) }
                    drawCoordinates = true
                    drawMarks = true
                    drawLastMove = true
                }
            }
            AndroidView({ boardView },
                    modifier = Modifier
                            .padding(12.dp)
                            .shadow(6.dp, MaterialTheme.shapes.large)
            ) { view ->
                view.apply {
                    boardSize = state.position?.boardSize ?: 9
                    position = state.position
                    isInteractive = state.boardInteractive
                    showCandidateMove(state.hoveredCell, StoneType.BLACK)
                }
            }

The last line triggers an invalidate. This works just fine on Android 29, but if I try it in an Android 25 (or lower) emulator, the view gets drawn ONCE and then never gets redrawn, even if the update block does get called.

Is there a workaround to this problem?

full code available at https://github.com/acristescu/OnlineGo/blob/9630a61a00e84c5a455bf230c406b1914da4c9b5/app/src/main/java/io/zenandroid/onlinego/ui/screens/tutorial/TutorialFragment.kt

0 Answers
Related