alibaba / rax

🐰 Rax is a progressive framework for building universal application. https://rax.js.org
Other
7.99k stars 627 forks source link

[Question]scrollview scrollTo 在支付宝小程序下不生效,微信小程序没问题 #2242

Closed waylon-gmail closed 2 years ago

waylon-gmail commented 2 years ago

https://rax.js.org/docs/components/scrollview

const scrollViewRef = useRef();

  const handleBackTop = () => {
    // @ts-ignore
    scrollViewRef?.current?.scrollTo({ y: 0 });
    console.log(scrollViewRef);
    console.log(scrollViewRef?.current);
  };

         <ScrollView
            className="scroll-container"
            horizontal={false}
            ref={scrollViewRef}
          >
 ...
waylon-gmail commented 2 years ago

image image

阿里审核人员很认真,这个按钮scrollTo{y: 0}点击没反应拒绝了。他以为那是客服按钮。

cryzzchen commented 2 years ago

@waylon-gmail 在阿里小程序中目前存在一个BUG,返回顶部时,需要给返回值一个细微的偏差值,才能触发滚动,可以改成以下代码:

scrollViewRef?.current?.scrollTo({ y: Math.random() });
waylon-gmail commented 2 years ago

试了好像没有作用。

cryzzchen commented 2 years ago

@waylon-gmail scrollview 有没有设置高度?

waylon-gmail commented 2 years ago

这样设置的。

          <ScrollView
            className="scroll-container"
            ref={scrollViewRef}
          >
            <View className="scroll-cont">
            </View>
          </ScrollView>

  .scroll-container {
    width: 100%;
    height: 100vh;

    .scroll-cont {
      width: 100%;
      padding-bottom: 100px;
    }
  }
cryzzchen commented 2 years ago

@waylon-gmail 请提供一个可复现问题的demo

SoloJiang commented 2 years ago

如果有后续 demo 可以把这个 issue 再打开