Skip to content

Instantly share code, notes, and snippets.

private func layoutItems(...) {
....
let layoutAttributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
layoutAttributes.frame = CGRect(
x: offsetX,
y: offsetY,
width: itemWidth,
height: itemHeight
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return allItemAttributes.filter { rect.intersects($0.frame) }
}
override func prepare() {
super.prepare()
guard let collectionView = collectionView, let delegate = delegate else {
return
}
guard collectionView.numberOfSections > 0 else { return }
var position: CGFloat = 0.0
(0 ..< numberOfSections).forEach { section in
layoutHeader(position: &position, collectionView: collectionView, delegate: delegate, section: section)
weak var delegate: CollectionViewLayoutDelegate?
private var allItemAttributes = [UICollectionViewLayoutAttributes]()
private var columnOffsetsY = [[CGFloat]]()
....
@ShoMasegi
ShoMasegi / MainController_Carousel_Row.kt
Created February 24, 2019 11:44
MainController_Carousel_Row.kt
@ShoMasegi
ShoMasegi / MainController_VisibilityEvent.kt
Created February 24, 2019 11:43
MainController_VisibilityEvent.kt
modelView {
id("header view")
onVisibilityStateChanged { model, view, visibilityState ->
// Do something with the new visibility state
}
onVisibilityChanged { model, view, percentVisibleHeight, percentVisibleWidth, visibleHeight, visibleWidth ,view ->
// Do something with the visibility information
}
}
@ShoMasegi
ShoMasegi / MainController_header.kt
Created February 24, 2019 11:41
MainController_header.kt
headerView {
id("header view")
cityName(data.name)
description(data.description)
...
}
@ShoMasegi
ShoMasegi / EpoxyExt.kt
Created February 24, 2019 10:43
Epoxy_Layout
inline fun EpoxyController.carousel(modelInitializer: CarouselModelBuilder.() -> Unit) {
CarouselModel_().apply {
modelInitializer()
}.addTo(this)
}
inline fun <T> CarouselModelBuilder.withModelsFrom(
items: List<T>,
modelBuilder: (T) -> EpoxyModel<*>
) {
@ShoMasegi
ShoMasegi / MainController.kt
Created February 24, 2019 08:23
Epoxy_Layout
class MainController internal constructor(): TypedEpoxyController<City>() {
interface Delegate {
fun onLinkClick(view: View) {}
fun onHeaderViewVisibilityChanged(percentVisibleHeight: Float) {}
}
var delegate: Delegate? = null
override fun buildModels(data: City?) {
data ?: return
@ShoMasegi
ShoMasegi / epoxy_layout_header_view.xml
Last active February 24, 2019 07:29
Epoxy_Layout
<?xml version="1.0" encoding="utf-8"?>
<layout ...>
<data>
<variable
name="cityName"
type="String" />
<variable
name="description"
type="String" />
</data>