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

Enchanted readme and added list of features and fixed sample package #43

Merged
merged 9 commits into from
May 13, 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
2 changes: 0 additions & 2 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 71 additions & 70 deletions README.MD

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ androidx-compose-foundation = { group = "androidx.compose.foundation", name = "f
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-animation = { group = "androidx.compose.animation", name = "animation" }
androidx-compose-material = { group = "androidx.compose.material", name = "material" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.2.1" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivityCompose" }
Expand Down
2 changes: 0 additions & 2 deletions modo-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.github.terrakok.configureJetpackCompose
import com.github.terrakok.configureKotlinAndroid

plugins {
alias(libs.plugins.modo.android.library)
Expand All @@ -10,7 +9,6 @@ plugins {
android {
namespace = "com.github.terrakok.modo.android.compose"

configureKotlinAndroid(this)
configureJetpackCompose(this)
}

Expand Down
3 changes: 2 additions & 1 deletion modo-compose/src/main/java/com/github/terrakok/modo/Modo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object Modo {
* Must be called to clear all data from [ScreenModelStore], related with removed screens.
*/
fun <T : Screen> onRootScreenFinished(rootScreen: RootScreen<T>?) {
// TODO: store root screen in memory and clear it here
rootScreen?.let(::clearScreenModel)
}

Expand Down Expand Up @@ -93,6 +94,7 @@ object Modo {
) {
screenCounterKey.get()
}
// FIXME: return same instance if there was no process death
val rootScreen = rememberSaveable(key = MODO_GRAPH) {
RootScreen(rootScreenFactory())
}
Expand All @@ -105,7 +107,6 @@ object Modo {
* It also saves and restores screenCounterKey for correct [generateScreenKey] usage.
* Integration point for your screen hierarchy. You can use this fun to integrate Modo to your Fragment or Activity.
*/
@OptIn(ExperimentalModoApi::class)
@Composable
fun <T : Screen> Fragment.rememberRootScreen(
rootScreenFactory: () -> T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ val displayingScreens = mutableStateMapOf<Screen, Unit>()

typealias ScreenTransitionContent = @Composable AnimatedVisibilityScope.(Screen) -> Unit

/**
* The way to animate [Screen]'s changing (transition).
*/
@Suppress("MagicNumber")
@ExperimentalAnimationApi
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@ package com.github.terrakok.modo.animation
import com.github.terrakok.modo.ComposeRendererScope
import com.github.terrakok.modo.stack.StackState

/**
* Describes the transition types for a stack.
*/
enum class StackTransitionType {
/**
* Represents opening a new screen in a stack.
*/
Push,

/**
* Represents replacement of current screen in a stack to a new one.
*/
Replace,

/**
* Represents closing the current screen in a stack.
*/
Pop,

/**
* Represents no transition.
*/
Idle
}

fun calculateStackTransitionType(oldScreensState: StackState?, newScreensState: StackState?): StackTransitionType =
if (oldScreensState != null && newScreensState != null) {
val oldStack = oldScreensState.stack
val newStack = newScreensState.stack
/**
* Culculates the transition type for the given [oldState] and [newState].
* It can be used with a combination with [ScreenTransitionContent] to culculate transitionSpec based on [StackTransitionType].
*/
fun calculateStackTransitionType(oldState: StackState?, newState: StackState?): StackTransitionType =
if (oldState != null && newState != null) {
val oldStack = oldState.stack
val newStack = newState.stack
when {
oldStack.lastOrNull() == newStack.lastOrNull() || oldStack.isEmpty() -> StackTransitionType.Idle
newStack.lastOrNull() in oldStack -> StackTransitionType.Pop
Expand All @@ -24,4 +46,7 @@ fun calculateStackTransitionType(oldScreensState: StackState?, newScreensState:
StackTransitionType.Idle
}

/**
* @see calculateStackTransitionType
*/
fun ComposeRendererScope<StackState>.calculateStackTransitionType() = calculateStackTransitionType(oldState, newState)
5 changes: 3 additions & 2 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ plugins {
}

android {
namespace = "com.github.terrakok.androidcomposeapp"
namespace = "com.github.terrakok.modo.sample"

configureKotlinAndroid(this)
configureJetpackCompose(this)

defaultConfig {
applicationId = "com.github.terrakok.androidcomposeapp"
applicationId = "com.github.terrakok.modo.sample"
targetSdk = libs.versions.compileSdk.get().toInt()
versionCode = 1
versionName = "1.0"
Expand All @@ -35,6 +35,7 @@ dependencies {
implementation(libs.androidx.activity.compose)

implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.material3)

implementation(libs.debug.logcat)

Expand Down
3 changes: 1 addition & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.terrakok.androidcomposeapp">
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".ModoSampleApplication"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

import android.content.res.Configuration
import androidx.activity.ComponentActivity
Expand All @@ -23,7 +23,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import com.github.terrakok.androidcomposeapp.screens.dialogs.showingDialogsCount
import com.github.terrakok.modo.sample.screens.dialogs.showingDialogsCount

@Composable
internal fun ComponentActivity.ActivityContent(content: @Composable () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.fadeIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import com.github.terrakok.androidcomposeapp.screens.MainScreen
import com.github.terrakok.androidcomposeapp.screens.containers.SampleStack
import com.github.terrakok.modo.Modo
import com.github.terrakok.modo.RootScreen
import com.github.terrakok.modo.sample.screens.MainScreen
import com.github.terrakok.modo.sample.screens.containers.SampleStack
import com.github.terrakok.modo.stack.StackScreen

class ModoLegacyIntegrationActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import com.github.terrakok.androidcomposeapp.screens.MainScreen
import com.github.terrakok.androidcomposeapp.screens.containers.SampleStack
import com.github.terrakok.modo.Modo.rememberRootScreen
import com.github.terrakok.modo.sample.screens.MainScreen
import com.github.terrakok.modo.sample.screens.containers.SampleStack

class ModoSampleActivity : AppCompatActivity() {

Expand All @@ -17,7 +17,7 @@ class ModoSampleActivity : AppCompatActivity() {
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
ActivityContent {
// Remember root screen in the composition,
// Remember root screen using rememberSeaveable under the hood.
val rootScreen = rememberRootScreen {
SampleStack(MainScreen(1))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

import android.app.Application
import com.github.terrakok.modo.ModoDevOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

import androidx.compose.foundation.background
import androidx.compose.runtime.remember
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

object SampleAppConfig {
const val counterEnabled: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp
package com.github.terrakok.modo.sample

/**
* The default light scrim, as defined by androidx and the platform:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.components
package com.github.terrakok.modo.sample.components

import androidx.compose.material.Icon
import androidx.compose.material.IconButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.fragment
package com.github.terrakok.modo.sample.fragment

import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -11,9 +11,9 @@ import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import com.github.terrakok.androidcomposeapp.screens.MainScreen
import com.github.terrakok.androidcomposeapp.screens.containers.SampleStack
import com.github.terrakok.modo.Modo.rememberRootScreen
import com.github.terrakok.modo.sample.screens.MainScreen
import com.github.terrakok.modo.sample.screens.containers.SampleStack

class ModoFragment : Fragment() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.fragment
package com.github.terrakok.modo.sample.fragment

import android.os.Bundle
import androidx.activity.addCallback
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.playground
package com.github.terrakok.modo.sample.playground

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -24,10 +24,10 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.github.terrakok.androidcomposeapp.screens.base.rememberCounterState
import com.github.terrakok.modo.Screen
import com.github.terrakok.modo.ScreenKey
import com.github.terrakok.modo.generateScreenKey
import com.github.terrakok.modo.sample.screens.base.rememberCounterState
import kotlinx.parcelize.Parcelize
import kotlin.random.Random

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.playground
package com.github.terrakok.modo.sample.playground

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
Expand All @@ -18,7 +18,7 @@ import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
import com.github.terrakok.androidcomposeapp.screens.MainScreen
import com.github.terrakok.modo.sample.screens.MainScreen
import com.github.terrakok.modo.stack.StackNavModel
import com.github.terrakok.modo.stack.StackScreen
import com.github.terrakok.modo.stack.back
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.screens
package com.github.terrakok.modo.sample.screens

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ContentTransform
Expand Down Expand Up @@ -27,11 +27,11 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.github.terrakok.androidcomposeapp.randomColor
import com.github.terrakok.modo.Screen
import com.github.terrakok.modo.ScreenKey
import com.github.terrakok.modo.animation.StackTransitionType
import com.github.terrakok.modo.generateScreenKey
import com.github.terrakok.modo.sample.randomColor
import kotlinx.parcelize.Parcelize
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.screens
package com.github.terrakok.modo.sample.screens

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.screens
package com.github.terrakok.modo.sample.screens

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.terrakok.androidcomposeapp.screens
package com.github.terrakok.modo.sample.screens

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand All @@ -8,28 +8,28 @@ import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import com.github.terrakok.androidcomposeapp.ModoLegacyIntegrationActivity
import com.github.terrakok.androidcomposeapp.ModoSampleActivity
import com.github.terrakok.androidcomposeapp.fragment.ModoFragment
import com.github.terrakok.androidcomposeapp.fragment.ModoFragmentIntegrationActivity
import com.github.terrakok.androidcomposeapp.screens.base.ButtonsScreenContent
import com.github.terrakok.androidcomposeapp.screens.containers.HorizontalPagerScreen
import com.github.terrakok.androidcomposeapp.screens.containers.OpenActivityAction
import com.github.terrakok.androidcomposeapp.screens.containers.SampleContainerScreen
import com.github.terrakok.androidcomposeapp.screens.containers.SampleMultiScreen
import com.github.terrakok.androidcomposeapp.screens.containers.StackInLazyColumnScreen
import com.github.terrakok.androidcomposeapp.screens.containers.custom.MovableContentPlaygroundScreen
import com.github.terrakok.androidcomposeapp.screens.containers.custom.RemovableItemContainerScreen
import com.github.terrakok.androidcomposeapp.screens.containers.custom.SampleCustomContainerScreen
import com.github.terrakok.androidcomposeapp.screens.dialogs.DialogsPlayground
import com.github.terrakok.androidcomposeapp.screens.stack.StackActionsScreen
import com.github.terrakok.androidcomposeapp.screens.viewmodel.AndroidViewModelSampleScreen
import com.github.terrakok.modo.ExperimentalModoApi
import com.github.terrakok.modo.Screen
import com.github.terrakok.modo.ScreenKey
import com.github.terrakok.modo.generateScreenKey
import com.github.terrakok.modo.lifecycle.LifecycleScreenEffect
import com.github.terrakok.modo.model.OnScreenRemoved
import com.github.terrakok.modo.sample.ModoLegacyIntegrationActivity
import com.github.terrakok.modo.sample.ModoSampleActivity
import com.github.terrakok.modo.sample.fragment.ModoFragment
import com.github.terrakok.modo.sample.fragment.ModoFragmentIntegrationActivity
import com.github.terrakok.modo.sample.screens.base.ButtonsScreenContent
import com.github.terrakok.modo.sample.screens.containers.HorizontalPagerScreen
import com.github.terrakok.modo.sample.screens.containers.OpenActivityAction
import com.github.terrakok.modo.sample.screens.containers.SampleContainerScreen
import com.github.terrakok.modo.sample.screens.containers.SampleMultiScreen
import com.github.terrakok.modo.sample.screens.containers.StackInLazyColumnScreen
import com.github.terrakok.modo.sample.screens.containers.custom.MovableContentPlaygroundScreen
import com.github.terrakok.modo.sample.screens.containers.custom.RemovableItemContainerScreen
import com.github.terrakok.modo.sample.screens.containers.custom.SampleCustomContainerScreen
import com.github.terrakok.modo.sample.screens.dialogs.DialogsPlayground
import com.github.terrakok.modo.sample.screens.stack.StackActionsScreen
import com.github.terrakok.modo.sample.screens.viewmodel.AndroidViewModelSampleScreen
import com.github.terrakok.modo.stack.LocalStackNavigation
import com.github.terrakok.modo.stack.StackNavContainer
import com.github.terrakok.modo.stack.back
Expand Down
Loading