{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

SubcomposeSlotReusePolicy

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.

Summary

Nested types

public final class SubcomposeSlotReusePolicy.SlotIdsSet implements Collection

Set containing slot ids currently available to reuse.

Public methods

abstract boolean
areCompatible(Object slotId, Object reusableSlotId)

Returns true if the content previously composed with reusableSlotId is compatible with the content which is going to be composed for slotId.

abstract void

This function will be called with slotIds set populated with the slot ids available to reuse.

Public methods

areCompatible

abstract boolean areCompatible(Object slotId, Object reusableSlotId)

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.

getSlotsToRetain

abstract void getSlotsToRetain(@NonNull SubcomposeSlotReusePolicy.SlotIdsSet slotIds)

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.