, which will run even when an exception was thrown or the coroutine was cancelled.
a
Andy Himberger
03/01/2023, 4:52 AM
I was finding I had to use invokeOnCompletion myself too so I can run my onDismissRequest logic, as the m3 bottomsheet wasn't calling it for me when I did a hide() from a backhandler (which is also odd that I had to setup my own backhandler to close bottomsheets on back button). though that was alpha06 haven't seen if alpha07 changed things there
j
jossiwolf
03/01/2023, 7:37 AM
Keep in mind that coroutines can be cancelled. If the animation gets interrupted for any reason, you'll still want to remove the sheet from composition if it went to the hidden state. In your code, you are launching a coroutine in which you call hide, a suspend function. If it gets cancelled, the whole coroutine will get cancelled too and you'll never reach the if. invokeOnCompletion on the job and try/finally around the hide call are equivalent for this use case, so it's up to preference
jossiwolf
03/01/2023, 7:38 AM
@Andy Himberger M3 sheets have a back handler, you don't need your own. Please file an issue if anything is not working as expected:)