@@ -26,6 +26,8 @@ public class VisibleDelegate {
2626 private boolean mInvisibleWhenLeave ;
2727 private boolean mIsFirstVisible = true ;
2828 private boolean mFirstCreateViewCompatReplace = true ;
29+ private boolean mAbortInitVisible = false ;
30+ private Runnable taskDispatchSupportVisible ;
2931
3032 private Handler mHandler ;
3133 private Bundle mSaveInstanceState ;
@@ -61,6 +63,10 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
6163 mFirstCreateViewCompatReplace = false ;
6264 }
6365
66+ initVisible ();
67+ }
68+
69+ private void initVisible () {
6470 if (!mInvisibleWhenLeave && !mFragment .isHidden () && mFragment .getUserVisibleHint ()) {
6571 if ((mFragment .getParentFragment () != null && isFragmentVisible (mFragment .getParentFragment ()))
6672 || mFragment .getParentFragment () == null ) {
@@ -76,10 +82,21 @@ public void onResume() {
7682 mNeedDispatch = false ;
7783 dispatchSupportVisible (true );
7884 }
85+ } else {
86+ if (mAbortInitVisible ) {
87+ mAbortInitVisible = false ;
88+ initVisible ();
89+ }
7990 }
8091 }
8192
8293 public void onPause () {
94+ if (taskDispatchSupportVisible != null ) {
95+ getHandler ().removeCallbacks (taskDispatchSupportVisible );
96+ mAbortInitVisible = true ;
97+ return ;
98+ }
99+
83100 if (mIsSupportVisible && isFragmentVisible (mFragment )) {
84101 mNeedDispatch = false ;
85102 mInvisibleWhenLeave = false ;
@@ -92,7 +109,7 @@ public void onPause() {
92109 public void onHiddenChanged (boolean hidden ) {
93110 if (!hidden && !mFragment .isResumed ()) {
94111 //if fragment is shown but not resumed, ignore...
95- mInvisibleWhenLeave = false ;
112+ onFragmentShownWhenNotResumed () ;
96113 return ;
97114 }
98115 if (hidden ) {
@@ -102,6 +119,23 @@ public void onHiddenChanged(boolean hidden) {
102119 }
103120 }
104121
122+ private void onFragmentShownWhenNotResumed () {
123+ mInvisibleWhenLeave = false ;
124+ dispatchChildOnFragmentShownWhenNotResumed ();
125+ }
126+
127+ private void dispatchChildOnFragmentShownWhenNotResumed () {
128+ FragmentManager fragmentManager = mFragment .getChildFragmentManager ();
129+ List <Fragment > childFragments = FragmentationMagician .getActiveFragments (fragmentManager );
130+ if (childFragments != null ) {
131+ for (Fragment child : childFragments ) {
132+ if (child instanceof ISupportFragment && !child .isHidden () && child .getUserVisibleHint ()) {
133+ ((ISupportFragment ) child ).getSupportDelegate ().getVisibleDelegate ().onFragmentShownWhenNotResumed ();
134+ }
135+ }
136+ }
137+ }
138+
105139 public void onDestroyView () {
106140 mIsFirstVisible = true ;
107141 }
@@ -126,12 +160,14 @@ private void safeDispatchUserVisibleHint(boolean visible) {
126160 }
127161
128162 private void enqueueDispatchVisible () {
129- getHandler (). post ( new Runnable () {
163+ taskDispatchSupportVisible = new Runnable () {
130164 @ Override
131165 public void run () {
166+ taskDispatchSupportVisible = null ;
132167 dispatchSupportVisible (true );
133168 }
134- });
169+ };
170+ getHandler ().post (taskDispatchSupportVisible );
135171 }
136172
137173 private void dispatchSupportVisible (boolean visible ) {
0 commit comments