Status Update
Comments
il...@google.com <il...@google.com> #2
ja...@gopuff.com <ja...@gopuff.com> #3
je...@hq.bill.com <je...@hq.bill.com> #4
private void refreshAllLiveData() {
AppDataBase YOUR_DATABASE_WHICH_YOU_BUILD = .....
SupportSQLiteDatabase writableDatabase = YOUR_DATABASE_WHICH_YOU_BUILD.getOpenHelper().getWritableDatabase();
//get the database count;
Cursor cursor = writableDatabase.query("SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name != 'android_metadata' AND name != 'room_master_table';");
int tableCount = 0;
while(cursor.moveToNext()) {
tableCount = cursor.getInt(0);
}
for (int i = 0; i < tableCount; i++) {
//update version table with the incremented count because room modification log stores tables with ids instead of names
writableDatabase.execSQL("INSERT OR REPLACE INTO room_table_modification_log VALUES(null, "+(i)+")");
}
YOUR_DATABASE_WHICH_YOU_BUILD.getInvalidationTracker().refreshVersionsAsync();
}
-----
This is a workaroud for refreshing all live datas, I still prefer to use a proper API you implemented.
Thanx
ni...@gmail.com <ni...@gmail.com> #5
il...@google.com <il...@google.com> #6
If you have an 'overlay' (like the example above of controlling a drawer that sits semantically above the entire NavHost), you should be adding it to composition only when you want to start handling back (e.g., if (condition) BackHandler {}
rather than using the enabled
property). That, combined with the position after the NavHost
is how you ensure that your callback is the last to register.
Keep in mind that with BackHandler
when you are controlling part of the UI itself as explained in the BackHandler
to do logging or affect the back stack of something you do not own (e.g., you should never be calling navController.popBackStack()
in your own callback).
The PredictiveBackHandler
progress
to implement the Predictive Back gesture.
nk...@gmail.com <nk...@gmail.com> #7
If you have a drawer in Scaffold
in Material2, it doesn't work right.
I'm using androidx.compose.material:material:1.5.4
, which is from the latest Compose BOM.
originally I had something like
val coroutineScope = rememberCoroutineScope()
val scaffoldState = rememberScaffoldState()
BackHandler(enabled = scaffoldState.drawerState.isOpen) {
coroutineScope.launch { scaffoldState.drawerState.close() }
}
Scaffold(
scaffoldState = scaffoldState,
drawerContent = {
AppDrawer()
},
content = {
HomeScreen()
}
)
but i also tried
val coroutineScope = rememberCoroutineScope()
val scaffoldState = rememberScaffoldState()
Scaffold(
scaffoldState = scaffoldState,
drawerContent = {
BackHandler(true) {
coroutineScope.launch { scaffoldState.drawerState.close() }
}
AppDrawer()
},
content = {
HomeScreen()
}
)
Here the drawer is in the composition immediately because that is how Scaffold is implemented.
If I navigate to a few screens and then open up the drawer, then the NavHost
consumes the back press because it was last added to the composition and the drawer stays open until the backstack size gets to 1.
There's no way to disable this
ga...@wahoofitness.com <ga...@wahoofitness.com> #10
Is there any development on being able to configure the BackHandler
in the NavHost
? Our application also has this issue. Below is our navigation architecture:
| HorizontalPager (beyondBoundsPageCount == pages size) <-- This is key
| Tab 1..4
| Tab 5
| NavHost
Because each tab is composed, we have to track the 'active' tab as to enable/disable the tab's respective BackHandler
. However, if I am on tab 2 which is an Ionic Portal (web micro-front-end), when using the BackHandler
to handle navigation events, the NavHost
on tab 5 receives the events if the currentBackStack.size > 1
. We cannot move the BackHandler
to be after the NavHost
as it will make the BackHandler
's within each destination route not consumable.
In addition to this, if we move Tab 5 to a higher order position in the HorizontalPager
(say position 1 or 2), this issue does not occur. It's only happening when it's the 'last' tab in the pager. We cannot re-order our tab positions as this is a requirement from our Product Manager.
Furthermore, it would be helpful if the BackHandler
/PredictiveBackHandler
would check the NavController
's enableOnBackPressedCallback
. Seems like the simplest approach.
Description
Component used: Navigation
Version used: 2.7.4
This is related to the changes made for this issue where the use of
OnBackPressedDispatcher
in aNavHost
was replaced withBackHandler
.These changes effectively disabled the API that we relied on,
NavController::enableOnBackPressed(enabled: Boolean)
, which we used to disable back handling in the navigation library when e.g. the drawer menu was open and we wanted to handle back tap in such a case to close the menu.The menu drawer is part of a
Scaffold
thus imho it should be handled on that level, aboveNavHost
and screens navigated to.One way to allow similar behavior could be to add e.g.
backHandlerEnabled
new argument to a composableNavHost
function and update its related code as the following:The following is a simplified abstract of our code dealing with menu closing by tapping back:
P.S. We seem to have overcome this problem by moving our
BackHandler
to be called afterNavHost
. However we aren't sure the order of calls here is guaranteed (the order of addingOnBackPressedCallback
s).