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
This commit is contained in:
1 parent
950b841d3d
commit
dc587e5601
3 files changed
+206
No files matched your search
@@ -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",
|
||||
|
||||
+79
@@ -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
|
||||
}
|
||||
+125
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user