ncapdevi / FragNav

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

Be able to setMaxLifecycle during the fragment transaction #248

Open kevinguitar opened 2 years ago

kevinguitar commented 2 years ago

Story

There's a known issue that if you use the hiding strategy on the fragment switch, the fragment's lifecycle won't be changed.

However, there's a new setMaxLifecycle function been added in the FragmentTransaction which can set the maximum lifecycle state during the transaction, and ViewPager2.FragmentStateAdapter actually has such implementation.

Bringing this function call to the library for the hiding strategy, so the fragment lifecycle will be triggered properly during switching.

What have been changed in this PR:

Related issue: https://github.com/ncapdevi/FragNav/issues/244

Original pull request: https://github.com/bandlab/FragNav/pull/2 coauthored by @gildor