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

Commit 7aac32dd authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Spa] Clean up LiveData" into main

parents b9e4f73b 3818328c
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@ android_library {
        "androidx.compose.material3_material3",
        "androidx.compose.material_material-icons-extended",
        "androidx.compose.runtime_runtime",
        "androidx.compose.runtime_runtime-livedata",
        "androidx.compose.ui_ui-tooling-preview",
        "androidx.lifecycle_lifecycle-livedata-ktx",
        "androidx.lifecycle_lifecycle-runtime-compose",
        "androidx.navigation_navigation-compose",
        "androidx.window_window",
+0 −2
Original line number Diff line number Diff line
@@ -57,10 +57,8 @@ dependencies {
    api("androidx.appcompat:appcompat:1.7.0")
    api("androidx.compose.material3:material3:1.4.0-alpha15")
    api("androidx.compose.material:material-icons-extended:1.7.8")
    api("androidx.compose.runtime:runtime-livedata:$jetpackComposeVersion")
    api("androidx.compose.ui:ui-tooling-preview:$jetpackComposeVersion")
    api("androidx.graphics:graphics-shapes-android:1.0.1")
    api("androidx.lifecycle:lifecycle-livedata-ktx")
    api("androidx.lifecycle:lifecycle-runtime-compose")
    api("androidx.navigation:navigation-compose:2.9.0")
    api("androidx.window:window:1.5.0-alpha02")
+0 −34
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.livedata

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.lifecycle.LiveData

/**
 * Starts observing this LiveData and represents its values via State and Callback.
 *
 * Every time there would be new value posted into the LiveData the returned State will be updated
 * causing recomposition of every Callback usage.
 */
@Composable
fun <T> LiveData<T>.observeAsCallback(): () -> T? {
    val isAllowed by observeAsState()
    return { isAllowed }
}