public interface SubcomposeSlotReusePolicy
This policy allows SubcomposeLayout to retain some of slots which we were used but not used anymore instead of disposing them. Next time when you try to compose a new slot instead of creating a completely new slot the layout would reuse the kept slot. This allows to do less work especially if the slot contents are similar.
Functions
getSlotsToRetain
public fun getSlotsToRetain(slotIds: SlotIdsSet)
This function will be called with slotIds set populated with the slot ids available to reuse. In the implementation you can remove slots you don't want to retain.
areCompatible
public fun areCompatible(slotId: Any?, reusableSlotId: Any?): Boolean
Returns true if the content previously composed with reusableSlotId is compatible with the content which is going to be composed for slotId. Slots could be considered incompatible if they display completely different types of the UI.
Members
SlotIdsSet
public class SlotIdsSet internal constructor(
internal val set: MutableOrderedScatterSet<Any?> = mutableOrderedScatterSetOf()
) : Collection<Any?>
Set containing slot ids currently available to reuse. Used by getSlotsToRetain. The set retains the insertion order of its elements, guaranteeing stable iteration order.
This class works exactly as MutableSet, but doesn't allow to add new items in it.
Properties
size
public override val size: Int
Functions
remove
public fun remove(slotId: Any?): Boolean
Removes a slotId from this set, if it is present.
Return
true if the slot id was removed, false if the set was not modified.
removeAll
public fun removeAll(slotIds: Collection<Any?>): Boolean
Removes all slot ids from slotIds that are also contained in this set.
Return
true if any slot id was removed, false if the set was not modified.
removeAll
public fun removeAll(predicate: (Any?) -> Boolean): Boolean
Removes all slot ids that match the given predicate.
Return
true if any slot id was removed, false if the set was not modified.
retainAll
public fun retainAll(slotIds: Collection<Any?>): Boolean
Retains only the slot ids that are contained in slotIds.
Return
true if any slot id was removed, false if the set was not modified.
retainAll
public fun retainAll(predicate: (Any?) -> Boolean): Boolean
Retains only slotIds that match the given predicate.
Return
true if any slot id was removed, false if the set was not modified.
clear
public fun clear(): Unit
Removes all slot ids from this set.
trimToSize
public fun trimToSize(maxSlotsToRetainForReuse: Int): Unit
Remove entries until size equals maxSlotsToRetainForReuse. Entries inserted last are removed first.
forEach
public fun forEach(block: (Any?) -> Unit): Unit
Iterates over every element stored in this set by invoking the specified block lambda. The iteration order is the same as the insertion order. It is safe to remove the element passed to block during iteration.
NOTE: This method is obscured by Collection<T>.forEach since it is marked with
fastForEach
public inline fun fastForEach(block: (Any?) -> Unit): Unit
Iterates over every element stored in this set by invoking the specified block lambda. The iteration order is the same as the insertion order. It is safe to remove the element passed to block during iteration.
NOTE: this method was added in order to allow for a more performant forEach method. It is necessary because forEach is obscured by Collection<T>.forEach since it is marked with @HidesMember.