mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3541 Ui | Fix | Fix crash in ShimmerEffect due to invalid colorResource usage (#2350)
This commit is contained in:
parent
b16ffacaf7
commit
8a353afb9a
3 changed files with 50 additions and 25 deletions
|
@ -9,11 +9,15 @@ import androidx.compose.animation.core.tween
|
|||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anytypeio.anytype.core_ui.R
|
||||
|
||||
@Composable
|
||||
|
@ -27,11 +31,13 @@ fun ShimmerEffect(
|
|||
val colorStart = colorResource(id = R.color.background_secondary)
|
||||
val colorEnd = colorResource(id = R.color.shape_secondary)
|
||||
|
||||
val shimmerColors = listOf(
|
||||
colorStart,
|
||||
colorEnd,
|
||||
colorStart
|
||||
)
|
||||
// Compose-safe gradient color list
|
||||
val shimmerColors = remember(colorStart, colorEnd) {
|
||||
listOf(colorStart, colorEnd, colorStart)
|
||||
}
|
||||
|
||||
// Prevent crash: verify color list is valid before creating Brush
|
||||
if (shimmerColors.size < 2) return
|
||||
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "")
|
||||
|
||||
|
@ -64,3 +70,13 @@ fun ShimmerEffect(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
@DefaultPreviews
|
||||
@Composable
|
||||
fun ShimmerEffectPreview() {
|
||||
ShimmerEffect(
|
||||
modifier = Modifier
|
||||
.width(164.dp)
|
||||
.height(18.dp)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.anytypeio.anytype.presentation.editor.editor.listener.ListenerType
|
|||
import com.anytypeio.anytype.presentation.objects.ObjectIcon
|
||||
import com.anytypeio.anytype.presentation.relations.ObjectRelationView
|
||||
import com.anytypeio.anytype.presentation.sets.model.ObjectView
|
||||
import timber.log.Timber
|
||||
|
||||
class RelationValueListWidget @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -418,27 +419,35 @@ class RelationValueListWidget @JvmOverloads constructor(
|
|||
private fun setLinksRelation(relation: ObjectRelationView.Links) {
|
||||
when (relation) {
|
||||
is ObjectRelationView.Links.From -> {
|
||||
val count = context.resources.getQuantityString(
|
||||
R.plurals.links_from_count,
|
||||
relation.count,
|
||||
relation.count
|
||||
)
|
||||
setupSingleTextItem(
|
||||
name = count,
|
||||
textColor = textColorPrimary
|
||||
)
|
||||
try {
|
||||
val count = context.resources.getQuantityString(
|
||||
R.plurals.links_from_count,
|
||||
relation.count,
|
||||
relation.count
|
||||
)
|
||||
setupSingleTextItem(
|
||||
name = count,
|
||||
textColor = textColorPrimary
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error while trying to show links in featured properties")
|
||||
}
|
||||
}
|
||||
|
||||
is ObjectRelationView.Links.Backlinks -> {
|
||||
val count = context.resources.getQuantityString(
|
||||
R.plurals.backlinks_count,
|
||||
relation.count,
|
||||
relation.count
|
||||
)
|
||||
setupSingleTextItem(
|
||||
name = count,
|
||||
textColor = textColorPrimary
|
||||
)
|
||||
try {
|
||||
val count = context.resources.getQuantityString(
|
||||
R.plurals.backlinks_count,
|
||||
relation.count,
|
||||
relation.count
|
||||
)
|
||||
setupSingleTextItem(
|
||||
name = count,
|
||||
textColor = textColorPrimary
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error while trying to show backlinks in featured properties")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1265,13 +1265,13 @@
|
|||
<!--endregion-->
|
||||
|
||||
<plurals name="backlinks_count">
|
||||
<item quantity="zero">$d backlinks</item>
|
||||
<item quantity="zero">%d backlinks</item>
|
||||
<item quantity="one">%d backlink</item>
|
||||
<item quantity="other">%d backlinks</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="links_from_count">
|
||||
<item quantity="zero">$d links</item>
|
||||
<item quantity="zero">%d links</item>
|
||||
<item quantity="one">%d link</item>
|
||||
<item quantity="other">%d links</item>
|
||||
</plurals>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue