Skip to content

Commit

Permalink
Merge pull request #346 from skaengus2012/feature/issue343
Browse files Browse the repository at this point in the history
Compose nav-component migration
  • Loading branch information
skaengus2012 authored Dec 21, 2024
2 parents 980d1c6 + b52edba commit 6f8d06e
Show file tree
Hide file tree
Showing 33 changed files with 322 additions and 501 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins {
alias(libs.plugins.nlab.android.application.compose)
alias(libs.plugins.nlab.android.application.jacoco)
alias(libs.plugins.nlab.android.hilt)
alias(libs.plugins.androidx.navigation.safearges)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ksp)
id("kotlin-parcelize")
kotlin("kapt")
Expand Down Expand Up @@ -97,17 +97,18 @@ dependencies {

implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.collections.immutable)
implementation(libs.kotlinx.serialization.json)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.cardview)
implementation(libs.androidx.constaintlayout)
implementation(libs.androidx.fragment.compose)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.startup.runtime)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.activity.compose)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
tools:targetApi="tiramisu">

<activity
android:name=".domain.feature.main.ui.MainActivity"
android:name=".apps.ui.MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 The N's lab Open Source Project
* Copyright (C) 2024 The N's lab Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,14 @@
* limitations under the License.
*/

package com.nlab.reminder.domain.feature.main.ui
package com.nlab.reminder.apps.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.nlab.reminder.R
import com.nlab.reminder.core.designsystem.compose.theme.PlaneatTheme
import dagger.hilt.android.AndroidEntryPoint

/**
Expand All @@ -30,8 +31,14 @@ import dagger.hilt.android.AndroidEntryPoint
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
enableEdgeToEdge()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

enableEdgeToEdge()
setContent {
val appState = rememberPlaneatAppState()
PlaneatTheme {
PlaneatApp(appState = appState)
}
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/nlab/reminder/apps/ui/NavComposeExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2024 The N's lab Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.nlab.reminder.apps.ui

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.navigation.NavBackStackEntry

/**
* @author Thalys
*/
typealias EnterTransitionFactory =
AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards EnterTransition?
typealias ExitTransitionFactory =
AnimatedContentTransitionScope<NavBackStackEntry>.() -> @JvmSuppressWildcards ExitTransition?
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 The N's lab Open Source Project
* Copyright (C) 2024 The N's lab Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,21 @@
* limitations under the License.
*/

package com.nlab.reminder.domain.common.android.lifecycle
package com.nlab.reminder.apps.ui

import androidx.lifecycle.SavedStateHandle
import com.nlab.reminder.core.data.model.Tag
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

/**
* @see <a href="./nav_main.xml">argument defined</a>
* @author Doohyun
* @author Thalys
*/
val SavedStateHandle.tag: Tag get() = checkNotNull(get<Tag>("tag"))
@Composable
fun PlaneatApp(
appState: PlaneatAppState
) {
PlaneatNavHost(
modifier = Modifier.fillMaxSize(),
appState = appState
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The N's lab Open Source Project
* Copyright (C) 2024 The N's lab Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,24 @@
* limitations under the License.
*/

package com.nlab.reminder.core.android.navigation
package com.nlab.reminder.apps.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController

/**
* @author Doohyun
* @author Thalys
*/
@NavGraphDsl
@JvmInline
value class NavGraphScope<T>(val navHandle: T)
@Stable
class PlaneatAppState(
val navController: NavHostController
)

@Composable
fun rememberPlaneatAppState(
navController: NavHostController = rememberNavController()
): PlaneatAppState = PlaneatAppState(
navController = navController
)
102 changes: 102 additions & 0 deletions app/src/main/java/com/nlab/reminder/apps/ui/PlaneatNavHost.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2024 The N's lab Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.nlab.reminder.apps.ui

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.EaseIn
import androidx.compose.animation.core.EaseOut
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import com.nlab.reminder.domain.feature.home.navigation.HomeEntryPointRoute
import com.nlab.reminder.domain.feature.home.navigation.homeEntryPoint
import com.nlab.reminder.domain.feature.home.navigation.homeScreen
import com.nlab.reminder.domain.feature.schedule.all.navigation.allScheduleScreen
import com.nlab.reminder.domain.feature.schedule.all.navigation.navigateToAllSchedule

/**
* @author Thalys
*/
private const val HOME_TRANSITION_DURATION = 300

@Composable
fun PlaneatNavHost(
appState: PlaneatAppState,
modifier: Modifier = Modifier
) {
val navController = appState.navController
NavHost(
navController = navController,
startDestination = HomeEntryPointRoute,
modifier = modifier,
enterTransition = { EnterTransition.None },
exitTransition = { ExitTransition.None },
popEnterTransition = { EnterTransition.None },
popExitTransition = { ExitTransition.None }
) {
homeEntryPoint {
val enterTransitionFactoryFromHome = createFromHomeEnterTransitionFactory()
val popExitTransitionFactoryFromHome = createFromHomePopExitTransitionFactory()
homeScreen(
provideExitTransition = createHomeExitTransition(),
providePopEnterTransition = createHomePopEnterTransitionFactory(),
onAllScheduleClicked = { navController.navigateToAllSchedule() }
)
allScheduleScreen(
provideEnterTransition = enterTransitionFactoryFromHome,
providePopExitTransition = popExitTransitionFactoryFromHome,
onBackClicked = { navController.popBackStack() }
)
}
}
}

private fun createFromHomeEnterTransitionFactory(): EnterTransitionFactory = {
slideIntoContainer(
animationSpec = tween(HOME_TRANSITION_DURATION, easing = EaseIn),
towards = AnimatedContentTransitionScope.SlideDirection.Start
)
}

private fun createHomeExitTransition(): ExitTransitionFactory = {
slideOutOfContainer(
animationSpec = tween(HOME_TRANSITION_DURATION, easing = EaseOut),
towards = AnimatedContentTransitionScope.SlideDirection.Start,
targetOffset = { (it * 0.3f).toInt() }
) + fadeOut(animationSpec = tween(HOME_TRANSITION_DURATION, easing = LinearEasing), targetAlpha = 0.2f)
}

private fun createHomePopEnterTransitionFactory(): EnterTransitionFactory = {
slideIntoContainer(
animationSpec = tween(HOME_TRANSITION_DURATION, easing = EaseIn),
towards = AnimatedContentTransitionScope.SlideDirection.End,
initialOffset = { (it * 0.3f).toInt() }
) + fadeIn(animationSpec = tween(HOME_TRANSITION_DURATION, easing = LinearEasing), initialAlpha = 0.2f)
}

private fun createFromHomePopExitTransitionFactory(): ExitTransitionFactory = {
slideOutOfContainer(
animationSpec = tween(HOME_TRANSITION_DURATION, easing = EaseOut),
towards = AnimatedContentTransitionScope.SlideDirection.End
)
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6f8d06e

Please sign in to comment.