提交 d48dc429 编写于 作者: Z zhangrongjie

fix nested scroll

Signed-off-by: Nzhangrongjie <zhangrongjie4@huawei.com>
Change-Id: Iff9e0cf088cf9d4144cff87c4ceaf00d75c93c4f
上级 c9bda94b
...@@ -236,20 +236,21 @@ struct ScrollExample { ...@@ -236,20 +236,21 @@ struct ScrollExample {
struct NestedScroll { struct NestedScroll {
@State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。 @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。
private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
private scroller: Scroller = new Scroller() private scrollerForScroll: Scroller = new Scroller()
private scrollerForList: Scroller = new Scroller()
build() { build() {
Flex() { Flex() {
Scroll(this.scroller) { Scroll(this.scrollerForScroll) {
Column() { Column() {
Text("Scroll Area") Text("Scroll Area")
.width("100%").height("40%").backgroundColor(0X330000FF) .width("100%").height("40%").backgroundColor(0X330000FF)
.fontSize(16).textAlign(TextAlign.Center) .fontSize(16).textAlign(TextAlign.Center)
.onClick(() => { .onClick(() => {
this.scroller.scrollToIndex(5) this.scrollerForList.scrollToIndex(5)
}) })
List({ space: 20, scroller: this.scroller }) { List({ space: 20, scroller: this.scrollerForList }) {
ForEach(this.arr, (item) => { ForEach(this.arr, (item) => {
ListItem() { ListItem() {
Text("ListItem" + item) Text("ListItem" + item)
...@@ -269,7 +270,7 @@ struct NestedScroll { ...@@ -269,7 +270,7 @@ struct NestedScroll {
}) })
.onScrollBegin((dx: number, dy: number) => { .onScrollBegin((dx: number, dy: number) => {
if ((this.listPosition == 0 && dy >= 0) || (this.listPosition == 2 && dy <= 0)) { if ((this.listPosition == 0 && dy >= 0) || (this.listPosition == 2 && dy <= 0)) {
this.scroller.scrollBy(0, -dy) this.scrollerForScroll.scrollBy(0, -dy)
return { dxRemain: dx, dyRemain: 0 } return { dxRemain: dx, dyRemain: 0 }
} }
this.listPosition = 1 this.listPosition = 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册