I have an app where the navigation is on some occa...
# compose-wear
g
I have an app where the navigation is on some occasions controlled by the state of a ForegroundService. At the moment, to make the screen navigate on a change to the state held in the Service, I use a
LaunchedEffect
that sits outside of the
NavHost
. You can see this here: https://github.com/garanj/wearwind/blob/main/app/src/main/java/com/garan/wearwind/FanActivity.kt#L115 So when the watch successfully connects to the fan, the screen transitions to the Connected screen, but it avoids the situation where when the user swipes back from the Connected screen they may hit the Connect screen but bounce back to the Connected screen as the fan hasn't disconnected yet... but is this a bad idea to have this navigation logic here? I've been trying to have it within each screen but with no success yet.
j
@Steve Bower [G] maybe you can provide some input here
g
Thanks John! Actually it does seem to be working well using the navigation within each screen, which I'm hoping is what Steve mentioned the other day! I may have misinterpreted! Just need to sort the case of handling both a swipe back from connected screen (currently using a DisposableEffect) but also a disconnection triggered by the fan not the user. Currently the DisposableEffect always triggers, swipe or not, which isn't what I want.
y
This came up in a code review and one reason I suggested asking was related to doing work in LaunchedEffect that might interfere with deeplinks (if there were some). So wondering if there is some playbook for these types of automatic navigation events.
@Garan Jenkin I was chatting with @Steve Bower [G] it would be interesting to know whether you can faithfully achieve some of your constraint layouts using box, column and row. Steve pointed out the weight modifiers which let you achieve effects like pinning some content to the bottom.
Mainly because I find the constraint layouts really hard to reason about read at a glance, and I'm curious whether there is something missing that means we should expect to see a lot of them in real world apps?
j
IMHO you will get way better mileage without ConstraintLayout in Compose, especially on Wear. Would be interested to see any use cases that folks have that really lend themselves to using CL on Wear and see if we can't do them better with more fundamental Compose layout components.
g
I'll move away from it 👍