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

Commit c4c6334e authored by Kelly Zhang's avatar Kelly Zhang Committed by Android (Google) Code Review
Browse files

Merge "Support Lottie resouces in Illustration widget in SPA."

parents 0d7ea363 196b1ee8
Loading
Loading
Loading
Loading
+1959 −0

File added.

Preview size limit exceeded, changes collapsed.

+9 −0
Original line number Diff line number Diff line
@@ -53,6 +53,15 @@ object IllustrationPageProvider : SettingsPageProvider {
@Composable
private fun IllustrationPage() {
    Column(Modifier.verticalScroll(rememberScrollState())) {
        Preference(object : PreferenceModel {
            override val title = "Lottie Illustration"
        })

        Illustration(object : IllustrationModel {
            override val resId = R.raw.accessibility_shortcut_type_triple_tap
            override val resourceType = ResourceType.LOTTIE
        })

        Preference(object : PreferenceModel {
            override val title = "Image Illustration"
        })
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ android_library {
        "androidx.compose.ui_ui-tooling-preview",
        "androidx.navigation_navigation-compose",
        "com.google.android.material_material",
        "lottie_compose",
    ],
    kotlincflags: [
        "-Xjvm-default=all",
+6 −3
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.widget.ui.ImageBox

import com.android.settingslib.spa.widget.ui.Lottie
enum class ResourceType { IMAGE, LOTTIE }

/**
@@ -72,7 +72,7 @@ fun Illustration(
    Column(
        modifier = modifier
            .fillMaxWidth()
            .padding(SettingsDimension.illustrationPadding),
            .padding(horizontal = SettingsDimension.illustrationPadding),
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        val illustrationModifier = modifier
@@ -85,7 +85,10 @@ fun Illustration(

        when (resourceType) {
            ResourceType.LOTTIE -> {
                // TODO: Add Lottie function after lottie is enabled.
                Lottie(
                    resId = resId,
                    modifier = illustrationModifier,
                )
            }
            ResourceType.IMAGE -> {
                ImageBox(
+54 −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.widget.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition

@Composable
fun Lottie(
    resId: Int,
    modifier: Modifier = Modifier,
) {
    Box(
        modifier = modifier,
    ) {
        BaseLottie(resId)
    }
}

@Composable
private fun BaseLottie(resId: Int) {
    val composition by rememberLottieComposition(
        LottieCompositionSpec.RawRes(resId)
    )
    val progress by animateLottieCompositionAsState(
        composition,
        iterations = LottieConstants.IterateForever,
    )
    LottieAnimation(
        composition = composition,
        progress = { progress },
    )
}
Loading