Minor Compose API migrations (#3493)
* Add labels * Remove OptIn * Remove ExperimentalPagerApis * remember selectedColorApplied * Migrate HorizontalPager
This commit is contained in:
1 parent
bb8ab21bd0
commit
b2bd05c851
13 files changed
+32
-33
No files matched your search
@@ -304,7 +304,6 @@ class FontCache private constructor(private val context: Context) {
|
||||
private val hashCode = "AssetFont|$name".hashCode()
|
||||
|
||||
override val fullDisplayName = name
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
override val composeFontFamily = FontFamily(ComposeFont("$name.ttf", assets))
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
@@ -336,7 +335,6 @@ class FontCache private constructor(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
class GoogleFont(
|
||||
private val context: Context,
|
||||
private val family: String,
|
||||
@@ -477,7 +475,6 @@ class FontCache private constructor(private val context: Context) {
|
||||
Pair("900", R.string.font_weight_extra_black)
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
val provider = ComposeGoogleFont.Provider(
|
||||
providerAuthority = "com.google.android.gms.fonts",
|
||||
providerPackage = "com.google.android.gms",
|
||||
|
||||
@@ -232,7 +232,7 @@ private fun ClipboardButton(
|
||||
startWidget = {
|
||||
val tint = LocalContentColor.current
|
||||
val contentAlpha = if (enabled) tint.alpha else ContentAlpha.disabled
|
||||
val alpha by animateFloatAsState(targetValue = contentAlpha)
|
||||
val alpha by animateFloatAsState(targetValue = contentAlpha, label = "")
|
||||
Icon(
|
||||
imageVector = imageVector,
|
||||
contentDescription = null,
|
||||
|
||||
@@ -53,7 +53,7 @@ fun HiddenAppsPreferences() {
|
||||
PreferenceScaffold(
|
||||
label = pageTitle,
|
||||
) {
|
||||
Crossfade(targetState = apps.isNotEmpty()) { present ->
|
||||
Crossfade(targetState = apps.isNotEmpty(), label = "") { present ->
|
||||
if (present) {
|
||||
PreferenceLazyColumn(state = state) {
|
||||
val toggleHiddenApp = { app: App ->
|
||||
|
||||
@@ -284,7 +284,6 @@ private fun getIconPackItemWidth(
|
||||
return iconPackItemWidth
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun IconPackItem(
|
||||
item: IconPackInfo,
|
||||
|
||||
@@ -41,7 +41,7 @@ fun PickAppForGesture() {
|
||||
PreferenceScaffold(
|
||||
label = stringResource(id = R.string.pick_app_for_gesture),
|
||||
) {
|
||||
Crossfade(targetState = apps.isNotEmpty()) { present ->
|
||||
Crossfade(targetState = apps.isNotEmpty(), label = "") { present ->
|
||||
if (present) {
|
||||
PreferenceLazyColumn(state = state) {
|
||||
preferenceGroupItems(
|
||||
|
||||
@@ -68,7 +68,10 @@ fun SmartspacePreferences(fromWidget: Boolean) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Crossfade(targetState = (smartspaceAdapter.state.value || fromWidget) && modeIsLawnchair) { targetState ->
|
||||
Crossfade(
|
||||
targetState = (smartspaceAdapter.state.value || fromWidget) && modeIsLawnchair,
|
||||
label = "",
|
||||
) { targetState ->
|
||||
if (targetState) {
|
||||
Column {
|
||||
SmartspacePreview()
|
||||
|
||||
@@ -40,7 +40,7 @@ fun Chip(
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val selectedProgress by animateFloatAsState(targetValue = if (selected) 1f else 0f)
|
||||
val selectedProgress by animateFloatAsState(targetValue = if (selected) 1f else 0f, label = "")
|
||||
Chip(
|
||||
label = label,
|
||||
selectedProgress = selectedProgress,
|
||||
|
||||
@@ -27,7 +27,7 @@ fun ClickableIcon(
|
||||
enabled = enabled,
|
||||
) {
|
||||
val contentAlpha = if (enabled) tint.alpha else ContentAlpha.disabled
|
||||
val alpha by animateFloatAsState(targetValue = contentAlpha)
|
||||
val alpha by animateFloatAsState(targetValue = contentAlpha, label = "")
|
||||
Icon(
|
||||
painter = painter,
|
||||
contentDescription = null,
|
||||
|
||||
@@ -50,7 +50,7 @@ fun DummyLauncherLayout(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val previewView = createPreviewView(idp)
|
||||
Crossfade(targetState = previewView) {
|
||||
Crossfade(targetState = previewView, label = "") {
|
||||
val view = it
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
|
||||
@@ -29,7 +29,7 @@ import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun LoadingScreen(isLoading: Boolean, content: @Composable () -> Unit) {
|
||||
Crossfade(targetState = isLoading) {
|
||||
Crossfade(targetState = isLoading, label = "") {
|
||||
if (it) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
|
||||
+12
-10
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.graphics.Color
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
@@ -27,9 +28,8 @@ import app.lawnchair.ui.preferences.components.colorpreference.pickers.SwatchGri
|
||||
import app.lawnchair.ui.preferences.preferenceGraph
|
||||
import com.android.launcher3.R
|
||||
import com.google.accompanist.navigation.animation.composable
|
||||
import com.google.accompanist.pager.ExperimentalPagerApi
|
||||
import com.google.accompanist.pager.HorizontalPager
|
||||
import com.google.accompanist.pager.rememberPagerState
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import com.patrykmichalik.opto.domain.Preference
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -56,7 +56,7 @@ fun NavGraphBuilder.colorSelectionGraph(route: String) {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPagerApi::class)
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun ColorSelection(
|
||||
label: String,
|
||||
@@ -68,8 +68,10 @@ fun ColorSelection(
|
||||
val appliedColor = adapter.state.value
|
||||
val context = LocalContext.current
|
||||
val selectedColor = remember { mutableStateOf(appliedColor.forCustomPicker(context)) }
|
||||
val selectedColorApplied = derivedStateOf {
|
||||
appliedColor is ColorOption.CustomColor && appliedColor.color == selectedColor.value
|
||||
val selectedColorApplied = remember {
|
||||
derivedStateOf {
|
||||
appliedColor is ColorOption.CustomColor && appliedColor.color == selectedColor.value
|
||||
}
|
||||
}
|
||||
val defaultTabIndex = when {
|
||||
dynamicEntries.any { it.value == appliedColor } -> 0
|
||||
@@ -82,7 +84,7 @@ fun ColorSelection(
|
||||
adapter.onChange(newValue = option)
|
||||
}
|
||||
|
||||
val pagerState = rememberPagerState(defaultTabIndex)
|
||||
val pagerState = rememberPagerState(initialPage = defaultTabIndex)
|
||||
PreferenceLayout(
|
||||
label = label,
|
||||
bottomBar = {
|
||||
@@ -119,18 +121,18 @@ fun ColorSelection(
|
||||
Chip(
|
||||
label = stringResource(id = R.string.presets),
|
||||
onClick = { scrollToPage(0) },
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffset,
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffsetFraction,
|
||||
page = 0,
|
||||
)
|
||||
Chip(
|
||||
label = stringResource(id = R.string.custom),
|
||||
onClick = { scrollToPage(1) },
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffset,
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffsetFraction,
|
||||
page = 1,
|
||||
)
|
||||
}
|
||||
HorizontalPager(
|
||||
count = 2,
|
||||
pageCount = 2,
|
||||
state = pagerState,
|
||||
verticalAlignment = Alignment.Top,
|
||||
modifier = Modifier.animateContentSize(),
|
||||
|
||||
+8
-10
@@ -2,11 +2,11 @@ package app.lawnchair.ui.preferences.components.colorpreference.pickers
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.graphics.Color as AndroidColor
|
||||
import android.graphics.Color.argb
|
||||
import android.widget.Toast
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
@@ -42,9 +42,8 @@ import app.lawnchair.ui.preferences.components.PreferenceGroup
|
||||
import app.lawnchair.ui.preferences.components.colorpreference.*
|
||||
import app.lawnchair.util.requireSystemService
|
||||
import com.android.launcher3.R
|
||||
import com.google.accompanist.pager.ExperimentalPagerApi
|
||||
import com.google.accompanist.pager.HorizontalPager
|
||||
import com.google.accompanist.pager.rememberPagerState
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ import kotlinx.coroutines.launch
|
||||
* @see HsvColorPicker
|
||||
* @see RgbColorPicker
|
||||
*/
|
||||
@OptIn(ExperimentalPagerApi::class)
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun CustomColorPicker(
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -130,20 +129,20 @@ fun CustomColorPicker(
|
||||
Chip(
|
||||
label = stringResource(id = R.string.hsb),
|
||||
onClick = { scrollToPage(0) },
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffset,
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffsetFraction,
|
||||
page = 0,
|
||||
)
|
||||
Chip(
|
||||
label = stringResource(id = R.string.rgb),
|
||||
onClick = { scrollToPage(1) },
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffset,
|
||||
currentOffset = pagerState.currentPage + pagerState.currentPageOffsetFraction,
|
||||
page = 1,
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalPager(
|
||||
modifier = Modifier.animateContentSize(),
|
||||
count = 2,
|
||||
pageCount = 2,
|
||||
state = pagerState,
|
||||
verticalAlignment = Alignment.Top,
|
||||
) { page ->
|
||||
@@ -187,7 +186,6 @@ fun CustomColorPicker(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun HexColorPicker(
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -228,7 +226,7 @@ private fun HexColorPicker(
|
||||
},
|
||||
),
|
||||
trailingIcon = {
|
||||
Crossfade(targetState = invalidString) {
|
||||
Crossfade(targetState = invalidString, label = "") {
|
||||
if (it) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_warning),
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ fun <T> ColorSwatch(
|
||||
.background(Color(color))
|
||||
.clickable(onClick = onClick)
|
||||
) {
|
||||
Crossfade(targetState = selected) {
|
||||
Crossfade(targetState = selected, label = "") {
|
||||
if (it) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Done,
|
||||
|
||||
Reference in new issue
Block a user