Prevent some unnecessary recompositions

This commit is contained in:
MM20 2022-05-16 22:25:55 +02:00
parent 308795265c
commit cb5be66e01
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 35 additions and 27 deletions

View File

@ -36,6 +36,7 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.ktx.toPixels
import de.mm20.launcher2.ui.launcher.helper.WallpaperBlur
import de.mm20.launcher2.ui.launcher.search.SearchBar
import de.mm20.launcher2.ui.launcher.search.SearchBarLevel
import de.mm20.launcher2.ui.launcher.search.SearchColumn
@ -102,21 +103,8 @@ fun PagerScaffold(
}
}
val density = LocalDensity.current
LaunchedEffect(blurWallpaper) {
if (!isAtLeastApiLevel(31)) return@LaunchedEffect
(context as Activity).window.attributes = context.window.attributes.also {
if (blurWallpaper) {
it.blurBehindRadius = with(density) { 32.dp.toPx().toInt() }
it.flags = it.flags or WindowManager.LayoutParams.FLAG_BLUR_BEHIND
} else {
it.blurBehindRadius = 0
it.flags = it.flags and WindowManager.LayoutParams.FLAG_BLUR_BEHIND.inv()
}
}
WallpaperBlur {
blurWallpaper
}
val currentPage = swipeableState.currentValue

View File

@ -42,6 +42,7 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.ktx.animateTo
import de.mm20.launcher2.ui.launcher.helper.WallpaperBlur
import de.mm20.launcher2.ui.launcher.search.SearchBar
import de.mm20.launcher2.ui.launcher.search.SearchBarLevel
import de.mm20.launcher2.ui.launcher.search.SearchColumn
@ -109,18 +110,8 @@ fun PullDownScaffold(
}
}
LaunchedEffect(blurWallpaper) {
if (!isAtLeastApiLevel(31)) return@LaunchedEffect
(context as Activity).window.attributes = context.window.attributes.also {
if (blurWallpaper) {
it.blurBehindRadius = with(density) { 32.dp.toPx().toInt() }
it.flags = it.flags or WindowManager.LayoutParams.FLAG_BLUR_BEHIND
} else {
it.blurBehindRadius = 0
it.flags = it.flags and WindowManager.LayoutParams.FLAG_BLUR_BEHIND.inv()
}
}
WallpaperBlur {
blurWallpaper
}

View File

@ -0,0 +1,29 @@
package de.mm20.launcher2.ui.launcher.helper
import android.app.Activity
import android.view.WindowManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import de.mm20.launcher2.ktx.isAtLeastApiLevel
@Composable
fun WallpaperBlur(blur: () -> Boolean) {
val context = LocalContext.current
val density = LocalDensity.current
val blurWallpaper = blur()
LaunchedEffect(blurWallpaper) {
if (!isAtLeastApiLevel(31)) return@LaunchedEffect
(context as Activity).window.attributes = context.window.attributes.also {
if (blurWallpaper) {
it.blurBehindRadius = with(density) { 32.dp.toPx().toInt() }
it.flags = it.flags or WindowManager.LayoutParams.FLAG_BLUR_BEHIND
} else {
it.blurBehindRadius = 0
it.flags = it.flags and WindowManager.LayoutParams.FLAG_BLUR_BEHIND.inv()
}
}
}
}