1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-05-19 03:42:10 +00:00

Initial setup for navigation display with nav3

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2026-05-04 00:18:15 +08:00
parent f6129aa3a3
commit b7ab28dcbe
7 changed files with 110 additions and 5 deletions
+2
View File
@@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.jetbrains.kotlin.compose)
alias(libs.plugins.jetbrains.compose.multiplatform)
alias(libs.plugins.koin)
alias(libs.plugins.jetbrains.kotlinx.serialization)
}
kotlin {
@@ -65,6 +66,7 @@ kotlin {
implementation(libs.jetbrains.navigation3.ui)
implementation(libs.jetbrains.lifecycle.navigation3)
implementation(libs.kotlinx.serialization.json)
implementation(libs.koin.compose.viewmodel)
implementation(libs.koin.annotations)
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe
object Constants {
const val INTENT_SCREEN_KEY = "SCREEN"
}
@@ -9,6 +9,9 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.core.content.IntentCompat
import net.newpipe.Constants
import net.newpipe.app.navigation.Screen
/**
* Entry point for compose-related UI components on Android
@@ -18,8 +21,14 @@ class ComposeActivity : ComponentActivity() {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
val startDestination = IntentCompat.getParcelableExtra(
intent,
Constants.INTENT_SCREEN_KEY,
Screen::class.java
)!!
setContent {
App()
App(startDestination)
}
}
}
@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.extensions
import android.content.Context
import android.content.Intent
import net.newpipe.Constants
import net.newpipe.app.ComposeActivity
import net.newpipe.app.navigation.Screen
import kotlin.jvm.java
/**
* Navigates to a given compose destination
*/
fun Context.navigateTo(screen: Screen) = Intent(this, ComposeActivity::class.java).also { intent ->
intent.putExtra(Constants.INTENT_SCREEN_KEY, screen.name)
startActivity(intent)
}
@@ -6,18 +6,19 @@
package net.newpipe.app
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import net.newpipe.app.di.KoinApp
import net.newpipe.app.navigation.Screen
import net.newpipe.app.theme.AppTheme
import org.koin.compose.KoinApplication
import org.koin.plugin.module.dsl.koinConfiguration
/**
* Entry point for the multiplatform compose application
*/
@Composable
@Preview
fun App() {
fun App(startDestination: Screen? = null) {
KoinApplication(configuration = koinConfiguration<KoinApp>()) {
AppTheme {
}
}
}
@@ -0,0 +1,26 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.navigation
import androidx.compose.runtime.Composable
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberNavBackStack
import androidx.navigation3.ui.NavDisplay
/**
* Navigation display for compose screens
* @param startDestination Starting destination for the activity/app, defaults to about
*/
@Composable
fun NavDisplay(startDestination: Screen) {
val backstack = rememberNavBackStack(screenConfig, startDestination)
NavDisplay(
backStack = backstack,
entryProvider = entryProvider {
}
)
}
@@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.navigation
import androidx.navigation3.runtime.NavKey
import androidx.savedstate.serialization.SavedStateConfiguration
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
/**
* Destinations for navigation in compose
*/
@Serializable
sealed interface Screen : NavKey {
val name: String
get() = this::class.simpleName.toString()
}
/**
* Saved state configuration for screens
*/
@OptIn(ExperimentalSerializationApi::class)
internal val screenConfig = SavedStateConfiguration {
serializersModule = SerializersModule {
polymorphic(NavKey::class) {
subclassesOfSealed<Screen>()
}
}
}