Add reverse pager layout

This commit is contained in:
MM20 2022-07-11 16:51:10 +02:00
parent 8b0e96b628
commit 18539c5f64
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
6 changed files with 64 additions and 47 deletions

File diff suppressed because one or more lines are too long

View File

@ -68,6 +68,7 @@ message Settings {
enum Layout {
PullDown = 0;
Pager = 1;
PagerReversed = 2;
}
Layout layout = 9;

View File

@ -122,7 +122,8 @@ class LauncherActivity : BaseActivity() {
darkNavBarIcons = lightNav,
)
}
Settings.AppearanceSettings.Layout.Pager -> {
Settings.AppearanceSettings.Layout.Pager,
Settings.AppearanceSettings.Layout.PagerReversed -> {
PagerScaffold(
modifier = Modifier
.fillMaxSize()
@ -133,6 +134,7 @@ class LauncherActivity : BaseActivity() {
},
darkStatusBarIcons = lightStatus,
darkNavBarIcons = lightNav,
reverse = layout == Settings.AppearanceSettings.Layout.PagerReversed
)
}
else -> {}

View File

@ -28,8 +28,10 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
@ -53,6 +55,7 @@ fun PagerScaffold(
modifier: Modifier = Modifier,
darkStatusBarIcons: Boolean = false,
darkNavBarIcons: Boolean = false,
reverse: Boolean = false,
) {
val viewModel: LauncherScaffoldVM = viewModel()
val searchVM: SearchVM = viewModel()
@ -213,9 +216,11 @@ fun PagerScaffold(
val widthPx = width.toPixels()
val originalLayoutDirection = LocalLayoutDirection.current
CompositionLocalProvider(
LocalOverscrollConfiguration provides null
LocalOverscrollConfiguration provides null,
LocalLayoutDirection provides if (reverse) LayoutDirection.Rtl else LayoutDirection.Ltr
) {
Row(
@ -232,61 +237,67 @@ fun PagerScaffold(
thresholds = { _, _ ->
FractionalThreshold(0.5f)
},
enabled = !isWidgetEditMode
enabled = !isWidgetEditMode,
reverseDirection = reverse,
)
.offset {
IntOffset(swipeableState.offset.value.roundToInt(), 0)
}
},
) {
CompositionLocalProvider(
LocalLayoutDirection provides originalLayoutDirection
) {
val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp)
val clockPadding by animateDpAsState(
if (isWidgetsScrollZero) 64.dp + insets.calculateBottomPadding() else 0.dp
)
val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp)
val clockHeight by remember {
derivedStateOf {
height - (64.dp + insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding)
val clockPadding by animateDpAsState(
if (isWidgetsScrollZero) 64.dp + insets.calculateBottomPadding() else 0.dp
)
val clockHeight by remember {
derivedStateOf {
height - (64.dp + insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding)
}
}
WidgetColumn(
modifier = Modifier
.requiredWidth(width)
.fillMaxHeight()
.nestedScroll(nestedScrollConnection)
.verticalScroll(widgetsScrollState)
.windowInsetsPadding(WindowInsets.safeDrawing)
.padding(horizontal = 8.dp)
.padding(top = 8.dp, bottom = 64.dp)
.padding(top = editModePadding),
clockHeight = { clockHeight },
clockBottomPadding = { clockPadding },
editMode = isWidgetEditMode,
onEditModeChange = {
viewModel.setWidgetEditMode(it)
}
)
val websearches by searchVM.websearchResults.observeAsState(emptyList())
val webSearchPadding by animateDpAsState(
if (websearches.isEmpty()) 0.dp else 48.dp
)
SearchColumn(
modifier = Modifier
.requiredWidth(width)
.fillMaxHeight()
.verticalScroll(searchScrollState, reverseScrolling = true)
.imePadding()
.windowInsetsPadding(WindowInsets.safeDrawing)
.padding(horizontal = 8.dp)
.padding(top = 8.dp, bottom = 64.dp)
.padding(bottom = webSearchPadding),
reverse = true,
)
}
WidgetColumn(
modifier = Modifier
.requiredWidth(width)
.fillMaxHeight()
.nestedScroll(nestedScrollConnection)
.verticalScroll(widgetsScrollState)
.windowInsetsPadding(WindowInsets.safeDrawing)
.padding(horizontal = 8.dp)
.padding(top = 8.dp, bottom = 64.dp)
.padding(top = editModePadding),
clockHeight = { clockHeight },
clockBottomPadding = { clockPadding },
editMode = isWidgetEditMode,
onEditModeChange = {
viewModel.setWidgetEditMode(it)
}
)
val websearches by searchVM.websearchResults.observeAsState(emptyList())
val webSearchPadding by animateDpAsState(
if (websearches.isEmpty()) 0.dp else 48.dp
)
SearchColumn(
modifier = Modifier
.requiredWidth(width)
.fillMaxHeight()
.verticalScroll(searchScrollState, reverseScrolling = true)
.imePadding()
.windowInsetsPadding(WindowInsets.safeDrawing)
.padding(horizontal = 8.dp)
.padding(top = 8.dp, bottom = 64.dp)
.padding(bottom = webSearchPadding),
reverse = true,
)
}
}
}

View File

@ -29,6 +29,7 @@ internal fun placeRightOrBottom(
current += it
}
}
private inline fun IntArray.forEachIndexed(reversed: Boolean, action: (Int, Int) -> Unit) {
if (!reversed) {
forEachIndexed(action)

View File

@ -481,6 +481,7 @@ fun LayoutPreference(
when (layouts[it]) {
AppearanceSettings.Layout.PullDown -> R.raw.lottie_scaffold_pulldown
AppearanceSettings.Layout.Pager -> R.raw.lottie_scaffold_pager
AppearanceSettings.Layout.PagerReversed -> R.raw.lottie_scaffold_pager_reverse
else -> 0
}
)