This file contains 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
private func layoutItems(...) { | |
.... | |
let layoutAttributes = UICollectionViewLayoutAttributes(forCellWith: indexPath) | |
layoutAttributes.frame = CGRect( | |
x: offsetX, | |
y: offsetY, | |
width: itemWidth, | |
height: itemHeight |
This file contains 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
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
return allItemAttributes.filter { rect.intersects($0.frame) } | |
} |
This file contains 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
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) |
This file contains 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
weak var delegate: CollectionViewLayoutDelegate? | |
private var allItemAttributes = [UICollectionViewLayoutAttributes]() | |
private var columnOffsetsY = [[CGFloat]]() | |
.... |
This file contains 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
carousel { | |
id("carousel") | |
numViewsToShowOnScreen(1.05f) | |
padding(Carousel.Padding.dp(20, 24)) | |
withModelsFrom(items) { | |
HomeItemBindingModel_() | |
.id(it.id) | |
.title(it.title) | |
.username(it.username) | |
} |
This file contains 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
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 | |
} | |
} |
This file contains 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
headerView { | |
id("header view") | |
cityName(data.name) | |
description(data.description) | |
... | |
} |
This file contains 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
inline fun EpoxyController.carousel(modelInitializer: CarouselModelBuilder.() -> Unit) { | |
CarouselModel_().apply { | |
modelInitializer() | |
}.addTo(this) | |
} | |
inline fun <T> CarouselModelBuilder.withModelsFrom( | |
items: List<T>, | |
modelBuilder: (T) -> EpoxyModel<*> | |
) { |
This file contains 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
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 |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout ...> | |
<data> | |
<variable | |
name="cityName" | |
type="String" /> | |
<variable | |
name="description" | |
type="String" /> | |
</data> |
NewerOlder