ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

Slide in and Slide out transitions #58

Closed nealsanche closed 7 years ago

nealsanche commented 7 years ago

Using version 2.0.0 and trying to get popFragment to perform a transition. So far, I can only get pushFragment to display a transition.

public void pushMyFragment(Fragment fragment, int tabIndex) {
        FragNavTransactionOptions.Builder transactionOptionsBuilder =
                FragNavTransactionOptions.newBuilder()
                        .customAnimations(R.anim.slide_in_right, R.anim.do_not_move);

        FragNavTransactionOptions transactionOptions = transactionOptionsBuilder.build();

        closeDrawer();
        selectTab(tabIndex);
        if (navController.getCurrentStackIndex() != tabIndex) {
            navController.switchTab(tabIndex);
        }
        navController.pushFragment(fragment, transactionOptions);
}
public void popMyFragment(int tabIndex) {
        FragNavTransactionOptions.Builder transactionOptionsBuilder =
                FragNavTransactionOptions.newBuilder()
                        .customAnimations(R.anim.do_not_move, R.anim.slide_out_left);

        FragNavTransactionOptions transactionOptions = transactionOptionsBuilder.build();

        selectTab(tabIndex);
        if (navController.getCurrentStackIndex() != tabIndex) {
            navController.switchTab(tabIndex);
        }
        navController.popFragment(transactionOptions);
}

Always, when popping, the fragment just dissapears. Any ideas?

nealsanche commented 7 years ago

I think I found the issue. In FragNavController.popFragments(popDepth, transactionOptions) if the last fragment is being popped before the root fragment, clearStack() is called but the transactionOptions is not passed in, so the last fragment pop will never have animations. I'll make a PR for this.

nealsanche commented 7 years ago

Please see: https://github.com/ncapdevi/FragNav/pull/59

ncapdevi commented 7 years ago

@nealsanche Great, thanks for the PR! I'll take a look at this as well as your PR later tonight and if it all checks out, post a quick fix 2.0.1.

nealsanche commented 7 years ago

Thanks Nic!

On Tue, Apr 11, 2017, 4:26 PM Nic Capdevila notifications@github.com wrote:

@nealsanche https://github.com/nealsanche Great, thanks for the PR! I'll take a look at this as well as your PR later tonight and if it all checks out, post a quick fix 2.0.1.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ncapdevi/FragNav/issues/58#issuecomment-293418486, or mute the thread https://github.com/notifications/unsubscribe-auth/AFHsyam2NNW_3Ufj7u6-1tRz2wN7lPtpks5ru_4HgaJpZM4M5psM .

-- *Neal Sanche | Android Tech Lead (c)403.870.2356 (o)888.740.0967*

http://robotsandpencils.com

-- Robots and Pencils Inc | 1507 14th Ave SW Calgary AB T3C 0W4 You can unsubscribe from the Robots and Pencils mailing lists by clicking here. https://robotsandpencils.com/contact/unsubscribe.html

ncapdevi commented 7 years ago

Thanks for the PR. It's merged in and will be pushed with 2.0.1 this Thurs/Friday unless something changes.

trimf commented 6 years ago

Unfortunately we have null in popFragment():

public boolean popFragment() throws UnsupportedOperationException {
        return this.popFragment((FragNavTransactionOptions)null);
    }

As a workaround we can use

FragNavTransactionOptions options = FragNavTransactionOptions
                        .newBuilder()
                        .customAnimations(
                                R.anim.enter_from_right,
                                R.anim.exit_to_left,
                                R.anim.enter_from_left,
                                R.anim.exit_to_right
                        ).build();

                fragNavController.popFragment(options);