MFlisar / ComposePreferences

Compose Preference Screen for Android - Material3 Design (including customisation, nesting and more)
Apache License 2.0
8 stars 0 forks source link

PreferenceSubScreen and Parent Scaffold appBar #3

Closed jscti closed 8 months ago

jscti commented 8 months ago

Hi There

My SettingScreen is based on a Scaffold with :

On a "Back" gesture : everything is OK, opened PreferenceSubScreen gets closed first, then my SettingScreen But clicking on my Scaffold Back-button closes directly my SettingScreen without closing the opened PreferenceSubScreen first

Is there a way to fix that ?


Not related but could it be possible to enable/disable the logs of your libs which are quite verbous ^^

Thanks :)

MFlisar commented 8 months ago

How about trying to use onBackPressedDispatcher.onBackPressed() (I just googled it, it seems to do what you need to do, I did not need it myself yet)?

You somehow must tell the compose system that you want to emulate a back press so that it can decide which BackHandler is currently the most inner one that wants to handle a back press... Your code simply ignores the BackHandlers and tells the navController to pop the back stack, which it of course will do...

jscti commented 8 months ago

Hey thanks

Got it working like you said, my Scaffold BackButton now triggers a "BackPress" and let BackHandlers do their job.

val dispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher + Scaffold onBackButton : dispatcher.onBackPressed()

For the "log" thing, do you think it's possible to "mute" them ? Need a separate issue to close this one ?

Thanks ;)

MFlisar commented 8 months ago

I removed the last log line, I did only find one though...