Comments (4)
I assume that Auth Nav
and Home Nav
completely separate graphs that are not used at the same time. From the navigation side the only special thing would be the tabs. For those you simply use NavRoot
instead of NavRoute
for the tab destinations themselves. When you then call navigateToRoot(TabXNavRoot)
the library will take care of the back stack management. There is an optional parameter whether the back stack of the passed in root should be restored and the next release will also add an optional parameter whether the current back stack should be cleared.
For sharing the view models between screens there are 2 variations
- if you are not using whetstone you'd need to use some APIs that are marked as internal, then you could get the destination id for register step 1 and through that obtain the view model, there will be some changes here in the next release (will be out mid January)
- if you are using whetstone you can use
@NavEntryComponent
which unfortunately is not documented yet (#255), essentially you'd do something like this
@ComposeScreen(
scope = Register1Scope::class,
parentScope = RegisterSharedScope::class,
stateMachine = ExampleStateMachine::class,
)
@NavDestination(
route = Register1Route::class
type = DestinationType.SCREEN,
destinationScope = AppScope::class,
)
@NavEntryComponent(
scope = RegisterSharedScope::class,
parentScope = AppScope::class,
)
@Composable
internal fun Register1Screen(...) { ... }
(the annotations will be simplified in one of the next releases to reduce boilerplate)
This will create a component that will be alive as long as Register Step 1
is on the back stack. The following screens can then also use RegisterSharedScope
as their parent scope (those other screens don't need @NavEntryComponent
). With this you could then simply add @ScopeTo(RegisterSharedScope::class)
to any class you want to make it shared between all screens that have RegisterSharedScope
as their parent.
from khonshu.
Our nav graphs are completely flat and more a collection of destinations than an actual graph. This has been working well for us with fragments for the past 3 years and compose for the past year. What is your use case for nested graphs?
from khonshu.
With the normal way, I am having:
- Auth Nav
- Login
- Register Step 1
- Register Step 2
- Register Step 3
- Home Nav
- Tab 1 Nav
- ...
- Tab 2 Nav
- ...
- Tab 3 Nav
- ...
- Tab 4 Nav
- ...
- Tab 1 Nav
- ...
My use case is that I wantRegister Step 1 Fragment
,Register Step 2 Fragment
, andRegister Step 3 Fragment
to use the same ViewModel scoped to Auth Nav scope.
from khonshu.
thank @gabrielittner for the detailed explanation.
I got the idea, we will use the ViewModel scoped to the Register Step 1
's EntryNav.
from khonshu.
Related Issues (20)
- Run whetstone tests with actual source files
- Run kapt/dagger in whetstone tests HOT 2
- Deep link support: Gradle plugin that generated intent filters
- Deep link support: test facility to check that all supported deep links exist
- Replace NavDestination annotations
- Document `Closeable` support
- Document NavEntryComponent HOT 1
- Support generics for objects injected into composables
- Remove rendererFactory parameter from RendererFragment annotation
- Document deep link support
- Add an `AppScope` marker class to the library
- Make compose parameters optional
- Bottom sheet back navigation from scrim area HOT 1
- Action Required: Fix Renovate Configuration
- navigation-experimental: LocalViewModelStoreOwner, LocalLifecycleOwner, LocalSavedStateRegistryOwner HOT 3
- [navigation] pop all stack (clear stack), then navigating to new `NavRoot` HOT 1
- Use `ImmutableSet` as NavHost parameter
- Compose injection: support qualifiers
- Support URL sharing for deep links
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 khonshu.