ncapdevi/FragNav

FragNavController.onSaveInstanceState not triggering TransactionListener when restoring previous tab

erawhctim opened this issue · 6 comments

(version 3.1.0)

Calling FragNavController.onSaveInstanceState doesn't work as expected and initialize doesn't restore the previously selected tab.

The code is running, it just seems like it wasn't designed as I expected the "tab restore" flow to work.

I'm testing this via the "Don't keep activities" developer setting on the device. If I selected tab 3 of 5 (default is 1), then launch another activity and then press back, the first activity's state is saved via onSaveInstanceState, then it is restored in onCreate and the saved state is passed into FragNavController.initialize - all of this is working.

However, FragNavController.restoreFromBundle doesn't pre-select the previous tab that was saved. The private restoreFromBundle restores fragmentStacksTags and the currentStackIndex value properly, but I would expect it to also select the tab index and notify the TransactionListener so I can update my UI according to the pre-selected previous tab that was reloaded from the saved state.

Is this expected behavior? I'm using a fork and have updated this so its not an issue at the moment, but it seems like a miss.

Your expectations seem correct to me. So to clarify, the state itself is actually being restored via the bundle, but the callback for the tabIndex isn't being called, correct?

Exactly. The code looks like it triggers the FragNavTabHistoryController, but I was expecting it to also call my custom TransactionListener to notify of the restored tab

Yeah, I think it makes sense to call the TransactionListener as well, should be an easy fix.

@ncapdevi Great! If you want, I can try and get a PR up for you for that fix today or tomorrow.

Yeah that would be great!

Fixed in 3.2.0 #204