ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

FragNavController.onSaveInstanceState not triggering TransactionListener when restoring previous tab #200

Closed erawhctim closed 5 years ago

erawhctim commented 5 years ago

(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.

ncapdevi commented 5 years ago

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?

erawhctim commented 5 years ago

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

ncapdevi commented 5 years ago

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

erawhctim commented 5 years ago

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

ncapdevi commented 5 years ago

Yeah that would be great!

ncapdevi commented 5 years ago

Fixed in 3.2.0 #204