OneBottomNavigationBar icon indicating copy to clipboard operation
OneBottomNavigationBar copied to clipboard

有机会适配下androidX的Fragment切换

Open phoenixsky opened this issue 2 years ago • 0 comments

androidX的fragment已经不需要用setUserHint方法了

On the new version of androidx.fragment (from 1.1.0+), Fragment.setUserVisibleHint will still get called if your FragmentStatePagerAdapter is using the old behavior, specified by BEHAVIOR_SET_USER_VISIBLE_HINT.

If you have constructed your FragmentStatePagerAdapter and passed BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, then Fragment.setUserVisibleHint will no longer be called inside FragmentStatePagerAdapter.instantiateItem.

NOTE: you can still call the deprecated Fragment.getUserVisibleHint if you have specified BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT in your FragmentStatePagerAdapter, but be advised that it will return true even though Fragment.isResumed() will return false.

新版本的fragment切换可以直接采用onResume来判断是否显示,但是需要在切换fragment时 加入以下代码

setMaxLifecycle(fragment, Lifecycle.State.RESUMED);

If you are manually calling this method, use FragmentTransaction.setMaxLifecycle(Fragment, Lifecycle.State) instead. If overriding this method, behavior implemented when passing in true should be moved to onResume(), and behavior implemented when passing in false should be moved to onPause().

phoenixsky avatar Aug 21 '21 16:08 phoenixsky