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
|
import React from 'react'
import {View} from 'react-native'
import {ScrollProvider} from '#/lib/ScrollContext'
import {List, type ListMethods} from '#/view/com/util/List'
import {Button, ButtonText} from '#/components/Button'
import * as Toggle from '#/components/forms/Toggle'
import {Text} from '#/components/Typography'
export function ListContained() {
const [animated, setAnimated] = React.useState(false)
const ref = React.useRef<ListMethods>(null)
const data = React.useMemo(() => {
return Array.from({length: 100}, (_, i) => ({
id: i,
text: `Message ${i}`,
}))
}, [])
return (
<>
<View style={{width: '100%', height: 300}}>
<ScrollProvider
onScroll={e => {
'worklet'
console.log(
JSON.stringify({
contentOffset: e.contentOffset,
layoutMeasurement: e.layoutMeasurement,
contentSize: e.contentSize,
}),
)
}}>
<List
data={data}
renderItem={item => {
return (
<View
style={{
padding: 10,
borderBottomWidth: 1,
borderBottomColor: 'rgba(0,0,0,0.1)',
}}>
<Text>{item.item.text}</Text>
</View>
)
}}
keyExtractor={item => item.id.toString()}
disableFullWindowScroll={true}
style={{flex: 1}}
onStartReached={() => {
console.log('Start Reached')
}}
onEndReached={() => {
console.log('End Reached (threshold of 2)')
}}
onEndReachedThreshold={2}
ref={ref}
disableVirtualization={true}
/>
</ScrollProvider>
</View>
<View style={{flexDirection: 'row', gap: 10, alignItems: 'center'}}>
<Toggle.Item
name="a"
label="Click me"
value={animated}
onChange={() => setAnimated(prev => !prev)}>
<Toggle.Checkbox />
<Toggle.LabelText>Animated Scrolling</Toggle.LabelText>
</Toggle.Item>
</View>
<Button
variant="solid"
color="primary"
size="large"
label="Scroll to End"
onPress={() => ref.current?.scrollToOffset({animated, offset: 0})}>
<ButtonText>Scroll to Top</ButtonText>
</Button>
<Button
variant="solid"
color="primary"
size="large"
label="Scroll to End"
onPress={() => ref.current?.scrollToEnd({animated})}>
<ButtonText>Scroll to End</ButtonText>
</Button>
<Button
variant="solid"
color="primary"
size="large"
label="Scroll to Offset 100"
onPress={() => ref.current?.scrollToOffset({animated, offset: 500})}>
<ButtonText>Scroll to Offset 500</ButtonText>
</Button>
</>
)
}
|