Add a CompositionLocal for getting the current Activity
This commit is contained in:
parent
b0cf2e5f28
commit
445146b531
5 changed files with 28 additions and 7 deletions
|
@ -2,9 +2,9 @@ package app.k9mail.feature.preview
|
|||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.WindowCompat
|
||||
import app.k9mail.core.ui.compose.common.activity.setActivityContent
|
||||
import app.k9mail.feature.preview.ui.FeatureApp
|
||||
|
||||
class FeatureActivity : ComponentActivity() {
|
||||
|
@ -15,7 +15,7 @@ class FeatureActivity : ComponentActivity() {
|
|||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
setContent {
|
||||
setActivityContent {
|
||||
FeatureApp()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package app.k9mail.ui.catalog
|
|||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.WindowCompat
|
||||
import app.k9mail.core.ui.compose.common.activity.setActivityContent
|
||||
import app.k9mail.ui.catalog.ui.CatalogScreen
|
||||
|
||||
class CatalogActivity : ComponentActivity() {
|
||||
|
@ -15,7 +15,7 @@ class CatalogActivity : ComponentActivity() {
|
|||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
setContent {
|
||||
setActivityContent {
|
||||
CatalogScreen()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -792,7 +792,7 @@ style:
|
|||
Compose:
|
||||
CompositionLocalAllowlist:
|
||||
active: true
|
||||
allowedCompositionLocals: [LocalColors, LocalElevations, LocalImages, LocalShapes, LocalSizes, LocalSpacings]
|
||||
allowedCompositionLocals: [LocalColors, LocalElevations, LocalImages, LocalShapes, LocalSizes, LocalSpacings, LocalActivity]
|
||||
ContentEmitterReturningValues:
|
||||
active: true
|
||||
ModifierComposable:
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package app.k9mail.core.ui.compose.common.activity
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionContext
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
||||
val LocalActivity = staticCompositionLocalOf<ComponentActivity> {
|
||||
error("No value for LocalActivity provided")
|
||||
}
|
||||
|
||||
fun ComponentActivity.setActivityContent(
|
||||
parent: CompositionContext? = null,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
setContent(parent) {
|
||||
CompositionLocalProvider(LocalActivity provides this, content = content)
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ import android.app.Activity
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.core.view.WindowCompat
|
||||
import app.k9mail.core.ui.compose.common.activity.setActivityContent
|
||||
import app.k9mail.feature.account.setup.navigation.NAVIGATION_ROUTE_ACCOUNT_SETUP
|
||||
import app.k9mail.feature.launcher.ui.FeatureLauncherApp
|
||||
import app.k9mail.feature.onboarding.navigation.NAVIGATION_ROUTE_ONBOARDING
|
||||
|
@ -19,7 +19,7 @@ class FeatureLauncherActivity : ComponentActivity() {
|
|||
|
||||
val destination = intent.getStringExtra(EXTRA_DESTINATION)
|
||||
|
||||
setContent {
|
||||
setActivityContent {
|
||||
FeatureLauncherApp(startDestination = destination)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue