Add reverse pager layout
This commit is contained in:
parent
8b0e96b628
commit
18539c5f64
1
base/src/main/res/raw/lottie_scaffold_pager_reverse.json
Normal file
1
base/src/main/res/raw/lottie_scaffold_pager_reverse.json
Normal file
File diff suppressed because one or more lines are too long
@ -68,6 +68,7 @@ message Settings {
|
|||||||
enum Layout {
|
enum Layout {
|
||||||
PullDown = 0;
|
PullDown = 0;
|
||||||
Pager = 1;
|
Pager = 1;
|
||||||
|
PagerReversed = 2;
|
||||||
}
|
}
|
||||||
Layout layout = 9;
|
Layout layout = 9;
|
||||||
|
|
||||||
|
|||||||
@ -122,7 +122,8 @@ class LauncherActivity : BaseActivity() {
|
|||||||
darkNavBarIcons = lightNav,
|
darkNavBarIcons = lightNav,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Settings.AppearanceSettings.Layout.Pager -> {
|
Settings.AppearanceSettings.Layout.Pager,
|
||||||
|
Settings.AppearanceSettings.Layout.PagerReversed -> {
|
||||||
PagerScaffold(
|
PagerScaffold(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@ -133,6 +134,7 @@ class LauncherActivity : BaseActivity() {
|
|||||||
},
|
},
|
||||||
darkStatusBarIcons = lightStatus,
|
darkStatusBarIcons = lightStatus,
|
||||||
darkNavBarIcons = lightNav,
|
darkNavBarIcons = lightNav,
|
||||||
|
reverse = layout == Settings.AppearanceSettings.Layout.PagerReversed
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
|
|||||||
@ -28,8 +28,10 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
|||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.Velocity
|
import androidx.compose.ui.unit.Velocity
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
@ -53,6 +55,7 @@ fun PagerScaffold(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
darkStatusBarIcons: Boolean = false,
|
darkStatusBarIcons: Boolean = false,
|
||||||
darkNavBarIcons: Boolean = false,
|
darkNavBarIcons: Boolean = false,
|
||||||
|
reverse: Boolean = false,
|
||||||
) {
|
) {
|
||||||
val viewModel: LauncherScaffoldVM = viewModel()
|
val viewModel: LauncherScaffoldVM = viewModel()
|
||||||
val searchVM: SearchVM = viewModel()
|
val searchVM: SearchVM = viewModel()
|
||||||
@ -213,9 +216,11 @@ fun PagerScaffold(
|
|||||||
|
|
||||||
val widthPx = width.toPixels()
|
val widthPx = width.toPixels()
|
||||||
|
|
||||||
|
val originalLayoutDirection = LocalLayoutDirection.current
|
||||||
|
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalOverscrollConfiguration provides null
|
LocalOverscrollConfiguration provides null,
|
||||||
|
LocalLayoutDirection provides if (reverse) LayoutDirection.Rtl else LayoutDirection.Ltr
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
@ -232,61 +237,67 @@ fun PagerScaffold(
|
|||||||
thresholds = { _, _ ->
|
thresholds = { _, _ ->
|
||||||
FractionalThreshold(0.5f)
|
FractionalThreshold(0.5f)
|
||||||
},
|
},
|
||||||
enabled = !isWidgetEditMode
|
enabled = !isWidgetEditMode,
|
||||||
|
reverseDirection = reverse,
|
||||||
)
|
)
|
||||||
.offset {
|
.offset {
|
||||||
IntOffset(swipeableState.offset.value.roundToInt(), 0)
|
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(
|
val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp)
|
||||||
if (isWidgetsScrollZero) 64.dp + insets.calculateBottomPadding() else 0.dp
|
|
||||||
)
|
|
||||||
|
|
||||||
val clockHeight by remember {
|
val clockPadding by animateDpAsState(
|
||||||
derivedStateOf {
|
if (isWidgetsScrollZero) 64.dp + insets.calculateBottomPadding() else 0.dp
|
||||||
height - (64.dp + insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding)
|
)
|
||||||
|
|
||||||
|
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,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ internal fun placeRightOrBottom(
|
|||||||
current += it
|
current += it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun IntArray.forEachIndexed(reversed: Boolean, action: (Int, Int) -> Unit) {
|
private inline fun IntArray.forEachIndexed(reversed: Boolean, action: (Int, Int) -> Unit) {
|
||||||
if (!reversed) {
|
if (!reversed) {
|
||||||
forEachIndexed(action)
|
forEachIndexed(action)
|
||||||
|
|||||||
@ -481,6 +481,7 @@ fun LayoutPreference(
|
|||||||
when (layouts[it]) {
|
when (layouts[it]) {
|
||||||
AppearanceSettings.Layout.PullDown -> R.raw.lottie_scaffold_pulldown
|
AppearanceSettings.Layout.PullDown -> R.raw.lottie_scaffold_pulldown
|
||||||
AppearanceSettings.Layout.Pager -> R.raw.lottie_scaffold_pager
|
AppearanceSettings.Layout.Pager -> R.raw.lottie_scaffold_pager
|
||||||
|
AppearanceSettings.Layout.PagerReversed -> R.raw.lottie_scaffold_pager_reverse
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user