未验证 提交 4a08bab1 编写于 作者: O openharmony_ci 提交者: Gitee

!11949 修复Scoll示例代码不能实现嵌套滑动的问题

Merge pull request !11949 from 张荣杰/docs1129
...@@ -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.
先完成此消息的编辑!
想要评论请 注册