-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AbnerMing
committed
May 15, 2024
1 parent
9e49b72
commit b2781e4
Showing
10 changed files
with
265 additions
and
14 deletions.
There are no files selected for viewing
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
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { ListView, RefreshController } from '@abner/refresh' | ||
|
||
/** | ||
* AUTHOR:AbnerMing | ||
* DATE:2024/5/14 | ||
* INTRODUCE:吸顶页面 | ||
* */ | ||
|
||
@Entry | ||
@Component | ||
struct StickyTopPage { | ||
@State controller: RefreshController = new RefreshController() //刷新控制器 | ||
@State arr: number[] = [] | ||
@State listPosition: number = 0 | ||
|
||
@Builder | ||
itemLayout(item: Object, _: number) { | ||
Text("item" + item) | ||
.fontSize(16) | ||
.width("100%") | ||
.height(60) | ||
} | ||
|
||
build() { | ||
Scroll() { | ||
Column() { | ||
Text("头View") | ||
.fontColor(Color.White) | ||
.width("100%") | ||
.height("40%") | ||
.backgroundColor(Color.Red) | ||
.textAlign(TextAlign.Center) | ||
Tabs({ barPosition: BarPosition.Start }) { | ||
TabContent() { | ||
this.testLayout() | ||
}.tabBar("Tab1") | ||
|
||
TabContent() { | ||
this.testLayout() | ||
}.tabBar("Tab2") | ||
} | ||
.vertical(false) | ||
.height("100%") | ||
}.width("100%") | ||
} | ||
.friction(0.6) | ||
.scrollBar(BarState.Off) | ||
.width('100%') | ||
.height('100%') | ||
// 下拉刷新相关 | ||
.onReachStart(() => { | ||
this.listPosition = 0 | ||
}) | ||
.onScrollFrameBegin((offset: number, _: ScrollState) => { | ||
//设置起始位置,保障在顶部时,才能执行下拉刷新 | ||
this.controller.markStartLocation(this.listPosition == 0) | ||
if (this.listPosition == 0 && offset <= 0) { | ||
return { offsetRemain: 0 } | ||
} | ||
this.listPosition = 1 | ||
return { offsetRemain: offset } | ||
}) | ||
|
||
} | ||
|
||
aboutToAppear() { | ||
for (let i = 0; i < 30; i++) { | ||
this.arr.push(i) | ||
} | ||
} | ||
|
||
/* | ||
* Author:AbnerMing | ||
* Describe:测试布局 | ||
*/ | ||
@Builder | ||
testLayout() { | ||
ListView({ | ||
items: this.arr, | ||
itemLayout: this.itemLayout, | ||
controller: this.controller, | ||
onRefresh: () => { | ||
//下拉刷新 | ||
//模拟耗时 | ||
setTimeout(() => { | ||
this.controller.finishRefresh() | ||
}, 1000) | ||
}, | ||
onLoadMore: () => { | ||
// 上拉加载 | ||
//模拟耗时 | ||
setTimeout(() => { | ||
this.controller.finishLoadMore() | ||
}, 1000) | ||
}, | ||
listAttribute: (attr) => { | ||
attr.nestedScroll = { | ||
scrollForward: NestedScrollMode.PARENT_FIRST, | ||
scrollBackward: NestedScrollMode.SELF_FIRST | ||
} | ||
} | ||
}) | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
example/src/main/ets/pages/sticky/StickyTopStaggeredPage.ets
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { RefreshController, StaggeredGridView } from '@abner/refresh' | ||
|
||
/** | ||
* AUTHOR:AbnerMing | ||
* DATE:2024/5/14 | ||
* INTRODUCE:吸顶页面-瀑布流方式 | ||
* */ | ||
|
||
@Entry | ||
@Component | ||
struct StickyTopStaggeredPage { | ||
@State controller: RefreshController = new RefreshController() //刷新控制器 | ||
@State arr: number[] = [] | ||
@State listPosition: number = 0 | ||
private itemHeightArray: number[] = [] | ||
@State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F] | ||
@State minSize: number = 80 | ||
@State maxSize: number = 180 | ||
|
||
// 计算FlowItem宽/高 | ||
getSize() { | ||
let ret = Math.floor(Math.random() * this.maxSize) | ||
return (ret > this.minSize ? ret : this.minSize) | ||
} | ||
|
||
// 设置FlowItem的宽/高数组 | ||
setItemSizeArray() { | ||
for (let i = 0; i < 100; i++) { | ||
this.itemHeightArray.push(this.getSize()) | ||
} | ||
} | ||
|
||
aboutToAppear() { | ||
for (let i = 0; i < 50; i++) { | ||
this.arr.push(i) | ||
} | ||
this.setItemSizeArray() | ||
} | ||
|
||
@Builder | ||
itemLayout(_this: StickyTopStaggeredPage, _: Object, index: number) { | ||
Column() { | ||
Text("测试数据" + index) | ||
}.width("100%") | ||
.height(this.itemHeightArray[index % 100]) | ||
.backgroundColor(this.colors[index % 5]) | ||
} | ||
|
||
build() { | ||
Scroll() { | ||
Column() { | ||
Text("头View") | ||
.fontColor(Color.White) | ||
.width("100%") | ||
.height("40%") | ||
.backgroundColor(Color.Red) | ||
.textAlign(TextAlign.Center) | ||
Tabs({ barPosition: BarPosition.Start }) { | ||
TabContent() { | ||
this.testLayout() | ||
}.tabBar("Tab1") | ||
|
||
TabContent() { | ||
this.testLayout() | ||
}.tabBar("Tab2") | ||
} | ||
.vertical(false) | ||
.height("100%") | ||
}.width("100%") | ||
} | ||
.friction(0.6) | ||
.scrollBar(BarState.Off) | ||
.width('100%') | ||
.height('100%') | ||
// 下拉刷新相关 | ||
.onReachStart(() => { | ||
this.listPosition = 0 | ||
}) | ||
.onScrollFrameBegin((offset: number, _: ScrollState) => { | ||
//设置起始位置,保障在顶部时,才能执行下拉刷新 | ||
this.controller.markStartLocation(this.listPosition == 0) | ||
if (this.listPosition == 0 && offset <= 0) { | ||
return { offsetRemain: 0 } | ||
} | ||
this.listPosition = 1 | ||
return { offsetRemain: offset } | ||
}) | ||
|
||
} | ||
|
||
/* | ||
* Author:AbnerMing | ||
* Describe:测试布局 | ||
*/ | ||
@Builder | ||
testLayout() { | ||
StaggeredGridView({ | ||
items: this.arr, | ||
itemLayout: (item: Object, index: number) => { | ||
this.itemLayout(this, item, index) | ||
}, | ||
controller: this.controller, | ||
onRefresh: () => { | ||
//下拉刷新 | ||
//模拟耗时 | ||
setTimeout(() => { | ||
this.controller.finishRefresh() | ||
}, 1000) | ||
}, | ||
onLoadMore: () => { | ||
// 上拉加载 | ||
//模拟耗时 | ||
setTimeout(() => { | ||
this.controller.finishLoadMore() | ||
}, 1000) | ||
}, | ||
nestedScroll: { | ||
scrollForward: NestedScrollMode.PARENT_FIRST, | ||
scrollBackward: NestedScrollMode.SELF_FIRST | ||
} | ||
}) | ||
} | ||
} |
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