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

Docs improvements #52

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
# [Modo](https://ikarenkov.github.io/Modo) - state-based Jetpack Compose navigation
Here’s the improved version of your documentation text:

# [Modo](https://ikarenkov.github.io/Modo) - State-Based Jetpack Compose Navigation

[![Maven Central](https://img.shields.io/maven-central/v/com.github.terrakok/modo-compose)](https://repo1.maven.org/maven2/com/github/terrakok)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Modo is a simple and convenient state-base navigation library for Jetpack Compose.
Modo is a simple and convenient state-based navigation library for Jetpack Compose.

https://github.com/ikarenkov/Modo/assets/17216532/e2977736-bdda-44a9-83f3-379731ddfecc

## [Project website](https://ikarenkov.github.io/Modo)
## [Project Website](https://ikarenkov.github.io/Modo)

Check out our website to get the most up-to-date information about the library:

* [**Modo overview**](https://ikarenkov.github.io/Modo/modooverview.html)
* [**Quick start guide**](https://ikarenkov.github.io/Modo/quickstartguide.html)
* [**Core concepts**](https://ikarenkov.github.io/Modo/core-concepts.html)
* [**How to integrate Modo in your app**](https://ikarenkov.github.io/Modo/how-to-integrate-modo-to-your-app.html)
* [**Features list**](https://ikarenkov.github.io/Modo/features.html)
* [**Modo Overview**](https://ikarenkov.github.io/Modo/modooverview.html)
* [**Quick Start Guide**](https://ikarenkov.github.io/Modo/quickstartguide.html)
* [**Core Concepts**](https://ikarenkov.github.io/Modo/core-concepts.html)
* [**How to Integrate Modo into Your App**](https://ikarenkov.github.io/Modo/how-to-integrate-modo-to-your-app.html)
* [**Features List**](https://ikarenkov.github.io/Modo/features.html)

## Navigation - is a graph
## Navigation is a Graph

Each integration of Modo is a
<a href="https://en.wikipedia.org/wiki/Tree_(graph_theory)#Rooted_tree" summary="A rooted tree is a tree in which one vertex has been designated the root.">rooted tree (wiki)</a> that can be displayed:
<a href="https://en.wikipedia.org/wiki/Tree_(graph_theory)#Rooted_tree" summary="A rooted tree is a tree in which one vertex has been designated the root.">rooted tree (wiki)</a> that can be displayed as follows:
<img src="Writerside/images/coreConcepts/diagram_1.png" alt="modo graph"/>

* Each node - is a <code>Screen</code> or <code>ContainerScreen</code></step>
* Leafs nodes - are <code>Screen</code>s.</step>
* Inner nodes - are <code>ContainerScreen</code>s. They can contain other <code>Screen</code>s or <code>ContainerScreen</code>s in
their <code>navigationState</code>.
* Root node - is a <code>RootScreen</code>. You can have multiply roots in your app. See <a href="https://ikarenkov.github.io/Modo/how-to-integrate-modo-to-your-app.html"> How to integrate Modo</a> for details.
* Each node is a <code>Screen</code> or <code>ContainerScreen</code>.
* Leaf nodes are <code>Screen</code>s.
* Inner nodes are <code>ContainerScreen</code>s. They can contain other <code>Screen</code>s or <code>ContainerScreen</code>s in their <code>
navigationState</code>.
* The root node is a <code>RootScreen</code>. You can have multiple roots in your app.
See <a href="https://ikarenkov.github.io/Modo/how-to-integrate-modo-to-your-app.html">How to integrate Modo</a> for details.

## State defines UI
## State Defines UI

* `NavigationState` defines UI
* Initial state is defined in constructor of `ContainerScreen` by `navModel: NavModel<State, Action>`
* To update state, use `dispatch(action: Action)` on `NavigationContainer`, or build-in extension functions
* `NavigationState` defines the UI:
* The initial state is defined in the constructor of `ContainerScreen` by `navModel: NavModel<State, Action>`.
* To update the state, use `dispatch(action: Action)` on `NavigationContainer`, or use the built-in extension functions
for [StackScreen](modo-compose/src/main/java/com/github/terrakok/modo/stack/StackActions.kt)
and [MultiScreen](modo-compose/src/main/java/com/github/terrakok/modo/multiscreen/MultiScreenActions.kt)
* There are Screen and ContainerScreen
* ContainerScreen can contain and render child screens
* There are some build-in implementation of ContainerScreen like StackScreen and MultiScreen
* You can easily create custom `Action` by extending `Action` or `ReducerAction`,
and [MultiScreen](modo-compose/src/main/java/com/github/terrakok/modo/multiscreen/MultiScreenActions.kt).
* There are `Screen` and `ContainerScreen`:
* `ContainerScreen` can contain and render child screens.
* There are some built-in implementations of `ContainerScreen` like `StackScreen` and `MultiScreen`.
* You can easily create custom `Action` by extending `Action` or `ReducerAction`.

# License

Expand Down
34 changes: 33 additions & 1 deletion Writerside/codeSnippets/SampleAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,40 @@ fun interface SampleAction : ReducerAction<SampleState> {
override fun reduce(oldState: SampleState): SampleState =
oldState.copy(screen3 = null)
}

class CreateScreen : SampleAction {
override fun reduce(oldState: SampleState): SampleState =
oldState.copy(screen3 = NestedScreen(canBeRemoved = true))
}
}
}

sealed interface SampleAction : NavigationAction<SampleState> {
class Remove : SampleAction
class CreateScreen : SampleAction
}

@Parcelize
internal class RemovableItemContainerScreen(
private val navModel: NavModel<RemovableItemContainerState, RemovableItemContainerAction> = NavModel(
RemovableItemContainerState(
NestedScreen(canBeRemoved = false),
NestedScreen(canBeRemoved = false),
NestedScreen(canBeRemoved = true),
NestedScreen(canBeRemoved = false),
)
)
) : ContainerScreen<RemovableItemContainerState, RemovableItemContainerAction>(navModel) {

override val reducer: NavigationReducer<RemovableItemContainerState, RemovableItemContainerAction> = NavigationReducer<RemovableItemContainerState, RemovableItemContainerAction> { action, state ->
when (action) {
is RemovableItemContainerAction.Remove -> {
state.copy(screen3 = null)
}
is RemovableItemContainerAction.CreateScreen -> {
state.copy(screen3 = NestedScreen(canBeRemoved = true))
}
}

}

}
2 changes: 1 addition & 1 deletion Writerside/modo-docs.tree
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<instance-profile name="Modo docs" id="modo-docs" start-page="ModoOverview.md">

<toc-element topic="ModoOverview.md" >
<toc-element topic="ModoOverview.md">
<toc-element topic="QuickStartGuide.md" />
<toc-element topic="Core-concepts.md" />
<toc-element topic="How-to-integrate-modo-to-your-app.md" />
Expand Down
32 changes: 16 additions & 16 deletions Writerside/topics/Android-integrations.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Android integrations
# Android Integrations

Modo provides android integrations of ViewModel and Lifecycle support by providing `LocalLifecycleOwner`, `LocalViewModelStoreOwner`
and `LocalSavedStateRegistryOwner`. So you can use functions like `viewModel` to obtain android `ViewModel`.
Modo provides Android integrations with ViewModel and Lifecycle support through `LocalLifecycleOwner`, `LocalViewModelStoreOwner`,
and `LocalSavedStateRegistryOwner`. This allows you to use functions like `viewModel` to obtain Android `ViewModel`.

> [Sample code](%github_code_url%sample/src/main/java/com/github/terrakok/modo/sample/screens/viewmodel/AndroidViewModelSampleScreen.kt) of usage
> android integration inside Modo Screen.
> [Sample code](%github_code_url%sample/src/main/java/com/github/terrakok/modo/sample/screens/viewmodel/AndroidViewModelSampleScreen.kt) demonstrating
> Android integration inside a Modo Screen.

## Lifecycle

Since Modo provides LifeCycle support, let's take a look what specific lifecycle event means in the case of Screen Lifecycle:
Since Modo provides Lifecycle support, let's take a look at what specific lifecycle events mean in the context of Screen Lifecycle:

* `Lifecycle.Event.ON_CREATE` - called once per a screen when screen is created.
* `Lifecycle.Event.ON_START` and `Lifecycle.Event.ON_RESUME` - dispatched when `Screen.Content` comes to composition by first time.
* `Lifecycle.Event.ON_PAUSE` and `Lifecycle.Event.ON_STOP` - dispatched when `Screen.Content` leaves composition.
* `Lifecycle.Event.ON_DESTROY` - called once per a `Screen` when it is removed from navigation graph.
* `Lifecycle.Event.ON_CREATE` - called once per screen when the screen is created.
* `Lifecycle.Event.ON_START` and `Lifecycle.Event.ON_RESUME` - dispatched when `Screen.Content` is composed for the first time.
* `Lifecycle.Event.ON_PAUSE` and `Lifecycle.Event.ON_STOP` - dispatched when `Screen.Content` leaves the composition.
* `Lifecycle.Event.ON_DESTROY` - called once per screen when it is removed from the navigation graph.

For correct handling `Lifecycle.Event` from your `Screen.Content` we recommend to use build-in [screen effects](Screen-effects.md). There is
convenient `LifecycleScreenEffect` that subscribes to Screen's Lifecycle.
For correctly handling `Lifecycle.Event` from your `Screen.Content`, we recommend using the built-in [screen effects](Screen-effects.md).
The `LifecycleScreenEffect` is a convenient way to subscribe to a screen's Lifecycle.

```Kotlin
```kotlin
LifecycleScreenEffect {
LifecycleEventObserver { _, event ->
logcat { "Lifecycle event $event." }
}
}
```

> If you use `LaunchedEffect` or `DisposableEffect` to subscribe to the `Screen`'s Lifecycle, you won't receive `Lifecycle.Event.ON_DESTROY` because
> this event happens after leaving the composition.
> If you use `LaunchedEffect` or `DisposableEffect` to subscribe to the screen's Lifecycle, you won't receive `Lifecycle.Event.ON_DESTROY` because
> this event happens after the screen leaves the composition.

{ style="warning" }

## ViewModel

You can use functions provided by Jetpack Compose to get `ViewModel`.
You can use functions provided by Jetpack Compose to get a `ViewModel`.

<include from="snippets.topic" element-id="under_develop_note"/>
29 changes: 14 additions & 15 deletions Writerside/topics/Community-and-contribution.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
# Community and contribution
# Community and Contribution

Modo is a community-driven project, and we welcome your contributions! Currently it is developing primary by
me ([Igor Karenkov](https://github.com/ikarenkov)). We
believe in the power of collaboration and are excited to see how you can
help us make Modo even better.
Modo is a community-driven project, and we welcome your contributions! Currently, it is primarily developed by
me, [Igor Karenkov](https://github.com/ikarenkov). We believe in the power of collaboration and are excited to see how you can help us make Modo even
better.

> Modo was started as a POC of state-driven navigation for Fragments by [Konstantin Tskhovrebov](https://github.com/terrakok). Then the support of
> Jetpack Compose was added by [Alexey Ershov](https://github.com/alaershov) and finalized by [Igor Karenkov](%ikarenkov_github_url%) (me). I've been
> developing Modo for a while and used it in my personal and work projects, so we with [Konstantin Tskhovrebov](https://github.com/terrakok) decided
> to
> transfer this project to my personal GitHub. Currently, I'm the main maintainer of Modo.
> Modo was started as a proof of concept for state-driven navigation for Fragments by [Konstantin Tskhovrebov](https://github.com/terrakok). Later,
> support for Jetpack Compose was added by [Alexey Ershov](https://github.com/alaershov) and finalized by [Igor Karenkov](%ikarenkov_github_url%). I
> have been developing Modo for a while and have used it in my personal and work projects. Together
> with [Konstantin Tskhovrebov](https://github.com/terrakok), we decided to transfer this project to my personal GitHub. Currently, I am the main
> maintainer of Modo.

{ style="note" }

## Join the Conversation:
## Join the Conversation

- [Telegram Group (RU)](https://t.me/Cicerone_RUS): Connect with other Modo users, ask questions, share your experiences, and discuss new features.
This is a great place to get help, share your ideas, and stay up-to-date with the latest developments.
- If you are seeking for english-speaking community, please [write to me](https://t.me/karenkovigor) and emphasize that need. We are ready to create a
- If you are seeking an English-speaking community, please [write to me](https://t.me/karenkovigor) and emphasize your need. We are ready to create a
new group for you.

## Contribute to Modo:
## Contribute to Modo

[GitHub](%github_url%): We encourage you to contribute to Modo by:

- Reporting issues: If you encounter any bugs or have suggestions for improvements, please [open an issue](%github_url%issues) on GitHub.
- Submitting pull requests: If you have code contributions, such as bug fixes, new features, or documentation improvements, feel free to submit a pull
request.
- Improving documentation: Help us make Modo easier to use by contributing to the documentation. Each page has an "Edit page" link on top of it. You
can improve existing documentation or write new guides and tutorials.
- Improving documentation: Help us make Modo easier to use by contributing to the documentation. Each page has an "Edit page" link at the top. You can
improve existing documentation or write new guides and tutorials.

## Why Contribute?

Expand Down
Loading