代码拉取完成,页面将自动刷新
在很多应用中,swiper组件每一个page的高度是不一致的,所以需要swiper组件下方页面的高度跟着一起变化。
向左滑动swiper组件,上方swiper组件高度变高,下方页面随着swiper的变化而平滑的变化。
实现方案如下:
Swiper() {
Column() {
Stack() {
Text('功能栏')
.textAlign(TextAlign.Center)
.margin({ top: $r('app.integer.swipersmoothvariation_margin_small'), left: $r('app.integer.swipersmoothvariation_default_padding') })
// swiper第一个page
this.GridBuilderFunction(this.dataPageOne, Const.GRID_DOUBLE_HEIGHT, Const.GRID_TEMPLATE)
}
.alignContent(Alignment.TopStart)
}
// swiper第二个page
this.GridBuilderFunction(this.dataPageTwo, Const.GRID_DOUBLE_HEIGHT, Const.GRID_TEMPLATE)
// swiper第三个page
this.GridBuilderFunction(this.dataPageThree, Const.GRID_DOUBLE_HEIGHT, Const.GRID_TEMPLATE)
// swiper第四个page
this.GridBuilderFunction(this.dataPageFour, Const.GRID_DOUBLE_HEIGHT, Const.GRID_TEMPLATE)
}
Swiper{
...
}
.onGestureSwipe((index: number, extraInfo: SwiperAnimationEvent) => {
animateTo({
duration: Const.DURATION,
curve: Curve.EaseOut,
playMode: PlayMode.Normal,
onFinish: () => {
logger.info('play end');
}
}, () => { // 通过左右滑动的距离来计算对应的上下位置的变化
if (index === 0 && extraInfo.currentOffset < 0) {
this.swiperDistance = extraInfo.currentOffset / Const.SCROLL_WIDTH * Const.SMALL_FONT_SIZE;
} else if (index === 1 && extraInfo.currentOffset > 0) {
this.swiperDistance = extraInfo.currentOffset / Const.SCROLL_WIDTH * Const.SMALL_FONT_SIZE - Const.SMALL_FONT_SIZE;
} else if (index === 2 && extraInfo.currentOffset < 0) {
this.swiperDistance = extraInfo.currentOffset / Const.SCROLL_WIDTH * Const.GRID_SINGLE_HEIGHT - Const.SMALL_FONT_SIZE;
} else if (index === 3 && extraInfo.currentOffset > 0) {
this.swiperDistance = extraInfo.currentOffset / Const.SCROLL_WIDTH * Const.GRID_SINGLE_HEIGHT - Const.SMALL_FONT_SIZE - Const.GRID_SINGLE_HEIGHT;
}
})
})
Swiper{
...
}
.onAnimationStart((_: number, targetIndex: number) => {
animateTo({
duration: Const.DURATION,
curve: Curve.EaseOut,
playMode: PlayMode.Normal,
onFinish: () => {
logger.info('play end');
}
}, () => {
if (targetIndex === 0) {
this.swiperDistance = 0;
} else if (targetIndex === 1 || targetIndex === 2) {
this.swiperDistance = -Const.SMALL_FONT_SIZE;
} else {
this.swiperDistance = -Const.SMALL_FONT_SIZE - Const.GRID_SINGLE_HEIGHT;
}
})
})
swipersmoothvariation // har包
|---common
| |---CommonConstants.ets // 提供自定义数据
|---pages
| |---MainPage.ets // 滑动变化效果实现页面
不涉及。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。