Skip to content

Commit

Permalink
Fix implementation of StableList
Browse files Browse the repository at this point in the history
  • Loading branch information
fibelatti committed Jan 14, 2024
1 parent 8a120c4 commit cc1b299
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ui/src/main/java/com/fibelatti/ui/foundation/StableList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ package com.fibelatti.ui.foundation

import androidx.compose.runtime.Immutable
import java.util.Collections
import java.util.Objects

/**
* An [Immutable] wrapper class that delegates to a [List] of [T] in order to provide stability to
* a composable when needed.
*/
@Immutable
class StableList<T> private constructor(items: List<T>) : List<T> by items {
class StableList<T> private constructor(private val items: List<T>) : List<T> by items {

override fun equals(other: Any?): Boolean = when {
this === other -> true
other !is StableList<*> -> false
else -> items == other.items
}

override fun hashCode(): Int = Objects.hashCode(items)

companion object {

Expand Down

0 comments on commit cc1b299

Please sign in to comment.