Created
July 29, 2021 11:32
-
-
Save ch8n/c91c1cfa6fad0826ac3842ad64e36cfe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// layout manager calls function getViewForPosition over recycler | |
// thus has a recycler. | |
class LayoutManager(private val recycler: Recycler) { | |
fun getViewForPosition(pos: Int): View { | |
return recycler.getView(pos) | |
} | |
} | |
class RecyclerView( | |
private val viewCache: ViewCache | |
) { | |
fun getView(pos: Int): View { | |
val viewOrNull = viewCache.getOrNull(pos) | |
// view found then return view | |
if (viewOrNull != null) { | |
return viewOrNull | |
} | |
return TODO() | |
} | |
} | |
class ViewCache { | |
private val viewCache = mutableMapOf<Int, View>() // LRU cache | |
fun getOrNull(pos: Int): View? = viewCache.get(pos) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment