Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider an alternative way for Fragment management that works with "in-app predictive back" aka FragmentManager.enablePredictiveBack(true) #11

Open
Zhuinden opened this issue Jun 9, 2023 · 1 comment

Comments

@Zhuinden
Copy link
Owner

Zhuinden commented Jun 9, 2023

static boolean USE_PREDICTIVE_BACK = true;

    /**
     * Control whether FragmentManager uses the new state predictive back feature that allows
     * seeing the previous Fragment when using gesture back.
     * <p>
     * This should only be changed <strong>before</strong> any fragment transactions are done
     * (i.e., in your <code>Application</code> class or prior to <code>super.onCreate()</code>
     * in every activity).
     *
     * @param enabled Whether predictive back should be enabled.
     */
    @PredictiveBackControl
    public static void enablePredictiveBack(boolean enabled) {
        FragmentManager.USE_PREDICTIVE_BACK = enabled;
    }

This sets a new behavior for ALL fragment managers in the entire app.

However, the problem is that the way this is handled in the FragmentManager via an internal fragment operation and an internal back callback handler, which means it's completely inaccessible from outside. The idea is that it "reverts" the "current fragment transaction on the fragment backstack" as you are dragging the gesture, reversing any SpecialEffectsControllers that are attributed to a Fragment.

However, DefaultFragmentStateChanger doesn't use .addToBackStack(). This means that in order to be able to use FragmentManager.USE_PREDICTIVE_BACK, you ***have to use .addToBackStack(), which however does not support "any arbitrary operations to navigate between various fragments", somehow we need to track the transactions with which a given fragment was added, revert up to that point, and add new fragments after.

This is quite a pain. Not using .addToBackStack() is a very powerful feature as it removed many limitations. However, a new FragmentStateChanger might need to be created in order to handle the new touch gesture in-app back handling paradigm, and regain feature parity against Navigation again.

@Zhuinden
Copy link
Owner Author

Funnily enough, if you use .add() + setMaxLifecycle(RESUMED) (unfortunately it cannot be stopped as that destroys the views 😒 ), you could theoretically just translate the fragment to the side and you'd see the views underneath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant