diff --git a/core/src/main/java/me/liam/support/ExtraTransaction.java b/core/src/main/java/me/liam/support/ExtraTransaction.java index 2b0517d..f619aae 100644 --- a/core/src/main/java/me/liam/support/ExtraTransaction.java +++ b/core/src/main/java/me/liam/support/ExtraTransaction.java @@ -22,6 +22,11 @@ public abstract class ExtraTransaction { public abstract ExtraTransaction setCustomerAnimations(int enterAnim,int exitAnim,int popEnterAnim,int popExitAnim); + /** + * 不展示pop动画,仅能生效一次,不影响其他事件 + * @param dontDisplaySelfPopAnim + * @return + */ public abstract ExtraTransaction dontDisplaySelfPopAnim(boolean dontDisplaySelfPopAnim); public abstract ExtraTransaction setResult(int resultCode, Bundle data); @@ -111,18 +116,21 @@ public ExtraTransaction setResult(int resultCode, Bundle data) { @Override public ExtraTransaction displayEnterAnim(boolean displayEnterAnim) { record.displayEnterAnim = displayEnterAnim; + getArguments(from).putBoolean(SupportTransaction.FRAGMENTATION_PLAY_ENTER_ANIM,record.displayEnterAnim); return this; } @Override public ExtraTransaction setTag(String tag) { record.tag = tag; + getArguments(from).putString(SupportTransaction.FRAGMENTATION_TAG,record.tag); return this; } @Override public ExtraTransaction addBackStack(boolean addBackStack) { record.addBackStack = addBackStack; + getArguments(from).putBoolean(SupportTransaction.FRAGMENTATION_BACK_STACK,record.addBackStack); return this; } diff --git a/core/src/main/java/me/liam/support/SupportFragment.java b/core/src/main/java/me/liam/support/SupportFragment.java index a423246..fbbcbd5 100644 --- a/core/src/main/java/me/liam/support/SupportFragment.java +++ b/core/src/main/java/me/liam/support/SupportFragment.java @@ -98,10 +98,19 @@ public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { if (!getArguments().getBoolean(SupportTransaction.FRAGMENTATION_PLAY_ENTER_ANIM)){ animation = AnimationUtils.loadAnimation(getContext(),R.anim.anim_empty); }else { - SupportFragment beforeOne = FragmentUtils.getBeforeOne(getFragmentManager(),this); + final SupportFragment beforeOne = FragmentUtils.getBeforeOne(getFragmentManager(),this); animation = AnimationUtils.loadAnimation(getContext(),fragmentAnimation.getEnterAnimId()); if (beforeOne != null){ - beforeOne.onCreatePopAnimations(false); + if (getArguments().getBoolean(SupportTransaction.FRAGMENTATION_DONT_DISPLAY_SELF_POP_ANIM)){ + getHandler().postDelayed(new Runnable() { + @Override + public void run() { + beforeOne.onSupportPause(); + } + },animation.getDuration()); + }else { + beforeOne.onCreatePopAnimations(false); + } } } getHandler().postDelayed(new Runnable() { @@ -120,7 +129,11 @@ public void run() { if (!enter){ SupportFragment show = FragmentUtils.getLastActiveFragment(getFragmentManager()); if (show != null){ - show.onCreatePopAnimations(true); + if (getArguments().getBoolean(SupportTransaction.FRAGMENTATION_DONT_DISPLAY_SELF_POP_ANIM)){ + show.onSupportResume(); + }else { + show.onCreatePopAnimations(true); + } } animation = AnimationUtils.loadAnimation(getContext(),fragmentAnimation.getExitAnimId()); } @@ -129,6 +142,30 @@ public void run() { return animation; } + public void onCreatePopAnimations(boolean popEnter){ + Animation animation; + if (popEnter){ + animation = AnimationUtils.loadAnimation(getContext(),fragmentAnimation.getPopEnterAnimId()); + getHandler().postDelayed(new Runnable() { + @Override + public void run() { + onSupportResume(); + } + },animation.getDuration()); + }else { + animation = AnimationUtils.loadAnimation(getContext(),fragmentAnimation.getPopExitAnimId()); + getHandler().postDelayed(new Runnable() { + @Override + public void run() { + onSupportPause(); + } + },animation.getDuration()); + } + if (getView() != null){ + getView().startAnimation(animation); + } + } + @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); @@ -154,38 +191,6 @@ public void onDestroyView() { super.onDestroyView(); } - public void onCreatePopAnimations(boolean popEnter){ - if (getArguments().getBoolean(SupportTransaction.FRAGMENTATION_DONT_DISPLAY_SELF_POP_ANIM)){ - if (popEnter){ - onSupportResume(); - }else { - onSupportPause(); - } - return; - } - Animation animation; - if (popEnter){ - animation = AnimationUtils.loadAnimation(getContext(),fragmentAnimation.getPopEnterAnimId()); - getHandler().postDelayed(new Runnable() { - @Override - public void run() { - onSupportResume(); - } - },animation.getDuration()); - }else { - animation = AnimationUtils.loadAnimation(getContext(),fragmentAnimation.getPopExitAnimId()); - getHandler().postDelayed(new Runnable() { - @Override - public void run() { - onSupportPause(); - } - },animation.getDuration()); - } - if (getView() != null){ - getView().startAnimation(animation); - } - } - public boolean isSavedInstance(){ return getArguments().getBoolean(SupportTransaction.FRAGMENTATION_SAVED_INSTANCE,false); } @@ -280,6 +285,7 @@ public FragmentAnimation onCreateCustomerAnimation() { /** * 懒加载 + * 用于FragmentPager中时请使用最新的FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT方式创建适配器 * @param savedInstanceState */ @Override @@ -326,6 +332,7 @@ public void onSwipeDrag(SupportFragment beforeOne, int state, float scrollPercen beforeOne.getView().setX((1.0f - scrollPercent) * startX); if (state == SwipeBackLayout.STATE_IDLE && scrollPercent == 0){ beforeOne.getView().setX(0); + ((SupportActivity)getActivity()).fragmentSwipeDrag = false; } } diff --git a/demo/src/main/java/wechat/MineFragment.java b/demo/src/main/java/wechat/MineFragment.java index 8131893..53d6421 100644 --- a/demo/src/main/java/wechat/MineFragment.java +++ b/demo/src/main/java/wechat/MineFragment.java @@ -44,11 +44,16 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (getChildFragmentManager().getFragments().size() > 10){ - popAllChild(); - }else { - loadRootFragment(R.id.mine_childContainer,SettingsFragment.newInstance(),new ClassicVerticalAnim(),true,true); - } +// if (getChildFragmentManager().getFragments().size() > 10){ +// popAllChild(); +// }else { +// loadRootFragment(R.id.mine_childContainer,SettingsFragment.newInstance(),new ClassicVerticalAnim(),true,true); +// } + ((RootFragment)getParentFragment()).getExtraTransaction() + .dontDisplaySelfPopAnim(true) + .setCustomerAnimations(R.anim.classic_vertical_enter,R.anim.classic_vertical_exit) + .start(SettingsFragment.newInstance()); + } }); profile.setOnClickListener(new View.OnClickListener() {