GithubHelp home page GithubHelp logo

Comments (4)

Jeevuz avatar Jeevuz commented on August 16, 2024

Hi! I think yes, its possible. But it will cause the Navigator in the BaseActivity to know about all transitions (activities and fragments). And such a big navigator can be a downside of this idea. But logically this will be the same as in sample app - when your activity dies, the navigator implemented in BaseActivity will be removed from the NavigationHolder, and exactly the same instance of navigator (from BaseActivity) will be added to it when new Activity appears.

from cicerone.

terrakok avatar terrakok commented on August 16, 2024

Hi, good question!
We need to remember that Router has only one active Navigator in a time.
So you can do what you need in this way:
In the BaseActivity put Navigator instance that implements all activity transitions. But for all fragment transitions it will call a subactivity's method. Activity that extends the base one will override this method to resolve fragment transitions.

from cicerone.

lectricas avatar lectricas commented on August 16, 2024

@terrakok
still didn't get it. In order to call fragmentNavigator method, we need to attach it to activity lifecycle by

    @Override
    protected void onResume() {
        super.onResume();
        SampleApplication.INSTANCE.getNavigatorHolder().setNavigator(navigator);
    }

Ok, we did that and now we want to startNewActivity.
How we should change the navigator?

@Jeevuz I suppose that having all screen navigation in one place would be awesome. Wanna see it in practice.

from cicerone.

Jeevuz avatar Jeevuz commented on August 16, 2024

If you want one big navigator so put it in BaseActivity. In this navigator you will put all your navigation logic both for activities and fragments transitions (eg. if this is sceen1 open activity1, if screen2 replace fragment to fragment2). Then you will add/remove this navigator in onResume/onPause of the BaseActivity. And that's it. You have our big navigator knowing all transitions of your app.

But if you want to divide your navigation, as @terrakok mentioned, so your BaseActivity navigator's applyCommand will call subactivity's method if it don't know how to handle some screens:

public class BaseActivity {

    ...

    @Override
    protected void onResume() {
        super.onResume();
        SampleApplication.INSTANCE.getNavigatorHolder().setNavigator(navigator);
    }

    @Override
    protected void onPause() {
        super.onPause();
        SampleApplication.INSTANCE.getNavigatorHolder().removeNavigator();
    }

    ...

    private Navigator navigator = new Navigator() {

        @Override
        public void applyCommand(Command command) {
            if (command instanceof Forward) {
                Forward forward = (Forward) command;
                if (SCREEN_NAME_ACTIVITY_1.equals(forward.getScreenKey())) {
                    // start your activity
                } else {
                    // all fragment transitions will be handled by subactivity
                    applyCommandInternal(command);
                }
            } else ...
        }
    }
    
    ...

    protected void applyCommandInternal(Command command) {
        // Nothing. Override in subactivity to perform fragment transitions.
    }
}

I hope you get the idea.

And I want to mention, that in both this cases you will need to implement your own Navigator that can do activity and fragment transitions at the same time.

from cicerone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.