Skip to content

Commit 2b9525c

Browse files
author
chetan-fueled
committed
docs(README.md): fragment transitions
refactor(TransitionConfig) refactor(*): rename sharedElementExit to sharedElementReturn refactor(*): rename sharedElementExit to sharedElementReturn
1 parent 2cf1804 commit 2b9525c

File tree

7 files changed

+21
-30
lines changed

7 files changed

+21
-30
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ When displaying a new fragment there are multiple parameters that can be specifi
6363
* **`skipBackStack`**: specify whether this fragment will be added to the `FragmentManager` back stack or not. The default value for this is `false`.
6464
* **`clearBackStack`**: specify whether the `FragmentManager` backstack should be cleared before displaying this fragment. The default value used for this is `false`.
6565
* **`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`.
66-
* **`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`.
66+
* **`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`.
67+
* **`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.
6768

6869
finally after we have specified all the parameters we need we can simply call `displayFragment()` to display the fragment.
6970

flowr/src/main/java/com/fueled/flowr/Flowr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private void setTransitions(Fragment fragment, TransitionConfig transitionConfig
346346
fragment.setEnterTransition(transitionConfig.enter);
347347
fragment.setSharedElementEnterTransition(transitionConfig.sharedElementEnter);
348348
fragment.setExitTransition(transitionConfig.exit);
349-
fragment.setSharedElementReturnTransition(transitionConfig.sharedElementExit);
349+
fragment.setSharedElementReturnTransition(transitionConfig.sharedElementReturn);
350350
}
351351

352352
/**
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package com.fueled.flowr.internal;
22

3-
import android.os.Build;
4-
import android.support.annotation.RequiresApi;
5-
import android.transition.ChangeBounds;
6-
import android.transition.Explode;
7-
import android.transition.Fade;
8-
import android.transition.Slide;
93
import android.transition.Transition;
10-
import android.view.Gravity;
114

125
/**
136
* Copyright (c) 2017 Fueled. All rights reserved.
@@ -18,20 +11,20 @@
1811
public class TransitionConfig {
1912

2013
public Transition sharedElementEnter;
21-
public Transition sharedElementExit;
14+
public Transition sharedElementReturn;
2215
public Transition enter;
2316
public Transition exit;
2417

2518
private TransitionConfig(Builder builder) {
2619
sharedElementEnter = builder.sharedElementEnter;
27-
sharedElementExit = builder.sharedElementExit;
20+
sharedElementReturn = builder.sharedElementReturn;
2821
enter = builder.enter;
2922
exit = builder.exit;
3023
}
3124

3225
public static final class Builder {
3326
private Transition sharedElementEnter;
34-
private Transition sharedElementExit;
27+
private Transition sharedElementReturn;
3528
private Transition enter;
3629
private Transition exit;
3730

@@ -43,8 +36,8 @@ public Builder sharedElementEnter(Transition val) {
4336
return this;
4437
}
4538

46-
public Builder sharedElementExit(Transition val) {
47-
sharedElementExit = val;
39+
public Builder sharedElementReturn(Transition val) {
40+
sharedElementReturn = val;
4841
return this;
4942
}
5043

@@ -62,13 +55,4 @@ public TransitionConfig build() {
6255
return new TransitionConfig(this);
6356
}
6457
}
65-
66-
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
67-
public static class Provider {
68-
public static Transition fade = new Fade();
69-
public static Transition explode = new Explode();
70-
public static Transition slideRight = new Slide(Gravity.RIGHT);
71-
public static Transition slideLeft = new Slide(Gravity.LEFT);
72-
public static Transition changeBounds = new ChangeBounds();
73-
}
7458
}

sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import android.databinding.DataBindingUtil;
44
import android.os.Build;
55
import android.support.annotation.NonNull;
6+
import android.transition.ChangeBounds;
7+
import android.transition.Fade;
8+
import android.transition.Transition;
69
import android.view.View;
710

811
import com.fueled.flowr.NavigationIconType;
@@ -72,19 +75,21 @@ private void displayLinkFragment() {
7275

7376
private void displayTransitionFragment() {
7477
getFlowr().open("/transition")
75-
.replaceCurrentFragment(true)
78+
.replaceCurrentFragment(true) // transition works with replace
7679
.setTransition(getTransitionConfig(), binding.flowrTextView)
7780
.displayFragment();
7881
}
7982

8083
@NonNull
8184
private TransitionConfig getTransitionConfig() {
8285
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
86+
Transition changeBoundsTransition = new ChangeBounds();
87+
Transition fadeTransition = new Fade();
8388
return new TransitionConfig.Builder()
84-
.sharedElementEnter(TransitionConfig.Provider.changeBounds)
85-
.sharedElementExit(TransitionConfig.Provider.changeBounds)
86-
.enter(TransitionConfig.Provider.fade)
87-
.exit(TransitionConfig.Provider.fade)
89+
.sharedElementEnter(changeBoundsTransition)
90+
.sharedElementReturn(changeBoundsTransition)
91+
.enter(fadeTransition)
92+
.exit(fadeTransition)
8893
.build();
8994
}
9095
return null;

sample/src/main/res/layout/fragment_home.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
android:text="@string/app_name"
1919
android:textColor="@color/white"
2020
android:textSize="16sp"
21-
android:transitionName="transitionText"/>
21+
android:transitionName="@string/transition_text"/>
2222

2323
<Button
2424
android:id="@+id/home_open_view_button"

sample/src/main/res/layout/fragment_transition.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
android:text="@string/app_name"
2323
android:textColor="@color/white"
2424
android:textSize="20sp"
25-
android:transitionName="transitionText"/>
25+
android:transitionName="@string/transition_text"/>
2626

2727
</FrameLayout>

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<string name="view_pick_nav_color">Pick Navigation Bar Color</string>
2020
<string name="view_toolbar_visible">Toolbar Visible</string>
2121
<string name="view_drawer_enabled">Drawer Enabled</string>
22+
<string name="transition_text">transitionText</string>
2223

2324

2425
</resources>

0 commit comments

Comments
 (0)