1 /*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 @file:Suppress("DEPRECATION")
18
19 package com.google.accompanist.insets.ui
20
21 import androidx.compose.foundation.layout.PaddingValues
22 import androidx.compose.foundation.layout.RowScope
23 import androidx.compose.foundation.layout.padding
24 import androidx.compose.material.AppBarDefaults
25 import androidx.compose.material.MaterialTheme
26 import androidx.compose.material.Surface
27 import androidx.compose.material.TopAppBar
28 import androidx.compose.material.contentColorFor
29 import androidx.compose.material.primarySurface
30 import androidx.compose.runtime.Composable
31 import androidx.compose.ui.Modifier
32 import androidx.compose.ui.graphics.Color
33 import androidx.compose.ui.unit.Dp
34 import androidx.compose.ui.unit.dp
35
36 /**
37 * A wrapper around [TopAppBar] which supports the setting of [contentPadding] to add
38 * internal padding. This is especially useful in conjunction with insets.
39 *
40 * For an edge-to-edge layout, typically you would use the
41 * [com.google.accompanist.insets.WindowInsets.systemBars] insets like so below:
42 *
43 * @sample com.google.accompanist.sample.insets.TopAppBar_Insets
44 */
45 @Deprecated(
46 """
47 accompanist/insets-ui has been deprecated.
48 This functionality has been upstreamed to Material.
49 For more migration information, please visit https://google.github.io/accompanist/insets/#migration
50 """
51 )
52 @Composable
TopAppBarnull53 public fun TopAppBar(
54 title: @Composable () -> Unit,
55 modifier: Modifier = Modifier,
56 contentPadding: PaddingValues = PaddingValues(0.dp),
57 navigationIcon: @Composable (() -> Unit)? = null,
58 actions: @Composable RowScope.() -> Unit = {},
59 backgroundColor: Color = MaterialTheme.colors.primarySurface,
60 contentColor: Color = contentColorFor(backgroundColor),
61 elevation: Dp = AppBarDefaults.TopAppBarElevation,
62 ) {
63 TopAppBarSurface(
64 modifier = modifier,
65 backgroundColor = backgroundColor,
66 contentColor = contentColor,
67 elevation = elevation
<lambda>null68 ) {
69 TopAppBarContent(
70 title = title,
71 navigationIcon = navigationIcon,
72 actions = actions,
73 modifier = Modifier.padding(contentPadding)
74 )
75 }
76 }
77
78 @Deprecated(
79 """
80 accompanist/insets-ui has been deprecated.
81 This functionality has been upstreamed to Material.
82 For more migration information, please visit https://google.github.io/accompanist/insets/#migration
83 """
84 )
85 @Composable
TopAppBarSurfacenull86 public fun TopAppBarSurface(
87 modifier: Modifier = Modifier,
88 backgroundColor: Color = MaterialTheme.colors.primarySurface,
89 contentColor: Color = contentColorFor(backgroundColor),
90 elevation: Dp = AppBarDefaults.TopAppBarElevation,
91 content: @Composable () -> Unit,
92 ) {
93 Surface(
94 color = backgroundColor,
95 contentColor = contentColor,
96 elevation = elevation,
97 modifier = modifier,
98 content = content
99 )
100 }
101
102 @Deprecated(
103 """
104 accompanist/insets-ui has been deprecated.
105 This functionality has been upstreamed to Material.
106 For more migration information, please visit https://google.github.io/accompanist/insets/#migration
107 """
108 )
109 @Composable
TopAppBarContentnull110 public fun TopAppBarContent(
111 title: @Composable () -> Unit,
112 modifier: Modifier = Modifier,
113 navigationIcon: @Composable (() -> Unit)? = null,
114 actions: @Composable RowScope.() -> Unit = {},
115 ) {
116 TopAppBar(
117 title = title,
118 navigationIcon = navigationIcon,
119 actions = actions,
120 backgroundColor = Color.Transparent,
121 elevation = 0.dp,
122 modifier = modifier
123 )
124 }
125