Skip to content

Commit 59b649f

Browse files
committed
#766, restore rootView's clickable status
1 parent 6daa61e commit 59b649f

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class SupportFragmentDelegate {
3535
FragmentAnimator mFragmentAnimator;
3636
AnimatorHelper mAnimHelper;
3737
boolean mLockAnim;
38-
private int mCustomEnterAnim = Integer.MIN_VALUE, mCustomExitAnim = Integer.MIN_VALUE;
38+
private int mCustomEnterAnim = Integer.MIN_VALUE, mCustomExitAnim = Integer.MIN_VALUE, mCustomPopExitAnim = Integer.MIN_VALUE;
3939

4040
private Handler mHandler;
4141
private boolean mFirstCreateView = true;
@@ -57,6 +57,8 @@ public class SupportFragmentDelegate {
5757
boolean mAnimByActivity = true;
5858
EnterAnimListener mEnterAnimListener;
5959

60+
private boolean mRootViewClickable;
61+
6062
public SupportFragmentDelegate(ISupportFragment support) {
6163
if (!(support instanceof Fragment))
6264
throw new RuntimeException("Must extends Fragment");
@@ -96,6 +98,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
9698
mReplaceMode = bundle.getBoolean(TransactionDelegate.FRAGMENTATION_ARG_REPLACE, false);
9799
mCustomEnterAnim = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CUSTOM_ENTER_ANIM, Integer.MIN_VALUE);
98100
mCustomExitAnim = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CUSTOM_EXIT_ANIM, Integer.MIN_VALUE);
101+
mCustomPopExitAnim = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CUSTOM_POP_EXIT_ANIM, Integer.MIN_VALUE);
99102
}
100103

101104
if (savedInstanceState == null) {
@@ -164,18 +167,17 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
164167

165168
View view = mFragment.getView();
166169
if (view != null) {
170+
mRootViewClickable = view.isClickable();
167171
view.setClickable(true);
168172
setBackground(view);
169173
}
170174

175+
171176
if (savedInstanceState != null
172177
|| mRootStatus == STATUS_ROOT_ANIM_DISABLE
173178
|| (mFragment.getTag() != null && mFragment.getTag().startsWith("android:switcher:"))
174179
|| (mReplaceMode && !mFirstCreateView)) {
175180
notifyEnterAnimEnd();
176-
} else if (mCustomEnterAnim != Integer.MIN_VALUE) {
177-
fixAnimationListener(mCustomEnterAnim == 0 ?
178-
mAnimHelper.getNoneAnim() : AnimationUtils.loadAnimation(_mActivity, mCustomEnterAnim));
179181
}
180182

181183
if (mFirstCreateView) {
@@ -569,6 +571,22 @@ public void run() {
569571
public void run() {
570572
if (mFragment == null) return;
571573
mSupportF.onEnterAnimationEnd(mSaveInstanceState);
574+
575+
if (mRootViewClickable) return;
576+
final View view = mFragment.getView();
577+
if (view == null) return;
578+
ISupportFragment preFragment = SupportHelper.getPreFragment(mFragment);
579+
if (preFragment == null) return;
580+
581+
long prePopExitDuration = preFragment.getSupportDelegate().getPopExitAnimDuration();
582+
long enterDuration = getEnterAnimDuration();
583+
584+
mHandler.postDelayed(new Runnable() {
585+
@Override
586+
public void run() {
587+
view.setClickable(false);
588+
}
589+
}, prePopExitDuration - enterDuration);
572590
}
573591
};
574592

@@ -624,6 +642,22 @@ public FragmentActivity getActivity() {
624642
return _mActivity;
625643
}
626644

645+
public long getEnterAnimDuration() {
646+
if (mCustomEnterAnim == Integer.MIN_VALUE) {
647+
if (mAnimHelper != null && mAnimHelper.enterAnim != null) {
648+
return mAnimHelper.enterAnim.getDuration();
649+
}
650+
} else {
651+
try {
652+
return AnimationUtils.loadAnimation(_mActivity, mCustomEnterAnim).getDuration();
653+
} catch (Exception e) {
654+
e.printStackTrace();
655+
}
656+
657+
}
658+
return NOT_FOUND_ANIM_TIME;
659+
}
660+
627661
public long getExitAnimDuration() {
628662
if (mCustomExitAnim == Integer.MIN_VALUE) {
629663
if (mAnimHelper != null && mAnimHelper.exitAnim != null) {
@@ -640,6 +674,22 @@ public long getExitAnimDuration() {
640674
return NOT_FOUND_ANIM_TIME;
641675
}
642676

677+
public long getPopExitAnimDuration() {
678+
if (mCustomPopExitAnim == Integer.MIN_VALUE) {
679+
if (mAnimHelper != null && mAnimHelper.popExitAnim != null) {
680+
return mAnimHelper.popExitAnim.getDuration();
681+
}
682+
} else {
683+
try {
684+
return AnimationUtils.loadAnimation(_mActivity, mCustomPopExitAnim).getDuration();
685+
} catch (Exception e) {
686+
e.printStackTrace();
687+
}
688+
689+
}
690+
return NOT_FOUND_ANIM_TIME;
691+
}
692+
643693
interface EnterAnimListener {
644694
void onEnterAnimStart();
645695
}

fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TransactionDelegate {
4242
static final String FRAGMENTATION_ARG_REPLACE = "fragmentation_arg_replace";
4343
static final String FRAGMENTATION_ARG_CUSTOM_ENTER_ANIM = "fragmentation_arg_custom_enter_anim";
4444
static final String FRAGMENTATION_ARG_CUSTOM_EXIT_ANIM = "fragmentation_arg_custom_exit_anim";
45+
static final String FRAGMENTATION_ARG_CUSTOM_POP_EXIT_ANIM = "fragmentation_arg_custom_pop_exit_anim";
4546

4647
static final String FRAGMENTATION_STATE_SAVE_ANIMATOR = "fragmentation_state_save_animator";
4748
static final String FRAGMENTATION_STATE_SAVE_IS_HIDDEN = "fragmentation_state_save_status";
@@ -369,6 +370,7 @@ private void start(FragmentManager fm, final ISupportFragment from, ISupportFrag
369370
record.currentFragmentPopEnter, record.targetFragmentExit);
370371
args.putInt(FRAGMENTATION_ARG_CUSTOM_ENTER_ANIM, record.targetFragmentEnter);
371372
args.putInt(FRAGMENTATION_ARG_CUSTOM_EXIT_ANIM, record.targetFragmentExit);
373+
args.putInt(FRAGMENTATION_ARG_CUSTOM_POP_EXIT_ANIM, record.currentFragmentPopExit);
372374
} else {
373375
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
374376
}

0 commit comments

Comments
 (0)