Change-Id: I66730ebfcd65d16304c87ba64a66e8f5b03291c4pull/2/head
parent
b677cc4508
commit
0dfc2f4fa7
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.core.ui
|
||||||
|
|
||||||
|
import androidx.compose.material.ripple.RippleAlpha
|
||||||
|
import androidx.compose.material.ripple.RippleTheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
object ClearRippleTheme : RippleTheme {
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
override fun defaultColor(): Color = Color.Transparent
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
override fun rippleAlpha() = RippleAlpha(
|
||||||
|
draggedAlpha = 0.0f,
|
||||||
|
focusedAlpha = 0.0f,
|
||||||
|
hoveredAlpha = 0.0f,
|
||||||
|
pressedAlpha = 0.0f,
|
||||||
|
)
|
||||||
|
}
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.samples.apps.nowinandroid.core.ui
|
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
|
||||||
import androidx.compose.material.icons.filled.Search
|
|
||||||
import androidx.compose.material.ripple.RippleAlpha
|
|
||||||
import androidx.compose.material.ripple.RippleTheme
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun NiaToolbar(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
@StringRes titleRes: Int,
|
|
||||||
onSearchClick: () -> Unit = {},
|
|
||||||
onMenuClick: () -> Unit = {},
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
IconButton(onClick = { onSearchClick() }) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Filled.Search,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = titleRes),
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
IconButton(onClick = { onMenuClick() }) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Filled.MoreVert,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object ClearRippleTheme : RippleTheme {
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun defaultColor(): Color = Color.Transparent
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun rippleAlpha() = RippleAlpha(
|
|
||||||
draggedAlpha = 0.0f,
|
|
||||||
focusedAlpha = 0.0f,
|
|
||||||
hoveredAlpha = 0.0f,
|
|
||||||
pressedAlpha = 0.0f,
|
|
||||||
)
|
|
||||||
}
|
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.core.ui.component
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material.icons.filled.Search
|
||||||
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import com.google.samples.apps.nowinandroid.core.ui.R
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NiaTopAppBar(
|
||||||
|
@StringRes titleRes: Int,
|
||||||
|
navigationIcon: ImageVector,
|
||||||
|
navigationIconContentDescription: String?,
|
||||||
|
actionIcon: ImageVector,
|
||||||
|
actionIconContentDescription: String?,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onNavigationClick: () -> Unit = {},
|
||||||
|
onActionClick: () -> Unit = {}
|
||||||
|
) {
|
||||||
|
CenterAlignedTopAppBar(
|
||||||
|
title = { Text(text = stringResource(id = titleRes)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = onNavigationClick) {
|
||||||
|
Icon(
|
||||||
|
imageVector = navigationIcon,
|
||||||
|
contentDescription = navigationIconContentDescription,
|
||||||
|
tint = MaterialTheme.colorScheme.onSurface
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = onActionClick) {
|
||||||
|
Icon(
|
||||||
|
imageVector = actionIcon,
|
||||||
|
contentDescription = actionIconContentDescription,
|
||||||
|
tint = MaterialTheme.colorScheme.onSurface
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = modifier
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview("Top App Bar")
|
||||||
|
@Composable
|
||||||
|
fun NiaTopAppBarPreview() {
|
||||||
|
NiaTopAppBar(
|
||||||
|
titleRes = R.string.top_app_bar_preview_title,
|
||||||
|
navigationIcon = Icons.Default.Search,
|
||||||
|
navigationIconContentDescription = "Navigation icon",
|
||||||
|
actionIcon = Icons.Default.MoreVert,
|
||||||
|
actionIconContentDescription = "Action icon"
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in new issue