diff --git a/README.md b/README.md index f07e8cc..49c6814 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ When displaying a new fragment there are multiple parameters that can be specifi * **`skipBackStack`**: specify whether this fragment will be added to the `FragmentManager` back stack or not. The default value for this is `false`. * **`clearBackStack`**: specify whether the `FragmentManager` backstack should be cleared before displaying this fragment. The default value used for this is `false`. * **`replaceCurrentFragment`**: specify whether this fragment should replace the fragment currently displayed inside the container or just be added over it. The default value used for this is `false`. -* **`enterAnim`** and **`exitAnim`**: animation resource ID for the enter and exit fragment animation. The default values used here are `R.anim.fragment_enter_anim` and `R.anim.fragment_exit_anim`. +* **`setCustomTransactionAnimation`**: specify `enterAnim` and `exitAnim` animation resource ID for the enter and exit fragment animation. The default values used here are `R.anim.fragment_enter_anim` and `R.anim.fragment_exit_anim`. +* **`setTransition`**: specify `transitionConfig` and `sharedElements` for adding custom transitions. For API >= 21, shared elements can also be passed between fragments. Make sure to add `android:transitionName` attribute to the shared views. finally after we have specified all the parameters we need we can simply call `displayFragment()` to display the fragment. diff --git a/flowr/src/main/java/com/fueled/flowr/Flowr.java b/flowr/src/main/java/com/fueled/flowr/Flowr.java index 555d0a8..a6fef8b 100644 --- a/flowr/src/main/java/com/fueled/flowr/Flowr.java +++ b/flowr/src/main/java/com/fueled/flowr/Flowr.java @@ -346,7 +346,7 @@ private void setTransitions(Fragment fragment, TransitionConfig transitionConfig fragment.setEnterTransition(transitionConfig.enter); fragment.setSharedElementEnterTransition(transitionConfig.sharedElementEnter); fragment.setExitTransition(transitionConfig.exit); - fragment.setSharedElementReturnTransition(transitionConfig.sharedElementExit); + fragment.setSharedElementReturnTransition(transitionConfig.sharedElementReturn); } /** diff --git a/flowr/src/main/java/com/fueled/flowr/internal/TransitionConfig.java b/flowr/src/main/java/com/fueled/flowr/internal/TransitionConfig.java index 1604990..1dd6c3e 100644 --- a/flowr/src/main/java/com/fueled/flowr/internal/TransitionConfig.java +++ b/flowr/src/main/java/com/fueled/flowr/internal/TransitionConfig.java @@ -1,13 +1,6 @@ package com.fueled.flowr.internal; -import android.os.Build; -import android.support.annotation.RequiresApi; -import android.transition.ChangeBounds; -import android.transition.Explode; -import android.transition.Fade; -import android.transition.Slide; import android.transition.Transition; -import android.view.Gravity; /** * Copyright (c) 2017 Fueled. All rights reserved. @@ -18,20 +11,20 @@ public class TransitionConfig { public Transition sharedElementEnter; - public Transition sharedElementExit; + public Transition sharedElementReturn; public Transition enter; public Transition exit; private TransitionConfig(Builder builder) { sharedElementEnter = builder.sharedElementEnter; - sharedElementExit = builder.sharedElementExit; + sharedElementReturn = builder.sharedElementReturn; enter = builder.enter; exit = builder.exit; } public static final class Builder { private Transition sharedElementEnter; - private Transition sharedElementExit; + private Transition sharedElementReturn; private Transition enter; private Transition exit; @@ -43,8 +36,8 @@ public Builder sharedElementEnter(Transition val) { return this; } - public Builder sharedElementExit(Transition val) { - sharedElementExit = val; + public Builder sharedElementReturn(Transition val) { + sharedElementReturn = val; return this; } @@ -62,13 +55,4 @@ public TransitionConfig build() { return new TransitionConfig(this); } } - - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) - public static class Provider { - public static Transition fade = new Fade(); - public static Transition explode = new Explode(); - public static Transition slideRight = new Slide(Gravity.RIGHT); - public static Transition slideLeft = new Slide(Gravity.LEFT); - public static Transition changeBounds = new ChangeBounds(); - } } diff --git a/sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java b/sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java index cd515e9..ee97920 100644 --- a/sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java +++ b/sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java @@ -3,6 +3,9 @@ import android.databinding.DataBindingUtil; import android.os.Build; import android.support.annotation.NonNull; +import android.transition.ChangeBounds; +import android.transition.Fade; +import android.transition.Transition; import android.view.View; import com.fueled.flowr.NavigationIconType; @@ -72,7 +75,7 @@ private void displayLinkFragment() { private void displayTransitionFragment() { getFlowr().open("/transition") - .replaceCurrentFragment(true) + .replaceCurrentFragment(true) // transition works with replace .setTransition(getTransitionConfig(), binding.flowrTextView) .displayFragment(); } @@ -80,11 +83,13 @@ private void displayTransitionFragment() { @NonNull private TransitionConfig getTransitionConfig() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Transition changeBoundsTransition = new ChangeBounds(); + Transition fadeTransition = new Fade(); return new TransitionConfig.Builder() - .sharedElementEnter(TransitionConfig.Provider.changeBounds) - .sharedElementExit(TransitionConfig.Provider.changeBounds) - .enter(TransitionConfig.Provider.fade) - .exit(TransitionConfig.Provider.fade) + .sharedElementEnter(changeBoundsTransition) + .sharedElementReturn(changeBoundsTransition) + .enter(fadeTransition) + .exit(fadeTransition) .build(); } return null; diff --git a/sample/src/main/res/layout/fragment_home.xml b/sample/src/main/res/layout/fragment_home.xml index 6883871..cff534d 100644 --- a/sample/src/main/res/layout/fragment_home.xml +++ b/sample/src/main/res/layout/fragment_home.xml @@ -18,7 +18,7 @@ android:text="@string/app_name" android:textColor="@color/white" android:textSize="16sp" - android:transitionName="transitionText"/> + android:transitionName="@string/transition_text"/>