Comments (4)
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.
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.
@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.
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)
- No view found for id HOT 1
- error with Creator ActivityScreen HOT 1
- How to use Cicerone in sigleActivity multimodule app? HOT 3
- `AppNavigator#setupFragmentTransaction` public signature compatibility HOT 5
- Question: How to get nextFragment when moving backward?
- Migration to mavenCentral HOT 2
- AppNavigator applyCommandsSync HOT 5
- Override Router implementation
- Where could I find more info when Cicerone falied to apply command? HOT 3
- Error when quickly changing fragments HOT 1
- I get NullPointerException when I try to set SupportAppNavigator in NavigatorHolder
- Crash in AppNavigator
- Crash in version 7.1 HOT 2
- ConcurrentModificationException
- v5 to v6+ migration guide HOT 2
- Crash in version 7.1 HOT 4
- Activity -> Fragment deeplinking
- Spelling and Grammar issues in Readme
- Remove Jetifier
- Few questions about your library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cicerone.