Blame view

SpringScrollViewNative.js 2.41 KB
75c87a8d   张志伟   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  /*
   * @Author: 石破天惊
   * @email: shanshang130@gmail.com
   * @Date: 2021-07-15 17:11:44
   * @LastEditTime: 2021-07-23 10:40:09
   * @LastEditors: 石破天惊
   * @Description:
   */
  /**
   * Author: Shi(bolan0000@icloud.com)
   * Date: 2019/1/17
   * Copyright (c) 2018, AoTang, Inc.
   *
   * Description: 将安卓导出的事件于iOS打平,消除安卓端因为原生自带的事件的影响
   */
  
  import React from "react";
  import { Animated, Platform, requireNativeComponent, View } from "react-native";
  
  const SpringScrollViewNative = Animated.createAnimatedComponent(
    requireNativeComponent("SpringScrollView")
  );
  
  export class SpringScrollViewNativeAdapter extends React.Component {
    _scrollViewRef;
    render() {
      return (
        <SpringScrollViewNative
          {...this.props}
          pagingEnabled={Platform.select({
            ios: false,
            android: this.props.pagingEnabled,
          })}
          pagingEnabledB={this.props.pagingEnabled}
          decelerationRate={
            this.props.pagingEnabled ? 0.99 : this.props.decelerationRate
          }
          ref={(ref) => (this._scrollViewRef = ref)}
          onTouchStart={(e) =>
            Platform.OS === "ios" &&
            this.props.onTouchBegin &&
            this.props.onTouchBegin(e)
          }
          onCustomTouchBegin={(e) =>
            this.props.onTouchBegin && this.props.onTouchBegin(e)
          }
          onTouchEnd={Platform.select({
            ios: this.props.onTouchEnd,
            android: null,
          })}
          onCustomTouchEnd={(e) =>
            this.props.onTouchEnd && this.props.onTouchEnd(e)
          }
          onCustomMomentumScrollBegin={(e) =>
            this.props.onMomentumScrollBegin &&
            this.props.onMomentumScrollBegin(e)
          }
          onCustomMomentumScrollEnd={(e) =>
            this.props.onMomentumScrollEnd && this.props.onMomentumScrollEnd(e)
          }
          onCustomScrollBeginDrag={(e) =>
            this.props.onScrollBeginDrag && this.props.onScrollBeginDrag(e)
          }
          onCustomScrollEndDrag={(e) =>
            this.props.onScrollEndDrag && this.props.onScrollEndDrag(e)
          }
        />
      );
    }
  
    attachScrollNativeEvent(offset) {
      return Animated.attachNativeEvent(this._scrollViewRef, "onScroll", [
        {
          nativeEvent: {
            contentOffset: offset,
          },
        },
      ]);
    }
  }
  
  export const SpringScrollContentViewNative =
    Platform.OS === "ios"
      ? requireNativeComponent("SpringScrollContentView")
      : View;