Skip to content

Structuring your app navigation

As seen in Composable navigation, you can make NavModels composable.

To achieve this, Appyx offers the Node class as the structural element.

Node illustration

In many of the examples you'll see this panel as an illustration of a very simple Node – it has some local state (id, colour, and a counter).

If you launch the sample app in the :app module, you can also change its state (colour) by tapping it. Its counter is stepped automatically. This is to illustrate that it has its own state, persisted and restored.

Node overview

You can think of a Node as a standalone component with:

  • Its own simplified lifecycle
  • State restoration
  • A @Composable view
  • Business logic that's kept alive even when the view isn't added to the composition
  • The ability to host generic Plugins to extract extra concerns without enforcing any particular architectural pattern

Parent nodes, child nodes

ParentNodes can have other Nodes as children. This means you can represent your whole application as a tree of Appyx nodes.

You can go as granular or as high-level as it fits you. This allows to keep the complexity low in individual Nodes by extracting responsibilities to children, as well as composing other components to build more complex functionality.

Composable navigation

Nodes offer the structure – NavModels add dynamism to it.

Read more in Composable navigation

Lifecycle

Nodes have their own lifecycles, directly using the related classes of androidx.lifecycle.

Read more in Lifecycle

ChildAware API

React to dynamically added child nodes in the tree: ChildAware API

Summary

A summary of Appyx's approach to structuring applications:

  • Compose your app out of Nodes with their own lifecycles and state
  • Navigation is local, composed of individual pieces of NavModels
  • Navigation is stateful
  • Navigation is unit-testable
  • You're free to implement your own navigable components by utilising NavModels
  • Avoid global navigation concerns, like shared modules needing to know about the application, or the application needing to know about all its possible modules