Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0458fa92 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge changes I2af44e3a,If75226f3,I0a5cbf01

* changes:
  Add SettingsFontFamily for SpaLib
  Add SearchScaffold for SpaLib
  Upgrade Compose version to 1.3 for SpaLib
parents e7eb1719 7bae0f83
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -18,9 +18,8 @@ buildscript {
    ext {
        spa_min_sdk = 21
        spa_target_sdk = 33
        jetpack_compose_version = '1.2.0-alpha04'
        jetpack_compose_version = '1.3.0'
        jetpack_compose_compiler_version = '1.3.2'
        jetpack_compose_material3_version = '1.0.0-alpha06'
    }
}
plugins {
+8 −3
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@
package com.android.settingslib.spa.gallery.page

import android.os.Bundle
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
import com.android.settingslib.spa.framework.common.SettingsPage
@@ -48,13 +51,15 @@ object SettingsPagerPageProvider : SettingsPageProvider {

    @Composable
    override fun Page(arguments: Bundle?) {
        SettingsScaffold(title = TITLE) {
        SettingsScaffold(title = TITLE) { paddingValues ->
            Box(Modifier.padding(paddingValues)) {
                SettingsPager(listOf("Personal", "Work")) {
                    PlaceholderTitle("Page $it")
                }
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ android {

dependencies {
    api "androidx.appcompat:appcompat:1.7.0-alpha01"
    api "androidx.compose.material3:material3:$jetpack_compose_material3_version"
    api "androidx.compose.material3:material3:1.1.0-alpha01"
    api "androidx.compose.material:material-icons-extended:$jetpack_compose_version"
    api "androidx.compose.runtime:runtime-livedata:$jetpack_compose_version"
    api "androidx.compose.ui:ui-tooling-preview:$jetpack_compose_version"
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.settingslib.spa.framework.compose

import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.KeyboardActionScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter

/**
 * An action when run, hides the keyboard if it's open.
 */
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun hideKeyboardAction(): KeyboardActionScope.() -> Unit {
    val keyboardController = LocalSoftwareKeyboardController.current
    return { keyboardController?.hide() }
}

/**
 * Creates a [LazyListState] that is remembered across compositions.
 *
 * And when user scrolling the lazy list, hides the keyboard if it's open.
 */
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun rememberLazyListStateAndHideKeyboardWhenStartScroll(): LazyListState {
    val listState = rememberLazyListState()
    val keyboardController = LocalSoftwareKeyboardController.current
    LaunchedEffect(listState) {
        snapshotFlow { listState.isScrollInProgress }
            .distinctUntilChanged()
            .filter { it }
            .collect { keyboardController?.hide() }
    }
    return listState
}
+2 −1
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filter
@@ -214,6 +213,7 @@ internal fun Pager(
            horizontalAlignment = horizontalAlignment,
            reverseLayout = reverseLayout,
            contentPadding = contentPadding,
            userScrollEnabled = false,
            modifier = modifier,
        ) {
            items(
@@ -241,6 +241,7 @@ internal fun Pager(
            horizontalArrangement = Arrangement.spacedBy(itemSpacing, horizontalAlignment),
            reverseLayout = reverseLayout,
            contentPadding = contentPadding,
            userScrollEnabled = false,
            modifier = modifier,
        ) {
            items(
Loading