Daniel Okanin
07/03/2022, 4:23 PMstable class ProViewModelItem {
unstable val profileImage: ImageDescriptor?
unstable val coverImage: ImageDescriptor?
stable val numReviews: Int
stable val reviewRating: Float
}
This is how I declare this class:
@Stable
class ProViewModelItem(
id: String?, title: String?,
val profileImage: ImageDescriptor? = null,
val coverImage: ImageDescriptor? = null,
val numReviews: Int = 0,
val reviewRating: Float = 0f,
) : HomeFeedViewModelItem(id, title)
Francesc
07/03/2022, 5:16 PMstable
is a contract. It's ok if you uphold your part. How's your ImageDescriptor defined?Daniel Okanin
07/03/2022, 5:17 PMDaniel Okanin
07/03/2022, 5:18 PMequals
will always return the same result for the same two instances.
2. When a public property of the type changes, composition will be notified.
3. All public property types are stable.
SO i dont uphold my pard?Francesc
07/03/2022, 5:41 PMDaniel Okanin
07/03/2022, 6:03 PMStylianos Gakis
07/03/2022, 6:06 PMFrancesc
07/03/2022, 6:07 PMDaniel Okanin
07/03/2022, 6:12 PMDaniel Okanin
07/07/2022, 9:29 PMstable class PhotoViewModelItem {
unstable val imageDescriptor: ImageDescriptor?
stable val isSaved: MutableState<Boolean>
stable val photoType: PhotoType?
stable val tagsCount: Int
}
Francesc
07/07/2022, 9:31 PMImageDescriptor
is defined, you could annotatte it there. If you don't, you could wrap it in a class and mark it as @Immutable
- assuming the implementation is indeed immutable. This stuff was recently described here https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8Daniel Okanin
07/07/2022, 9:45 PMFrancesc
07/07/2022, 9:46 PMDaniel Okanin
07/07/2022, 9:48 PMFrancesc
07/07/2022, 9:55 PMequals
and hashCode
do not change, the object does not change. If it's immutable (doesn't change after construction) then those holdFrancesc
07/07/2022, 9:59 PMequals
to determine if it needs to recompose for immuable objects. If you use data classes you get that for free, otherwise you have to write the equals
to ensure a new, different object , does not yield the same equals
(you could break that if you omitted a field, for instance)Daniel Okanin
07/07/2022, 10:02 PM