forked from alibaba/rax
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollViewDemo.js
More file actions
146 lines (126 loc) · 3.27 KB
/
Copy pathScrollViewDemo.js
File metadata and controls
146 lines (126 loc) · 3.27 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {createElement, Component} from 'rax';
import View from 'rax-view';
import Text from 'rax-text';
import Image from 'rax-image';
import Link from 'rax-link';
import TextInput from 'rax-textinput';
import Button from 'rax-button';
import Switch from 'rax-switch';
import Video from 'rax-video';
import ScrollView from 'rax-scrollview';
import TouchableOpacity from 'rax-touchable';
import RecyclerView from 'rax-recyclerview';
import RefreshControl from 'rax-refreshcontrol';
class Thumb extends Component {
shouldComponentUpdate(nextProps, nextState) {
return false;
}
render() {
return (
<View style={styles.button}>
<View style={styles.box} />
</View>
);
}
}
let THUMBS = [];
for (let i = 0; i < 20; i++) THUMBS.push(i);
let createThumbRow = (val, i) => <Thumb key={i} />;
class ScrollViewDemo extends Component {
state = {
horizontalScrollViewEventLog: false,
scrollViewEventLog: false,
};
render() {
return (
<View>
<View style={styles.container}>
<ScrollView
ref={(scrollView) => {
this.horizontalScrollView = scrollView;
}}
style={{
height: 100,
}}
horizontal={true}
onEndReached={() => this.setState({horizontalScrollViewEventLog: true})}
>
{THUMBS.map(createThumbRow)}
</ScrollView>
<TouchableOpacity
style={styles.button}
onPress={() => this.horizontalScrollView.scrollTo({x: 0})}>
<Text>Scroll to start</Text>
</TouchableOpacity>
<View style={styles.eventLogBox}>
<Text>{this.state.horizontalScrollViewEventLog ? 'onEndReached' : ''}</Text>
</View>
</View>
<View style={styles.container}>
<ScrollView
ref={(scrollView) => {
this.scrollView = scrollView;
}}
style={{
height: 500,
}}
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>
<TouchableOpacity
style={styles.button}
onPress={() => this.scrollView.scrollTo({y: 0})}>
<Text>Scroll to top</Text>
</TouchableOpacity>
<View style={styles.eventLogBox}>
<Text>{this.state.scrollViewEventLog ? 'onEndReached' : ''}</Text>
</View>
</View>
</View>
);
}
}
let styles = {
sticky: {
position: 'sticky',
width: 750,
backgroundColor: '#cccccc'
},
container: {
padding: 20,
borderStyle: 'solid',
borderColor: '#dddddd',
borderWidth: 1,
marginLeft: 20,
marginRight: 20,
marginBottom: 10,
},
button: {
margin: 7,
padding: 5,
alignItems: 'center',
backgroundColor: '#eaeaea',
borderRadius: 3,
},
box: {
width: 64,
height: 64,
},
eventLogBox: {
padding: 10,
margin: 10,
height: 80,
borderWidth: 1,
borderColor: '#f0f0f0',
backgroundColor: '#f9f9f9',
},
};
export default ScrollViewDemo;