Guys I'm having the worse time with compose. Need ...
# compose
s
Guys I'm having the worse time with compose. Need an opinion. I have a lazy column. With complex nested objects. One of them is a list of cards. Which has its own inner children. Problem is. One of these cards has a timer (Simple Text composable) and every time I update it from VM it requests focus and auto scrolls to itself 🤔 Problem is.. I took the same code to another fresh project. Didn't face any issues :) Difference is in modules probably. New project is 1 and main is mannny
z
Are you using the same version of compose in both?
s
Yup.
I made sure keys were stable, I even used keys in my inner loops. I also made sure recomposition is happening at text composable level
It's been driving me insane for 2 days lol
z
Hm, maybe add a focus listener and put a breakpoint in it, see what's triggering the focus call?
👍 1
s
Here recomposition is only happpening in the text composable Yet auto focuses when i scroll past this in one of my cards which has this, and it ticks
Copy code
@Composable
fun TimerDisplay(startTime: Long) {
var lastDay by remember { mutableIntStateOf(0) }
var lastHour by remember { mutableIntStateOf(0) }
var lastMinute by remember { mutableIntStateOf(0) }
var lastSecond by remember { mutableIntStateOf(0) }
LaunchedEffect(startTime) {
while (isActive) {
val time = startTime.getDaysHoursMinsSecsBetweenTodayAndProvidedDate()
lastDay = time.getOrNull(0)?.toInt() ?: lastDay
lastHour = time.getOrNull(1)?.toInt() ?: lastHour
lastMinute = time.getOrNull(2)?.toInt() ?: lastMinute
lastSecond = time.getOrNull(3)?.toInt() ?: lastSecond
delay(1000L) // Updates every second
}
}
val dayString =
pluralStringResource(
id = R.plurals.line_consumption_day_title_android,
lastDay,
lastDay
)
val hoursString =
stringResource(
id = R.string.uptime_hour_min_sec,
lastHour,
lastMinute,
lastSecond
)
Row(modifier = Modifier.fillMaxWidth()) {
Text(
text = hoursString,
style = FontManager.defaultTextStyleBold14Sp,
modifier = Modifier.fillMaxWidth()
)
}
}
I did, i added onFocuseChanged{} to everything, + focusable(false)
still no luck. it's worth mentioning, this is hosted a fragment, I tried doing it withtout compose view and coardinater but same thing
I'll test that thanks
z
what's the stack trace inside the focus listener when this happens?
s
I made it only update every 4 seconds, to catch it scrolling, Break points on focuse changed, don't trigger
K Update I don't think there's anything wrong here
It must be my host fragment and XML, will update if fixed
It was XML related. Compose view parent was a constraint layout, which has also a parent of constraints layout.
It mostly affected the ui and looked glitchy if sizes are changing in the compose view suddenly, going over bounds etc.. expanding elements etc..
fixed by removing direct parent ^