gyf-dev / gyf-dev/ImmersionBar

使用viewpager2+fragment时,沉浸式失效

Open
#473 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
11.5k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

如题,使用viewpager2+fragment时,viewpager2使用FragmentStateAdapter,fragment生命周期不走setUserVisibleHint,在onResume和onPause中处理也不行。

但是当应用从后台返回前台后,沉浸式生效。

//失效
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
"setUserVisibleHint----${isVisibleToUser}".loge()
mImmersionProxy.isUserVisibleHint = isVisibleToUser
}

override fun onResume() {
    mImmersionProxy.isUserVisibleHint = true
    super.onResume()
    mImmersionProxy.onResume()

}

override fun onPause() {
    mImmersionProxy.isUserVisibleHint = false
    super.onPause()
    mImmersionProxy.onPause()

}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using ViewPager2 with FragmentStateAdapter and inspect the fragment entry points shown: setUserVisibleHint, onResume, and onPause. Verify immersive mode behavior during page changes and after returning from the background; done means the correct fragment consistently applies immersive mode without relying on the app returning to the foreground.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.