Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【支付宝小程序】ScrollView 调用 scrollTo 不生效 #175

Closed
MarshallYang opened this issue Jul 8, 2021 · 4 comments
Closed

【支付宝小程序】ScrollView 调用 scrollTo 不生效 #175

MarshallYang opened this issue Jul 8, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@MarshallYang
Copy link

【问题描述】
创建 scrollView 后使用 ref 赋值,外部调用 scrollTo 方法没效果。
控制台输出 ref.current 有值。

控制台表现

【期望效果】
可以滑动到指定位置。

【代码】

import { createElement, useRef } from 'rax';
import View from 'rax-view';
import ScrollView from 'rax-scrollview';


export default function Home() {

  const svRef = useRef(null);

  return (
    <View styel={{ width: '100vw', height: '100vw', position: 'relative' }}>
      <ScrollView
        ref={svRef}
        style={{ width: '100vw', height: '100vh' }}
      >
        {
          new Array(100).fill(0).map((value, index) => {
            return (
              <View key={`line-${index}`} style={{ width: '100%', height: '80rpx' }}>
                line-{index}
              </View>
            );
          })
        }
        <View style={{ position: 'absolute', right: 0, bottom: '100rpx', width: '200rpx', height: '80rpx', color: 'white', backgroundColor: 'blue' }} onClick={() => { svRef.current.scrollTo({ x: 0, y: 0 }); }}>
          To Top
        </View>
      </ScrollView>
    </View>
  );
}

【复现 demo仓库】
https://github.com/MarshallYang/rax-miniapp-scrollto-bug

@ChrisCindy
Copy link
Contributor

目前测试后支付宝小程序确实存在该问题,设置 scroll-top 无法生效,待进一步排查。

@ChrisCindy ChrisCindy added the bug Something isn't working label Jul 9, 2021
@ChrisCindy ChrisCindy self-assigned this Jul 9, 2021
@ChrisCindy
Copy link
Contributor

支付宝小程序在 scrollTop 值前后未发生变化的情况下会出现这种问题。目前可行的处理方式是在 y 值上加一个微小变量,例如

svRef.current.scrollTo({ y: 0 + Math.random() * 0.01 });

@MarshallYang
Copy link
Author

支付宝小程序在 scrollTop 值前后未发生变化的情况下会出现这种问题。目前可行的处理方式是在 y 值上加一个微小变量,例如

svRef.current.scrollTo({ y: 0 + Math.random() * 0.01 });

好的,多谢

@Selinahann
Copy link

支付宝小程序在 scrollTop 值前后未发生变化的情况下会出现这种问题。目前可行的处理方式是在 y 值上加一个微小变量,例如

svRef.current.scrollTo({ y: 0 + Math.random() * 0.01 });

非常感谢,解决了我的问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants