Skip to content

Commit

Permalink
docs(README.md): fragment transitions
Browse files Browse the repository at this point in the history
refactor(TransitionConfig)

refactor(*): rename sharedElementExit to sharedElementReturn
  • Loading branch information
chetan-fueled committed Nov 26, 2017
1 parent 2cf1804 commit 35a329a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion flowr/src/main/java/com/fueled/flowr/Flowr.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,13 +11,13 @@
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.sharedElementExit;
enter = builder.enter;
exit = builder.exit;
}
Expand Down Expand Up @@ -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();
}
}
15 changes: 10 additions & 5 deletions sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,19 +75,21 @@ private void displayLinkFragment() {

private void displayTransitionFragment() {
getFlowr().open("/transition")
.replaceCurrentFragment(true)
.replaceCurrentFragment(true) // transition works with replace
.setTransition(getTransitionConfig(), binding.flowrTextView)
.displayFragment();
}

@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)
.sharedElementExit(changeBoundsTransition)
.enter(fadeTransition)
.exit(fadeTransition)
.build();
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="16sp"
android:transitionName="transitionText"/>
android:transitionName="@string/transition_text"/>

<Button
android:id="@+id/home_open_view_button"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/fragment_transition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="20sp"
android:transitionName="transitionText"/>
android:transitionName="@string/transition_text"/>

</FrameLayout>
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="view_pick_nav_color">Pick Navigation Bar Color</string>
<string name="view_toolbar_visible">Toolbar Visible</string>
<string name="view_drawer_enabled">Drawer Enabled</string>
<string name="transition_text">transitionText</string>


</resources>

0 comments on commit 35a329a

Please sign in to comment.