Ian Warwick
12/31/2019, 11:21 AMRouter
pattern for a single activity approach using compose where you can specify URI routings to compositions - you can do something like this in your single activity
class MainActivity : AppCompatActivity() {
private val router = Router(this) {
schemes("https", "http")
hosts("<http://memset.com|memset.com>", "<http://www.memset.com|www.memset.com>")
"/" composeWith { HomeScreenComposer() }
"/cardeditor" composeWith { CardEditorScreenComposer(model(CardEditorViewModel::class)) }
".*" composeTo { Text("404 Not Found") }
}.startAt("<https://memset.com/>")
}
Then later in your composition you can get at the router using an ambient
val router = +ambient(ActiveRouter)
And navigate to another composition
router.goto("<http://memset.com/anywhere>")
The problem is that if I get at the ambient inside an onClick
listener since the listener is not @Composable() () -> Unit
I get an error composition requires an active composition context
Declaring the ambient ref outside the click listener works fine, before I was passing around router: Router
to functions though learned about Ambient and thought why not try 😆 seems quite cool is it the right way to go for this sort of thing? apologies if the question is not relevant here, full source here:- https://github.com/fluxtah/memsetAdam Powell
12/31/2019, 2:56 PMIan Warwick
12/31/2019, 3:30 PMonClick
listeners @Composable
or is it just an anti-pattern to reference with +ambient(...)
in an onClick
listener?Adam Powell
12/31/2019, 3:31 PMIan Warwick
12/31/2019, 3:32 PM