OXYGENHUB
# 1c42a70fcba3 oxygenhub-android / app / src / main / java / io / oxygenhub / android / ui / common / AppScreen.kt
2.7 KiB · last changed Sign-in, dashboard, repositories, issues and inbox screens, adaptive (refs #2) 11 days ago source blame history raw
1
package io.oxygenhub.android.ui.common
2
3
import androidx.compose.foundation.layout.Box
4
import androidx.compose.foundation.layout.Column
5
import androidx.compose.foundation.layout.RowScope
6
import androidx.compose.foundation.layout.WindowInsets
7
import androidx.compose.foundation.layout.fillMaxSize
8
import androidx.compose.foundation.layout.padding
9
import androidx.compose.material.icons.Icons
10
import androidx.compose.material.icons.automirrored.filled.ArrowBack
11
import androidx.compose.material3.ExperimentalMaterial3Api
12
import androidx.compose.material3.Icon
13
import androidx.compose.material3.MaterialTheme
14
import androidx.compose.material3.IconButton
15
import androidx.compose.material3.Scaffold
16
import androidx.compose.material3.SnackbarHost
17
import androidx.compose.material3.SnackbarHostState
18
import androidx.compose.material3.Text
19
import androidx.compose.material3.TopAppBar
20
import androidx.compose.runtime.Composable
21
import androidx.compose.runtime.remember
22
import androidx.compose.ui.Modifier
23
import androidx.compose.ui.text.style.TextOverflow
24
25
/**
26
 * A screen with its top bar. The navigation bar or rail around it takes
27
 * the bottom and side insets, so only the top bar's own are applied here.
28
 */
29
@OptIn(ExperimentalMaterial3Api::class)
30
@Composable
31
fun AppScreen(
32
    title: String,
33
    modifier: Modifier = Modifier,
34
    subtitle: String? = null,
35
    onBack: (() -> Unit)? = null,
36
    snackbar: SnackbarHostState = remember { SnackbarHostState() },
37
    actions: @Composable RowScope.() -> Unit = {},
38
    content: @Composable () -> Unit,
39
) {
40
    Scaffold(
41
        modifier = modifier,
42
        contentWindowInsets = WindowInsets(0, 0, 0, 0),
43
        snackbarHost = { SnackbarHost(snackbar) },
44
        topBar = {
45
            TopAppBar(
46
                title = {
47
                    Column {
48
                        Text(title, maxLines = 1, overflow = TextOverflow.Ellipsis)
49
                        if (subtitle != null) {
50
                            Text(
51
                                subtitle,
52
                                style = MaterialTheme.typography.labelMedium,
53
                                color = MaterialTheme.colorScheme.onSurfaceVariant,
54
                                maxLines = 1,
55
                                overflow = TextOverflow.Ellipsis,
56
                            )
57
                        }
58
                    }
59
                },
60
                navigationIcon = {
61
                    if (onBack != null) {
62
                        IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back") }
63
                    }
64
                },
65
                actions = actions,
66
            )
67
        },
68
    ) { padding ->
69
        Box(Modifier.fillMaxSize().padding(padding)) { content() }
70
    }
71
}