Coder Social home page Coder Social logo

modo's Introduction

Modo - State-Based Jetpack Compose Navigation

Maven Central latest stable Maven Central latest License: MIT

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

Modo.overview.mp4

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

Navigation is a Graph

Each integration of Modo is a rooted tree (wiki) that can be displayed as follows: modo graph

  • Each node is a Screen or ContainerScreen.
  • Leaf nodes are Screens.
  • Inner nodes are ContainerScreens. They can contain other Screens or ContainerScreens in their navigationState.
  • The root node is a RootScreen. You can have multiple roots in your app. See How to integrate Modo for details.

State Defines UI

  • 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 and MultiScreen.
  • 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

MIT License

Copyright (c) Konstantin Tskhovrebov (@terrakok)
          and Karenkov Igor (@KarenkovID)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

modo's People

Contributors

alaershov avatar aradxxx avatar etaskaevhh avatar ikarenkov avatar ppav avatar terrakok avatar trdelnk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modo's Issues

Compose MultiScreen lose state during navigation back

What is wrong?

MultiScreen doesn't use StateHolder and SaveableStateProvider as ComposeRenderer do. Watch video to compare MultiComposeScreen and ComposeRenderer behavior.

MultiScreen state lost

How to fix?

We should reuse ComposeRenderer logic in MultiComposeScreen. Also we can add nested screen stack support as spacial case of MultiComposeScreen

[Compose] Support nested navigation

Nested navigation can be used in multimode projects to separate outer and inner logic. It also can be used in MultiScreen navigation, to share logic.

  • NestedWrapperScreen with state and reducer
  • Inner reducer support, to delegate logic like in ELM architecture.
  • Sample
  • Multimodule Sample

Inner modo usage

Greetings!

First of all, huge props for creating this amazing simple library.

I have a case in which I want to navigate between fragments in app scope. But I also want to navigate between fragments nested inside another fragment.

Imagine you have a fragment with bottom bar. I want to be able to navigate between fragments shown on it. At this moment I've encountered that I need a modorenderer which requires activity. Can I achieve this behavior using current implementation of Modo?

Render bug (Compose)

override fun Content() call multitime. My logs (action forward):
v0.7.0:
override fun Content() SampleScreen: ScreenKey(value=Screen#0)
override fun Content() SampleScreen: ScreenKey(value=Screen#2)

v0.7.1 (bug). Problem inside SlideTransition()
override fun Content() SampleScreen: ScreenKey(value=Screen#0)
override fun Content() SampleScreen: ScreenKey(value=Screen#0)
override fun Content() SampleScreen: ScreenKey(value=Screen#2)
override fun Content() SampleScreen: ScreenKey(value=Screen#0)
override fun Content() SampleScreen: ScreenKey(value=Screen#2)
override fun Content() SampleScreen: ScreenKey(value=Screen#2)
override fun Content() SampleScreen: ScreenKey(value=Screen#2)

The Modo bug? Upon entering the [ Stacks In lazyColumn ], the following operations were performed, and then the app crashed.

operation steps:

[ Stacks In lazyColumn ] > delete item [ MainScreen 0 ] > [ Add item ] -> Crash !

Modo Dev branch

Emulator :

Android 6.0.1 & X86-64 & OpenGL driver 4.1

Logcat:

16:05:55.973 AndroidRuntime          FATAL EXCEPTION: main
                                     Process: com.github.terrakok.modo.sample, PID: 2552
                                     java.lang.IllegalArgumentException: modifier is updated when deactivated
                                     	at androidx.compose.ui.internal.InlineClassHelperKt.throwIllegalArgumentException(InlineClassHelper.kt:34)
                                     	at androidx.compose.ui.node.LayoutNode.setModifier(LayoutNode.kt:1969)
                                     	at androidx.compose.ui.node.ComposeUiNode$Companion$SetModifier$1.invoke(ComposeUiNode.kt:47)
                                     	at androidx.compose.ui.node.ComposeUiNode$Companion$SetModifier$1.invoke(ComposeUiNode.kt:47)
                                     	at androidx.compose.runtime.changelist.Operation$UpdateNode.execute(Operation.kt:449)
                                     	at androidx.compose.runtime.changelist.Operations.executeAndFlushAllPendingOperations(Operations.kt:309)
                                     	at androidx.compose.runtime.changelist.ChangeList.executeAndFlushAllPendingChanges(ChangeList.kt:81)
                                     	at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:984)
                                     	at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:1013)
                                     	at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:1142)
                                     	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_release(Composer.kt:3874)
                                     	at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_release(Composer.kt:3874)
                                     	at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:649)
                                     	at androidx.compose.runtime.CompositionImpl.setContentWithReuse(Composition.kt:641)
                                     	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcomposeInto(SubcomposeLayout.kt:518)
                                     	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:488)
                                     	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:479)
                                     	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState.subcompose(SubcomposeLayout.kt:463)
                                     	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$Scope.subcompose(SubcomposeLayout.kt:895)
                                     	at androidx.compose.foundation.lazy.layout.LazyLayoutMeasureScopeImpl.measure-0kLqBqw(LazyLayoutMeasureScope.kt:125)
                                     	at androidx.compose.foundation.lazy.LazyListMeasuredItemProvider.getAndMeasure-0kLqBqw(LazyListMeasuredItemProvider.kt:55)
                                     	at androidx.compose.foundation.lazy.LazyListMeasuredItemProvider.getAndMeasure-0kLqBqw$default(LazyListMeasuredItemProvider.kt:49)
                                     	at androidx.compose.foundation.lazy.LazyListMeasureKt.measureLazyList-x0Ok8Vo(LazyListMeasure.kt:214)
                                     	at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke-0kLqBqw(LazyList.kt:326)
                                     	at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke(LazyList.kt:183)
                                     	at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$3$2$1.invoke-0kLqBqw(LazyLayout.kt:119)
                                     	at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$3$2$1.invoke(LazyLayout.kt:112)
                                     	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:725)
                                     	at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:135)
                                     	at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:646)
                                     	at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:188)
                                     	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:316)
                                     	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:315)
                                     	at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2441)
                                     	at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:502)
                                     	at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:258)
                                     	at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
                                     	at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.
---------------------------- PROCESS ENDED (2552) for package com.github.terrakok.modo.sample ----------------------------
16:05:56.127 InputDispatcher         channel '2dc72ca com.github.terrakok.modo.sample/com.github.terrakok.modo.sample.ModoSampleActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
16:05:56.181 KernelUidCpuTimeReader  Failed to read uid_cputime: /proc/uid_cputime/show_uid_stat: open failed: ENOENT (No such file or directory)

[Compose] Screen dispose callback

Need to add callback to detect, when screen removes from stack. It can be used, when screen contains come subscriptions, that must be disposed

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.