Update Wear Scaffold usage to be more consistent (#3562)

* Update TimeText to only show at the top of the screen

* Add Scaffold with PositionIndicator and TimeText where missing
This commit is contained in:
Joris Pelgröm 2023-06-03 02:45:06 +02:00 committed by GitHub
parent 2ff492a1c2
commit 8dac1627f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 305 additions and 253 deletions

View file

@ -44,7 +44,7 @@ fun ConversationResultView(
PositionIndicator(scalingLazyListState = scrollState)
}
},
timeText = { TimeText(visible = !scrollState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scrollState) }
) {
ScalingLazyColumn(
state = scrollState,

View file

@ -22,10 +22,13 @@ import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.InlineSlider
import androidx.wear.compose.material.InlineSliderDefaults
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleButton
import androidx.wear.compose.material.ToggleButtonDefaults
import androidx.wear.compose.material.ToggleChipDefaults
import androidx.wear.compose.material.rememberScalingLazyListState
import com.mikepenz.iconics.compose.Image
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import io.homeassistant.companion.android.common.R
@ -60,9 +63,18 @@ fun DetailsPanelView(
) {
val haptic = LocalHapticFeedback.current
val context = LocalContext.current
val scalingLazyListState = rememberScalingLazyListState()
WearAppTheme {
ThemeLazyColumn {
Scaffold(
positionIndicator = {
if (scalingLazyListState.isScrollInProgress) {
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(state = scalingLazyListState) {
val attributes = entity.attributes as Map<*, *>
item {
@ -163,6 +175,7 @@ fun DetailsPanelView(
}
}
}
}
}
@Composable

View file

@ -8,8 +8,11 @@ import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.items
import androidx.wear.compose.material.rememberScalingLazyListState
import io.homeassistant.companion.android.common.data.integration.Entity
import io.homeassistant.companion.android.theme.WearAppTheme
import io.homeassistant.companion.android.util.playPreviewEntityScene1
@ -35,9 +38,18 @@ fun EntityViewList(
) {
// Remember expanded state of each header
val expandedStates = rememberExpandedStates(entityLists.keys.map { it.hashCode() })
val scalingLazyListState = rememberScalingLazyListState()
WearAppTheme {
ThemeLazyColumn {
Scaffold(
positionIndicator = {
if (scalingLazyListState.isScrollInProgress) {
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(state = scalingLazyListState) {
for (header in entityListsOrder) {
val entities = entityLists[header].orEmpty()
if (entities.isNotEmpty()) {
@ -84,6 +96,7 @@ fun EntityViewList(
}
}
}
}
}
@Preview

View file

@ -72,7 +72,7 @@ fun MainView(
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(
state = scalingLazyListState

View file

@ -40,7 +40,7 @@ fun SensorManagerUi(
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(
state = scalingLazyListState

View file

@ -36,7 +36,7 @@ fun SensorsView(
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
val sensorManagers = getSensorManagers()
ThemeLazyColumn(

View file

@ -47,7 +47,7 @@ fun SetFavoritesView(
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(
state = scalingLazyListState

View file

@ -17,9 +17,12 @@ import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleChip
import androidx.wear.compose.material.ToggleChipDefaults
import androidx.wear.compose.material.rememberScalingLazyListState
import com.mikepenz.iconics.compose.Image
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import io.homeassistant.companion.android.data.SimplifiedEntity
@ -38,8 +41,17 @@ fun SetTileShortcutsView(
isShowShortcutTextEnabled: Boolean,
onShowShortcutTextEnabled: (Boolean) -> Unit
) {
val scalingLazyListState = rememberScalingLazyListState()
WearAppTheme {
ThemeLazyColumn {
Scaffold(
positionIndicator = {
if (scalingLazyListState.isScrollInProgress) {
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(state = scalingLazyListState) {
item {
ListHeader(id = commonR.string.shortcuts_tile)
}
@ -125,6 +137,7 @@ fun SetTileShortcutsView(
}
}
}
}
}
@Preview(device = Devices.WEAR_OS_LARGE_ROUND)

View file

@ -84,7 +84,7 @@ fun SettingsView(
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(!scalingLazyListState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(
state = scalingLazyListState

View file

@ -12,10 +12,14 @@ import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.rememberScalingLazyListState
import com.mikepenz.iconics.compose.Image
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import io.homeassistant.companion.android.common.R
import io.homeassistant.companion.android.theme.WearAppTheme
import io.homeassistant.companion.android.theme.wearColorPalette
import io.homeassistant.companion.android.util.IntervalToString
import io.homeassistant.companion.android.views.ListHeader
@ -27,7 +31,17 @@ fun TemplateTileSettingsView(
refreshInterval: Int,
onClickRefreshInterval: () -> Unit
) {
ThemeLazyColumn {
val scalingLazyListState = rememberScalingLazyListState()
WearAppTheme {
Scaffold(
positionIndicator = {
if (scalingLazyListState.isScrollInProgress) {
PositionIndicator(scalingLazyListState = scalingLazyListState)
}
},
timeText = { TimeText(scalingLazyListState = scalingLazyListState) }
) {
ThemeLazyColumn(state = scalingLazyListState) {
item {
ListHeader(id = R.string.template_tile)
}
@ -64,6 +78,8 @@ fun TemplateTileSettingsView(
)
}
}
}
}
}
@Preview(device = Devices.WEAR_OS_LARGE_ROUND)

View file

@ -1,31 +1,28 @@
package io.homeassistant.companion.android.home.views
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.wear.compose.material.ScalingLazyListState
import androidx.wear.compose.material.TimeText
import androidx.wear.compose.material.rememberScalingLazyListState
import androidx.wear.compose.material.scrollAway
@Composable
fun TimeText(
visible: Boolean
scalingLazyListState: ScalingLazyListState
) {
AnimatedVisibility(
visible = visible,
enter = slideInVertically(),
exit = slideOutVertically()
) {
TimeText()
}
TimeText(
modifier = Modifier.scrollAway(scrollState = scalingLazyListState)
)
}
@Preview(device = Devices.WEAR_OS_LARGE_ROUND)
@Composable
private fun PreviewTimeText() {
CompositionLocalProvider {
TimeText(visible = true)
TimeText(scalingLazyListState = rememberScalingLazyListState())
}
}

View file

@ -39,7 +39,7 @@ fun PhoneInstallView(
PositionIndicator(scalingLazyListState = scrollState)
}
},
timeText = { TimeText(visible = !scrollState.isScrollInProgress) }
timeText = { TimeText(scalingLazyListState = scrollState) }
) {
Box(modifier = Modifier.background(MaterialTheme.colors.background)) {
ThemeLazyColumn(state = scrollState) {