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

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

Merge "Adding animation to edit widget button" into main

parents 31833dee ef6348dc
Loading
Loading
Loading
Loading
+73 −31
Original line number Diff line number Diff line
@@ -24,7 +24,11 @@ import android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
import android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
import android.widget.FrameLayout
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.BorderStroke
@@ -83,10 +87,13 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.scale
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.pointer.motionEventSpy
@@ -289,13 +296,14 @@ fun CommunalHub(
                removeEnabled = removeButtonEnabled
            )
        }

        if (currentPopup != null) {
            when (currentPopup) {
                PopupType.CtaTile -> {
        if (currentPopup == PopupType.CtaTile) {
            PopupOnDismissCtaTile(viewModel::onHidePopup)
        }
                PopupType.CustomizeWidgetButton -> {

        AnimatedVisibility(
            visible = currentPopup == PopupType.CustomizeWidgetButton,
            modifier = Modifier.fillMaxSize()
        ) {
            ButtonToEditWidgets(
                onClick = {
                    viewModel.onHidePopup()
@@ -304,9 +312,6 @@ fun CommunalHub(
                onHide = { viewModel.onHidePopup() }
            )
        }
                null -> {}
            }
        }

        if (viewModel is CommunalViewModel && dialogFactory != null) {
            val isEnableWidgetDialogShowing by
@@ -654,17 +659,53 @@ private fun Toolbar(
    }
}

@OptIn(ExperimentalAnimationApi::class)
@Composable
private fun ButtonToEditWidgets(
private fun AnimatedVisibilityScope.ButtonToEditWidgets(
    onClick: () -> Unit,
    onHide: () -> Unit,
) {
    Popup(alignment = Alignment.TopCenter, offset = IntOffset(0, 40), onDismissRequest = onHide) {
    Popup(
        alignment = Alignment.TopCenter,
        offset = IntOffset(0, 40),
        onDismissRequest = onHide,
    ) {
        val colors = LocalAndroidColorScheme.current
        Button(
            modifier =
                Modifier.height(56.dp).background(colors.secondary, RoundedCornerShape(50.dp)),
                Modifier.height(56.dp)
                    .graphicsLayer { transformOrigin = TransformOrigin(0f, 0f) }
                    .animateEnterExit(
                        enter =
                            fadeIn(
                                initialAlpha = 0f,
                                animationSpec = tween(durationMillis = 500, easing = LinearEasing)
                            ),
                        exit =
                            fadeOut(
                                animationSpec = tween(durationMillis = 500, easing = LinearEasing)
                            )
                    )
                    .background(colors.secondary, RoundedCornerShape(50.dp)),
            onClick = onClick,
        ) {
            Row(
                modifier =
                    Modifier.animateEnterExit(
                        enter =
                            fadeIn(
                                animationSpec =
                                    tween(
                                        durationMillis = 167,
                                        delayMillis = 500,
                                        easing = LinearEasing
                                    )
                            ),
                        exit =
                            fadeOut(
                                animationSpec = tween(durationMillis = 167, easing = LinearEasing)
                            )
                    )
            ) {
                Icon(
                    imageVector = Icons.Outlined.Widgets,
@@ -676,11 +717,12 @@ private fun ButtonToEditWidgets(
                Text(
                    text = stringResource(R.string.button_to_configure_widgets_text),
                    style = MaterialTheme.typography.titleSmall,
                color = colors.onSecondary,
                    color = colors.onSecondary
                )
            }
        }
    }
}

@Composable
private fun PopupOnDismissCtaTile(onHidePopup: () -> Unit) {