Skip to content

Commit f64b2e3

Browse files
author
Jorge Costa
committed
Fixed transaction animation in fragments. Now we don't need to set a transaction (null) to have the default animation
1 parent d6e9a35 commit f64b2e3

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

activity-fragment-manager/src/main/java/com/massivedisaster/activitymanager/AddFragmentTransaction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class AddFragmentTransaction extends FragmentTransaction {
4747

4848
@Override
4949
public void commit() {
50+
// Apply the default activity animation if the FragmentTransaction is null.
51+
if (mTransactionAnimation == null) {
52+
mTransactionAnimation = mActivity;
53+
}
54+
55+
// Set the custom transaction animation.
56+
mFrgTransaction.setCustomAnimations(mTransactionAnimation.getAnimationEnter(), mTransactionAnimation.getAnimationExit(),
57+
mTransactionAnimation.getAnimationPopEnter(),
58+
mTransactionAnimation.getAnimationPopExit());
59+
5060
// Add the new fragment to the stack.
5161
mFrgTransaction.add(mActivity.getContainerViewId(), mFragment, mTag);
5262
// Hide the first fragment in the container.

activity-fragment-manager/src/main/java/com/massivedisaster/activitymanager/FragmentTransaction.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public abstract class FragmentTransaction implements ITransaction<FragmentTransa
4545
protected Fragment mFragment;
4646
protected android.support.v4.app.FragmentTransaction mFrgTransaction;
4747
protected String mTag;
48+
protected TransactionAnimation mTransactionAnimation;
4849

4950
/**
5051
* FragmentTransaction constructor, created to be used by an activity.
@@ -129,15 +130,7 @@ public Fragment getFragment() {
129130
* @return Return the Transaction instance.
130131
*/
131132
public FragmentTransaction setTransactionAnimation(TransactionAnimation transactionAnimation) {
132-
// Apply the default activity animation if the FragmentTransaction is null.
133-
if (transactionAnimation == null) {
134-
transactionAnimation = mActivity;
135-
}
136-
137-
// Set the custom transaction animation.
138-
mFrgTransaction.setCustomAnimations(transactionAnimation.getAnimationEnter(), transactionAnimation.getAnimationExit(),
139-
transactionAnimation.getAnimationPopEnter(),
140-
transactionAnimation.getAnimationPopExit());
133+
mTransactionAnimation = transactionAnimation;
141134

142135
return this;
143136
}

activity-fragment-manager/src/main/java/com/massivedisaster/activitymanager/ReplaceFragmentTransaction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class ReplaceFragmentTransaction extends FragmentTransaction {
4747

4848
@Override
4949
public void commit() {
50+
// Apply the default activity animation if the FragmentTransaction is null.
51+
if (mTransactionAnimation == null) {
52+
mTransactionAnimation = mActivity;
53+
}
54+
55+
// Set the custom transaction animation.
56+
mFrgTransaction.setCustomAnimations(mTransactionAnimation.getAnimationEnter(), mTransactionAnimation.getAnimationExit(),
57+
mTransactionAnimation.getAnimationPopEnter(),
58+
mTransactionAnimation.getAnimationPopExit());
59+
5060
// Hide the first fragment in the container.
5161
if (mActivity.getSupportFragmentManager().findFragmentById(mActivity.getContainerViewId()) != null) {
5262
mFrgTransaction.hide(mActivity.getSupportFragmentManager().findFragmentById(mActivity.getContainerViewId()));

0 commit comments

Comments
 (0)