3.7.8 • Published 8 months ago

rax-scrollview v3.7.8

Weekly downloads
169
License
BSD-3-Clause
Repository
github
Last release
8 months ago

rax-scrollview

npm

支持

Web / Weex / 阿里小程序 / 微信小程序 / 字节跳动小程序

描述

ScrollView 是一个包装了滚动操作的组件。一般情况下需要一个确定的高度来保证 ScrollView 的正常展现。

安装

$ npm install rax-scrollview --save

属性

属性类型默认值必填描述支持
scrollEventThrottlenumber50false这个属性控制在滚动过程中,scroll 事件被调用的频率,用于滚动的节流
horizontalboolean-false设置为横向滚动
scrollTopnumber0false竖向滚动距离,优先级高于scrollTo方法(注:运行时小程序无法生效,请使用 scrollTo 方案)
scrollLeftnumber0false横向滚动距离,优先级高于scrollTo方法(注:运行时小程序无法生效,请使用 scrollTo 方案)
showsHorizontalScrollIndicatorbooleantruefalse是否允许出现水平滚动条
showsVerticalScrollIndicatorbooleantruefalse是否允许出现垂直滚动条
onEndReachedThresholdnumber500false设置加载更多的偏移
onEndReachedfunction-false滚动区域还剩onEndReachedThreshold的长度时触发
onScrollfunction-false滚动时触发的事件,返回当前滚动的水平垂直距离
onTouchStartfunction-falsetouchStart 触发的事件,返回触摸点数据(touches、changedTouches)
onTouchMovefunction-falsetouchMove 触发的事件,返回触摸点数据(touches、changedTouches)
onTouchEndfunction-falsetouchEnd 触发的事件,返回触摸点数据(touches、changedTouches)
onTouchCancelfunction-falsetouchCancel 触发的事件,返回触摸点数据(touches、changedTouches)
disableScrollboolean-false是否禁止滚动, rax-scrollview@3.3.3 及以上版本支持

方法

scrollTo({x: number,y: number, animated?: boolean, duration?: number})

参数

参数为 object,包含以下属性

属性类型默认值必填描述支持
xnumber- 横向的偏移量
ynumber-纵向的偏移量
animatedbooleantrue在设置滚动条位置时使用动画过渡
durationnumber400animated 设置为 true 时,可以设置 duration 来控制动画的执行时间,单位 ms

scrollIntoView({id: string, animated?: boolean, duration?: number, offsetX?: number, offsetY?: number})

参数

参数为 object,包含以下属性

属性类型默认值必填描述支持
idstring-需要滚动到的元素 id
animatedbooleantrue在设置滚动条位置时使用动画过渡
durationnumber400animated 设置为 true 时,可以设置 duration 来控制动画的执行时间,单位 ms
offsetXnumber-滚动的额外 X 偏移
offsetYnumber-滚动的额外 Y 偏移

示例

import { createElement, Component, render, createRef } from 'rax';

import DriverUniversal from 'driver-universal';
import View from 'rax-view';
import Text from 'rax-text';
import ScrollView from 'rax-scrollview';

function Thumb() {
  return (
    <View style={styles.button}>
      <View style={styles.box} />
    </View>
  );
}

const THUMBS = new Array(20).fill(1);
const createThumbRow = (val, index) => <Thumb key={index} />;

class App extends Component {
  state = {
    horizontalScrollViewEventLog: false,
    scrollViewEventLog: false,
  };
  constructor(props) {
    super(props);
    this.horizontalScrollView = createRef();
  }

  render() {
    return (
      <View style={styles.root}>
        <View style={styles.container}>
          <ScrollView
            ref={this.horizontalScrollView}
            style={{
              height: '100rpx',
            }}
            horizontal={true}
            onEndReached={() =>
              this.setState({ horizontalScrollViewEventLog: true })
            }
          >
            {THUMBS.map(createThumbRow)}
          </ScrollView>

          <View
            style={styles.button}
            onClick={() => {
              this.horizontalScrollView.current.scrollTo({ x: 0 });
            }}
          >
            <Text>Scroll to start</Text>
          </View>

          <View style={styles.eventLogBox}>
            <Text>
              {this.state.horizontalScrollViewEventLog ? 'onEndReached' : ''}
            </Text>
          </View>
        </View>

        <View style={{ ...styles.container, height: '500rpx' }}>
          <ScrollView
            ref={scrollView => {
              this.scrollView = scrollView;
            }}
            onEndReached={() => this.setState({ scrollViewEventLog: true })}
          >
            <View>
              <View style={styles.sticky}>
                <Text>Cannot sticky</Text>
              </View>
            </View>

            <View style={styles.sticky}>
              <Text>Sticky view must in ScrollView root</Text>
            </View>

            {THUMBS.map(createThumbRow)}
          </ScrollView>

          <View
            style={styles.button}
            onClick={() => {
              this.scrollView.scrollTo({ y: 0 });
            }}
          >
            <Text>Scroll to top</Text>
          </View>

          <View style={styles.eventLogBox}>
            <Text>{this.state.scrollViewEventLog ? 'onEndReached' : ''}</Text>
          </View>
        </View>
      </View>
    );
  }
}

const styles = {
  root: {
    width: '750rpx',
    paddingTop: '20rpx',
  },
  sticky: {
    position: 'sticky',
    width: '750',
    backgroundColor: '#cccccc',
  },
  container: {
    padding: '20rpx',
    borderStyle: 'solid',
    borderColor: '#dddddd',
    borderWidth: '1rpx',
    marginLeft: '20rpx',
    marginRight: '20rpx',
    marginBottom: '10rpx',
  },
  button: {
    margin: '7rpx',
    padding: '5rpx',
    alignItems: 'center',
    backgroundColor: '#eaeaea',
    borderRadius: '3rpx',
  },
  box: {
    width: '64rpx',
    height: '64rpx',
  },
  eventLogBox: {
    padding: '10rpx',
    margin: '10rpx;,
    height: '80rpx',
    borderWidth: '1rpx',
    borderColor: '#f0f0f0',
    backgroundColor: '#f9f9f9',
  },
};

render(<App />, document.body, { driver: DriverUniversal });
@everything-registry/sub-chunk-2533@rax-ui/filter-list-select@rax-ui/filter-multi-select@rax-ui/table@rax-ui/tabs@rax-ui/select@alifd/meet@aligov/block-certificate-card-swiper@aligov/block-customzone-banner@aligov/block-service-subject@aligov/block-service-zone@aligov/gov-h5-card-rax-sdk@aligov/gov-h5-guide-rax-sdk@aligov/gov-h5-rate-rax-sdk@aligov/miniapp-city-list@aligov/miniapp-portal-render@aligov/miniapp-user-profile@aligov/miniapp-user-setting@aliretail/mallmod-miniapp-rax-bargain_activity_entry@aliretail/mallmod-miniapp-rax-reward_activity_entry@aliretail/officialmod-miniapp-rax-add_on_sku_list@aliretail/officialmod-miniapp-rax-mall_add_on_sku_list@aliretail/officialmod-miniapp-rax-mall_bargain_activity_entry@aliretail/officialmod-miniapp-rax-mall_category_list@aliretail/officialmod-miniapp-rax-mall_reward_activity_entry@aliretail/deploy@aliretail/ha-mallmod-miniapp-rax-category_list_page@aliretail/base-member-sdk@aliretail/basemember@aliretail/officialmod-miniapp-rax-mall_search_result@aliretail/point-member-sdk@aliretail/point-member-sdk-dev@aliretail/rax-materials-componentsbiz-components-test-1cn-meettboc-scrollviewtemplate-taobaotemplate-chat@sfc-components/scroll-view@rax-ui/action-sheet@rax-ui/calendar@rax-materials/scaffolds-app-shop@rax-materials/user-detail-form@halofe/astore-mods-miniapp-rax-detail@halofe/astore-mods-miniapp-rax-item-evaluation@halofe/astore-mods-miniapp-rax-trade-order@halofe/astore-mods-miniapp-rax-trade-refund@halofe/rax-item-evaluation@halofe/rax-trade-order@halofe/rax-trade-refund@halofe/rax-detailrax-tbms-chat-pluginrax-theme-buyrax-theme-chatrax-theme-taobaorax-tabbarrax-tabheaderrax-tablerax-recyclerviewrax-card-scrollerrax-componentsrax-animatedrax-calendarrax-page-layoutrax-waterfallrax-xsliderfeihe_shop
3.7.8

8 months ago

3.7.7

2 years ago

3.7.6

2 years ago

3.7.5

2 years ago

3.7.5-beta.1

2 years ago

3.7.4

2 years ago

3.7.3

2 years ago

3.7.2

2 years ago

3.7.1-4

2 years ago

3.7.1-5

2 years ago

3.7.1-3

2 years ago

3.7.1-6

2 years ago

3.7.1

2 years ago

3.7.1-2

2 years ago

3.7.1-1

3 years ago

3.7.1-0

3 years ago

3.7.0

3 years ago

3.6.1

3 years ago

3.6.0

3 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.5.0

3 years ago

3.5.0-0

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.4.1-0

3 years ago

3.4.0

3 years ago

3.3.8-0

3 years ago

3.3.7

3 years ago

3.3.6

3 years ago

3.3.5

3 years ago

3.3.4

4 years ago

3.3.4-0

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.6

4 years ago

3.2.5

4 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.2.3-0

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.1-0

4 years ago

3.0.0

4 years ago

3.0.0-0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.6

4 years ago

1.1.6-beta.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.4-1

4 years ago

1.1.4-0

4 years ago

1.1.3

4 years ago

1.1.3-0

4 years ago

1.1.2

4 years ago

1.1.1-beta.7

4 years ago

1.1.1-beta.6

4 years ago

1.1.1

4 years ago

1.1.1-beta.5

5 years ago

1.1.1-beta.4

5 years ago

1.1.1-beta.3

5 years ago

1.1.1-beta.2

5 years ago

1.1.1-beta.1

5 years ago

1.1.0-8

5 years ago

1.1.0-7

5 years ago

1.1.0-6

5 years ago

1.1.0-5

5 years ago

1.1.0

5 years ago

1.1.0-4

5 years ago

1.1.0-3

5 years ago

1.1.0-2

5 years ago

1.1.0-1

5 years ago

1.1.0-0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.8

5 years ago

1.0.0-beta.7

5 years ago

1.0.0-beta.6

5 years ago

1.0.0-beta.5

5 years ago

1.0.0-beta.3

5 years ago

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

1.0.0-beta.0

5 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.21-beta

7 years ago

0.4.20

7 years ago

0.4.19

7 years ago

0.4.18

7 years ago

0.4.17

7 years ago

0.4.16

7 years ago

0.4.15

7 years ago

0.5.0-beta

7 years ago

0.4.14

7 years ago

0.4.13

7 years ago

0.4.12

7 years ago

0.4.11

7 years ago

0.4.10

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.13

7 years ago

0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago