<waterfall>
是weex
中 瀑布流布局組件欠啤。
其中熄阻,子控件<header>
的sticky
屬性默認(rèn)為 上下都是懸浮的膘掰,可參考我修改后的waterfall demo跪另,上下滑動(dòng)就會(huì)發(fā)現(xiàn)這一表現(xiàn)拧抖。
但項(xiàng)目中,一般我們都是只在頁面頂部進(jìn)行懸浮免绿,而不是底部唧席,因此需要修改該表現(xiàn)。經(jīng)過前端一系列的操作后嘲驾,最終還是決定在 native的 weexSDK
中直接修改源碼效果最佳淌哟,代碼也更清晰。
查看源碼后(版本為0.18.0)辽故,發(fā)現(xiàn)布局信息在:WXMultiColumnLayout.m
中徒仓,關(guān)鍵函數(shù)為:
- (void)_adjustStickyForHeaderAttributes:(WXMultiColumnLayoutHeaderAttributes *)header
next:(WXMultiColumnLayoutHeaderAttributes *)nextHeader
{
CGRect bounds = self.collectionView.bounds;
CGFloat originY = header.frame.origin.y;
CGFloat maxY = nextHeader ? (nextHeader.frame.origin.y - header.frame.size.height) : (CGRectGetMaxY(bounds) - header.frame.size.height);
CGFloat currentY = CGRectGetMaxY(bounds) - bounds.size.height + self.collectionView.contentInset.top;
CGFloat resultY = MIN(MAX(currentY, originY), maxY);
CGPoint origin = header.frame.origin;
origin.y = resultY;
header.frame = (CGRect){origin, header.frame.size};
header.hidden = NO;
}
在這個(gè)函數(shù)中,weex
會(huì)根據(jù)當(dāng)前header
和下一個(gè)header
的位置誊垢,來設(shè)置不同的位移掉弛,那么在底部懸浮的關(guān)鍵代碼就在于
CGFloat resultY = MIN(MAX(currentY, originY), maxY);
這里會(huì)限制header
的Y方向位移症见。
因此,只需要修改 maxY 即可殃饿。
CGFloat maxY = nextHeader ? (nextHeader.frame.origin.y - header.frame.size.height) : (CGRectGetMaxY(bounds) - header.frame.size.height);
改為:
CGFloat maxY = CGFLOAT_MAX;
Done.