From dc587e560188ca6bcf71989dc02fe5899f5e3c4d Mon Sep 17 00:00:00 2001 From: Shamali P Date: Mon, 12 May 2025 13:18:39 +0000 Subject: [PATCH] Add top level reusable layouts for widget picker Bug: 408283627 Flag: EXEMPT independent module Test: See demo; will be part of larger screenshot test Change-Id: I10ebc3982b9c64b4b475a3d2201bf1afb1ad654a --- modules/widgetpicker/Android.bp | 2 + .../ui/components/SinglePaneLayout.kt | 79 +++++++++++ .../ui/components/TwoPaneLayout.kt | 125 ++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/SinglePaneLayout.kt create mode 100644 modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TwoPaneLayout.kt diff --git a/modules/widgetpicker/Android.bp b/modules/widgetpicker/Android.bp index 46ea0a540d..f9df984376 100644 --- a/modules/widgetpicker/Android.bp +++ b/modules/widgetpicker/Android.bp @@ -90,6 +90,8 @@ android_library { "src/com/android/launcher3/widgetpicker/ui/components/ScrollableFloatingToolbar.kt", "src/com/android/launcher3/widgetpicker/ui/components/LeadingIconToolbarTab.kt", "src/com/android/launcher3/widgetpicker/ui/components/TitledBottomSheet.kt", + "src/com/android/launcher3/widgetpicker/ui/components/TwoPaneLayout.kt", + "src/com/android/launcher3/widgetpicker/ui/components/SinglePaneLayout.kt", ], static_libs: [ "androidx.compose.foundation_foundation", diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/SinglePaneLayout.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/SinglePaneLayout.kt new file mode 100644 index 0000000000..e53e86b224 --- /dev/null +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/SinglePaneLayout.kt @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2025 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 + * + * http://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.android.launcher3.widgetpicker.ui.components + +/* + * Copyright (C) 2025 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 + * + * http://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. + */ + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.android.launcher3.widgetpicker.ui.components.SinglePaneLayoutDimensions.searchBarBottomMargin + +/** + * A layout that shows all the widget picker content in a column like pane. + * + * @param searchBar A sticky search bar shown on top in the left pane. + * @param toolbar an option toolbar shown at bottom of the screen that allows users to select what + * to see in the [content] + * @param content the primary content e.g. widgets expand collapse list. + */ +@Composable +fun SinglePaneLayout( + searchBar: @Composable () -> Unit, + toolbar: (@Composable () -> Unit)? = null, + content: @Composable () -> Unit, +) { + val topContent: @Composable ColumnScope.() -> Unit = { + Column(modifier = Modifier.fillMaxWidth().weight(1f)) { + searchBar() + Spacer(modifier = Modifier.fillMaxWidth().height(searchBarBottomMargin)) + content() + } + } + + val bottomContent: @Composable ColumnScope.() -> Unit = { toolbar?.let { it() } } + + Column(modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) { + topContent() + bottomContent() + } +} + +private object SinglePaneLayoutDimensions { + val searchBarBottomMargin = 16.dp +} diff --git a/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TwoPaneLayout.kt b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TwoPaneLayout.kt new file mode 100644 index 0000000000..7d9eb43615 --- /dev/null +++ b/modules/widgetpicker/src/com/android/launcher3/widgetpicker/ui/components/TwoPaneLayout.kt @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2025 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 + * + * http://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.android.launcher3.widgetpicker.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.semantics.isTraversalGroup +import androidx.compose.ui.semantics.paneTitle +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.dp +import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayoutDimensions.LEFT_PANE_WEIGHT +import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayoutDimensions.RIGHT_PANE_WEIGHT +import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayoutDimensions.horizontalPadding +import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayoutDimensions.paneSpacing +import com.android.launcher3.widgetpicker.ui.components.TwoPaneLayoutDimensions.searchBarBottomMargin + +/** + * A layout that splits the widget picker content into two panes where the left pane takes about + * [LEFT_PANE_WEIGHT] space while the right pane takes the remaining. + * + * The left pane always has a [searchBar] on the top and the left and right panes contain dynamic + * content based on the user's actions. + * + * @param searchBar A sticky search bar shown on top in the left pane. + * @param leftContent list options available for user to select that will be shown on left + * @param rightContent content for the currently selected list option + * @param rightPaneTitle when a user selects an option on left pane, changing this title for right + * pane guides the user that content for selected option is now visible on right. When using + * accessibility services like talkback, after selecting an option on left, the users can use four + * finger swipe down to move focus to the right pane. + * @param rightPaneBackgroundColor color to use for that background of content on right. + */ +@Composable +fun TwoPaneLayout( + searchBar: @Composable () -> Unit, + leftContent: @Composable () -> Unit, + rightContent: @Composable () -> Unit, + rightPaneTitle: String?, + rightPaneBackgroundColor: Color = TwoPaneLayoutDefaults.rightPaneBackgroundColor, +) { + val rightPaneModifier = + if (rightPaneTitle != null) { + Modifier.semantics { paneTitle = rightPaneTitle } + } else Modifier + + val leftPane: @Composable RowScope.() -> Unit = { + Column( + modifier = + Modifier.semantics { isTraversalGroup = true } + .fillMaxHeight() + .padding(end = paneSpacing) + .weight(LEFT_PANE_WEIGHT) + ) { + searchBar() + Spacer(modifier = Modifier.height(searchBarBottomMargin).fillMaxWidth()) + leftContent() + } + } + + val rightPane: @Composable RowScope.() -> Unit = { + Box( + contentAlignment = Alignment.Center, + modifier = + rightPaneModifier + .fillMaxHeight() + .weight(RIGHT_PANE_WEIGHT) + .clip(TwoPaneLayoutDimensions.rightPaneShape) + .background(rightPaneBackgroundColor), + ) { + rightContent() + } + } + + Row(modifier = Modifier.padding(horizontal = horizontalPadding).fillMaxSize()) { + leftPane() + rightPane() + } +} + +private object TwoPaneLayoutDimensions { + const val LEFT_PANE_WEIGHT = 0.37f + const val RIGHT_PANE_WEIGHT = 1 - LEFT_PANE_WEIGHT + + val horizontalPadding = 14.dp + val paneSpacing = 16.dp + + val searchBarBottomMargin = 16.dp + + val rightPaneShape = RoundedCornerShape(28.dp) +} + +private object TwoPaneLayoutDefaults { + val rightPaneBackgroundColor + @Composable get() = MaterialTheme.colorScheme.surfaceBright +}