Skip to content

Commit 35da15d

Browse files
committed
Refactor to conditionally use Scaffold or NavigationSuiteScaffold
Modify RYScaffold to use NavigationSuiteScaffold only when navigationSuiteItems is not null, otherwise default to using Scaffold. This ensures appropriate usage of components based on the availability of navigationSuiteItems while maintaining UI consistency.
1 parent 9e2dd6c commit 35da15d

File tree

1 file changed

+69
-26
lines changed

1 file changed

+69
-26
lines changed

app/src/main/java/me/ash/reader/ui/component/base/RYScaffold.kt

+69-26
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,59 @@ fun RYScaffold(
3434
currentWindowAdaptiveInfo()
3535
)
3636

37-
NavigationSuiteScaffold(
38-
modifier = modifier
39-
.background(
40-
MaterialTheme.colorScheme.surfaceColorAtElevation(
41-
topBarTonalElevation,
42-
color = containerColor
43-
)
44-
),
45-
layoutType = layoutType,
46-
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
47-
containerTonalElevation,
48-
color = containerColor
49-
) onDark MaterialTheme.colorScheme.surface,
50-
navigationSuiteItems = navigationSuiteItems ?: {},
51-
content = {
52-
Column {
37+
if (navigationSuiteItems != null) {
38+
NavigationSuiteScaffold(
39+
modifier = modifier
40+
.background(
41+
MaterialTheme.colorScheme.surfaceColorAtElevation(
42+
topBarTonalElevation,
43+
color = containerColor
44+
)
45+
),
46+
layoutType = layoutType,
47+
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
48+
containerTonalElevation,
49+
color = containerColor
50+
) onDark MaterialTheme.colorScheme.surface,
51+
navigationSuiteItems = navigationSuiteItems,
52+
content = {
53+
Column {
54+
if (topBar != null) {
55+
topBar()
56+
} else if (navigationIcon != null || actions != null) {
57+
TopAppBar(
58+
title = {},
59+
navigationIcon = { navigationIcon?.invoke() },
60+
actions = { actions?.invoke(this) },
61+
colors = TopAppBarDefaults.topAppBarColors(
62+
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
63+
topBarTonalElevation
64+
),
65+
)
66+
)
67+
}
68+
content()
69+
if (floatingActionButton != null) {
70+
Box(
71+
modifier = Modifier.fillMaxSize(),
72+
contentAlignment = Alignment.BottomEnd
73+
) {
74+
floatingActionButton()
75+
}
76+
}
77+
}
78+
}
79+
)
80+
} else {
81+
Scaffold(
82+
modifier = modifier
83+
.background(
84+
MaterialTheme.colorScheme.surfaceColorAtElevation(
85+
topBarTonalElevation,
86+
color = containerColor
87+
)
88+
),
89+
topBar = {
5390
if (topBar != null) {
5491
topBar()
5592
} else if (navigationIcon != null || actions != null) {
@@ -64,17 +101,23 @@ fun RYScaffold(
64101
)
65102
)
66103
}
67-
content()
104+
},
105+
floatingActionButton = {
68106
if (floatingActionButton != null) {
69-
Box(
70-
modifier = Modifier.fillMaxSize(),
71-
contentAlignment = Alignment.BottomEnd
72-
) {
73-
floatingActionButton()
74-
}
107+
floatingActionButton()
75108
}
76-
}
77-
}
78-
)
109+
},
110+
content = {
111+
Column {
112+
Spacer(modifier = Modifier.height(it.calculateTopPadding()))
113+
content()
114+
}
115+
},
116+
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
117+
containerTonalElevation,
118+
color = containerColor
119+
) onDark MaterialTheme.colorScheme.surface
120+
)
121+
}
79122
}
80123

0 commit comments

Comments
 (0)