Skip to content

Commit 6d2bb13

Browse files
committed
update layout and theming
1 parent 4b3d955 commit 6d2bb13

File tree

3 files changed

+31
-71
lines changed

3 files changed

+31
-71
lines changed

app/src/main/java/pro/jayeshseth/animations/MainActivity.kt

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,22 @@ package pro.jayeshseth.animations
22

33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
5-
import androidx.activity.SystemBarStyle
65
import androidx.activity.compose.setContent
76
import androidx.activity.enableEdgeToEdge
87
import androidx.compose.foundation.layout.fillMaxSize
98
import androidx.compose.material3.MaterialTheme
109
import androidx.compose.material3.Surface
1110
import androidx.compose.ui.Modifier
12-
import androidx.core.view.WindowCompat
1311
import pro.jayeshseth.animations.navigation.NavGraph
1412
import pro.jayeshseth.animations.ui.theme.AnimationsTheme
15-
import com.google.accompanist.systemuicontroller.rememberSystemUiController
1613

1714
class MainActivity : ComponentActivity() {
1815
override fun onCreate(savedInstanceState: Bundle?) {
1916
super.onCreate(savedInstanceState)
2017

21-
enableEdgeToEdge(
22-
statusBarStyle = SystemBarStyle.auto(
23-
android.graphics.Color.TRANSPARENT,
24-
android.graphics.Color.TRANSPARENT,
25-
) {
26-
true
27-
}
28-
)
29-
WindowCompat.setDecorFitsSystemWindows(window, false)
18+
enableEdgeToEdge()
3019
setContent {
3120
AnimationsTheme {
32-
val systemUiController = rememberSystemUiController()
33-
val color = MaterialTheme.colorScheme.background.copy(alpha = 0.8f)
34-
systemUiController.setStatusBarColor(
35-
color = color,
36-
darkIcons = false,
37-
)
38-
systemUiController.setNavigationBarColor(
39-
color = color,
40-
navigationBarContrastEnforced = false
41-
)
4221
Surface(
4322
modifier = Modifier
4423
.fillMaxSize(),
@@ -49,31 +28,4 @@ class MainActivity : ComponentActivity() {
4928
}
5029
}
5130
}
52-
}
53-
//class NavActivity : ComponentActivity() {
54-
// override fun onCreate(savedInstanceState: Bundle?) {
55-
// super.onCreate(savedInstanceState)
56-
//
57-
// WindowCompat.setDecorFitsSystemWindows(window, false)
58-
// setContent {
59-
// AnimationsTheme {
60-
// val systemUiController = rememberSystemUiController()
61-
// val color = MaterialTheme.colorScheme.background.copy(alpha = 0.8f)
62-
// systemUiController.setStatusBarColor(
63-
// color = color,
64-
// )
65-
// systemUiController.setNavigationBarColor(
66-
// color = color,
67-
// navigationBarContrastEnforced = false
68-
// )
69-
// Surface(
70-
// modifier = Modifier
71-
// .fillMaxSize(),
72-
// color = MaterialTheme.colorScheme.background
73-
// ) {
74-
// NavGraph()
75-
// }
76-
// }
77-
// }
78-
// }
79-
//}
31+
}

app/src/main/java/pro/jayeshseth/animations/ui/screens/HomeScreen.kt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package pro.jayeshseth.animations.ui.screens
22

3-
import androidx.compose.foundation.layout.Column
43
import androidx.compose.foundation.layout.navigationBarsPadding
54
import androidx.compose.foundation.layout.padding
65
import androidx.compose.foundation.rememberScrollState
7-
import androidx.compose.foundation.verticalScroll
8-
import androidx.compose.material3.CenterAlignedTopAppBar
96
import androidx.compose.material3.ExperimentalMaterial3Api
107
import androidx.compose.material3.Text
118
import androidx.compose.material3.TopAppBarDefaults
9+
import androidx.compose.material3.rememberTopAppBarState
1210
import androidx.compose.runtime.Composable
1311
import androidx.compose.ui.Modifier
1412
import androidx.compose.ui.graphics.Color
1513
import androidx.compose.ui.text.font.FontWeight
16-
import androidx.compose.ui.unit.dp
14+
import androidx.compose.ui.unit.sp
15+
import pro.jayeshseth.commoncomponents.HomeScaffold
1716
import pro.jayeshseth.commoncomponents.InteractiveButton
17+
import pro.jayeshseth.commoncomponents.StatusBarAwareThemedColumn
1818

1919
@OptIn(ExperimentalMaterial3Api::class)
2020
@Composable
@@ -28,23 +28,24 @@ fun HomeScreen(
2828
navToBouncyRopes: () -> Unit,
2929
navToAnimateValueAsState: () -> Unit
3030
) {
31-
Column {
32-
CenterAlignedTopAppBar(
33-
title = {
34-
Text(
35-
text = "Animations in Jetpack Compose",
36-
fontWeight = FontWeight.Bold
37-
)
38-
},
39-
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
40-
containerColor = Color.Transparent
41-
),
42-
)
43-
Column(
31+
val scrollState = rememberScrollState()
32+
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState())
33+
HomeScaffold(
34+
innerScrollState = scrollState,
35+
topAppBarScrollBehavior = scrollBehavior,
36+
title = {
37+
Text(
38+
text = "Animations in Jetpack Compose",
39+
fontSize = 25.sp,
40+
fontWeight = FontWeight.Bold
41+
)
42+
}
43+
) {
44+
StatusBarAwareThemedColumn(
45+
statusBarColor = Color.Transparent,
4446
modifier = Modifier
45-
.verticalScroll(rememberScrollState())
47+
.padding(it)
4648
.navigationBarsPadding()
47-
.padding(horizontal = 20.dp)
4849
) {
4950
InteractiveButton(
5051
text = "Animate Visibility",

app/src/main/java/pro/jayeshseth/animations/ui/theme/Theme.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import androidx.compose.material3.dynamicDarkColorScheme
99
import androidx.compose.material3.dynamicLightColorScheme
1010
import androidx.compose.material3.lightColorScheme
1111
import androidx.compose.runtime.Composable
12-
import androidx.compose.runtime.SideEffect
12+
import androidx.compose.runtime.DisposableEffect
13+
import androidx.compose.ui.graphics.toArgb
1314
import androidx.compose.ui.platform.LocalContext
1415
import androidx.compose.ui.platform.LocalView
1516
import androidx.core.view.WindowCompat
@@ -54,9 +55,15 @@ fun AnimationsTheme(
5455
}
5556
val view = LocalView.current
5657
if (!view.isInEditMode) {
57-
SideEffect {
58+
DisposableEffect(key1 = darkTheme) {
5859
val window = (view.context as Activity).window
60+
window.statusBarColor = colorScheme.surface.copy(0.5f).toArgb()
61+
window.navigationBarColor = colorScheme.surface.copy(0.5f).toArgb()
5962
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
63+
WindowCompat.getInsetsController(window, view).isAppearanceLightNavigationBars =
64+
!darkTheme
65+
66+
onDispose {}
6067
}
6168
}
6269

0 commit comments

Comments
 (0)