be-components 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/BetMatch/api/index.js +11 -0
- package/lib/commonjs/BetMatch/api/index.js.map +1 -1
- package/lib/commonjs/BetMatch/components/BetMatchCard.js +60 -42
- package/lib/commonjs/BetMatch/components/BetMatchCard.js.map +1 -1
- package/lib/commonjs/BetMatch/index.js +134 -50
- package/lib/commonjs/BetMatch/index.js.map +1 -1
- package/lib/commonjs/Components/AutoScrollFlatList.js +50 -7
- package/lib/commonjs/Components/AutoScrollFlatList.js.map +1 -1
- package/lib/commonjs/Components/Icons.js +2 -0
- package/lib/commonjs/Components/Icons.js.map +1 -1
- package/lib/commonjs/Components/PremiumIcons.js +366 -0
- package/lib/commonjs/Components/PremiumIcons.js.map +1 -0
- package/lib/commonjs/Components/index.js +7 -0
- package/lib/commonjs/Components/index.js.map +1 -1
- package/lib/commonjs/FlashMarket/index.js +27 -0
- package/lib/commonjs/FlashMarket/index.js.map +1 -1
- package/lib/commonjs/Premium/components/ALaCartePremium.js +289 -0
- package/lib/commonjs/Premium/components/ALaCartePremium.js.map +1 -0
- package/lib/commonjs/Premium/index.js +12 -0
- package/lib/commonjs/Premium/index.js.map +1 -0
- package/lib/commonjs/SocialComponents/api/index.js +12 -0
- package/lib/commonjs/SocialComponents/api/index.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/BetMatch/api/index.js +11 -0
- package/lib/module/BetMatch/api/index.js.map +1 -1
- package/lib/module/BetMatch/components/BetMatchCard.js +61 -43
- package/lib/module/BetMatch/components/BetMatchCard.js.map +1 -1
- package/lib/module/BetMatch/index.js +135 -51
- package/lib/module/BetMatch/index.js.map +1 -1
- package/lib/module/Components/AutoScrollFlatList.js +51 -8
- package/lib/module/Components/AutoScrollFlatList.js.map +1 -1
- package/lib/module/Components/Icons.js +3 -0
- package/lib/module/Components/Icons.js.map +1 -1
- package/lib/module/Components/PremiumIcons.js +359 -0
- package/lib/module/Components/PremiumIcons.js.map +1 -0
- package/lib/module/Components/index.js +2 -1
- package/lib/module/Components/index.js.map +1 -1
- package/lib/module/FlashMarket/index.js +27 -0
- package/lib/module/FlashMarket/index.js.map +1 -1
- package/lib/module/Premium/components/ALaCartePremium.js +280 -0
- package/lib/module/Premium/components/ALaCartePremium.js.map +1 -0
- package/lib/module/Premium/index.js +5 -0
- package/lib/module/Premium/index.js.map +1 -0
- package/lib/module/SocialComponents/api/index.js +12 -0
- package/lib/module/SocialComponents/api/index.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/BetMatch/api/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/BetMatch/api/index.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/BetMatch/components/BetMatchCard.d.ts +7 -2
- package/lib/typescript/lib/commonjs/BetMatch/components/BetMatchCard.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/BetMatch/index.d.ts +7 -1
- package/lib/typescript/lib/commonjs/BetMatch/index.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/Components/AutoScrollFlatList.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/Components/PremiumIcons.d.ts +85 -0
- package/lib/typescript/lib/commonjs/Components/PremiumIcons.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/Components/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/FlashMarket/index.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/Premium/components/ALaCartePremium.d.ts +9 -0
- package/lib/typescript/lib/commonjs/Premium/components/ALaCartePremium.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/Premium/index.d.ts +6 -0
- package/lib/typescript/lib/commonjs/Premium/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/SocialComponents/api/index.d.ts +6 -6
- package/lib/typescript/lib/commonjs/SocialComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/BetMatch/api/index.d.ts +1 -0
- package/lib/typescript/lib/module/BetMatch/api/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/BetMatch/components/BetMatchCard.d.ts +7 -2
- package/lib/typescript/lib/module/BetMatch/components/BetMatchCard.d.ts.map +1 -1
- package/lib/typescript/lib/module/BetMatch/index.d.ts +7 -1
- package/lib/typescript/lib/module/BetMatch/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/Components/AutoScrollFlatList.d.ts.map +1 -1
- package/lib/typescript/lib/module/Components/PremiumIcons.d.ts +86 -0
- package/lib/typescript/lib/module/Components/PremiumIcons.d.ts.map +1 -0
- package/lib/typescript/lib/module/Components/index.d.ts +2 -1
- package/lib/typescript/lib/module/Components/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/FlashMarket/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/Premium/components/ALaCartePremium.d.ts +14 -0
- package/lib/typescript/lib/module/Premium/components/ALaCartePremium.d.ts.map +1 -0
- package/lib/typescript/lib/module/Premium/index.d.ts +6 -0
- package/lib/typescript/lib/module/Premium/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/SocialComponents/api/index.d.ts +6 -6
- package/lib/typescript/lib/module/SocialComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/index.d.ts +2 -1
- package/lib/typescript/lib/module/index.d.ts.map +1 -1
- package/lib/typescript/src/BetMatch/api/index.d.ts +2 -1
- package/lib/typescript/src/BetMatch/api/index.d.ts.map +1 -1
- package/lib/typescript/src/BetMatch/components/BetMatchCard.d.ts +9 -3
- package/lib/typescript/src/BetMatch/components/BetMatchCard.d.ts.map +1 -1
- package/lib/typescript/src/BetMatch/index.d.ts +15 -1
- package/lib/typescript/src/BetMatch/index.d.ts.map +1 -1
- package/lib/typescript/src/Components/AutoScrollFlatList.d.ts.map +1 -1
- package/lib/typescript/src/Components/Icons.d.ts.map +1 -1
- package/lib/typescript/src/Components/PremiumIcons.d.ts +27 -0
- package/lib/typescript/src/Components/PremiumIcons.d.ts.map +1 -0
- package/lib/typescript/src/Components/index.d.ts +2 -1
- package/lib/typescript/src/Components/index.d.ts.map +1 -1
- package/lib/typescript/src/FlashMarket/index.d.ts.map +1 -1
- package/lib/typescript/src/Premium/components/ALaCartePremium.d.ts +12 -0
- package/lib/typescript/src/Premium/components/ALaCartePremium.d.ts.map +1 -0
- package/lib/typescript/src/Premium/index.d.ts +10 -0
- package/lib/typescript/src/Premium/index.d.ts.map +1 -0
- package/lib/typescript/src/SocialComponents/api/index.d.ts +1 -1
- package/lib/typescript/src/SocialComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/BetMatch/api/index.ts +11 -2
- package/src/BetMatch/components/BetMatchCard.tsx +44 -35
- package/src/BetMatch/index.tsx +105 -38
- package/src/Components/AutoScrollFlatList.tsx +50 -15
- package/src/Components/Icons.tsx +5 -0
- package/src/Components/PremiumIcons.tsx +201 -0
- package/src/Components/index.tsx +2 -0
- package/src/FlashMarket/index.tsx +15 -0
- package/src/Premium/components/ALaCartePremium.tsx +121 -0
- package/src/Premium/index.tsx +5 -0
- package/src/SocialComponents/api/index.ts +9 -1
- package/src/index.tsx +2 -1
- package/src/types.d.ts +36 -0
package/src/BetMatch/index.tsx
CHANGED
|
@@ -3,23 +3,33 @@ import { Text, View } from "../Components/Themed";
|
|
|
3
3
|
import { MyOrdersHelpers } from '../MarketComponents/components/MyOrderList/api';
|
|
4
4
|
import type { AthleteProps, EventProps, LeagueProps, MarketProps, MatchProps, OrderProps, PlayerFilterProps, PublicPlayerProps, TeamProps, TournamentProps } from '../types';
|
|
5
5
|
import { BetMatchApi } from './api';
|
|
6
|
-
import { ActivityIndicator, FlatList } from 'react-native';
|
|
6
|
+
import { ActivityIndicator, FlatList, Modal, StyleSheet, TouchableWithoutFeedback } from 'react-native';
|
|
7
7
|
import BetMatchCardSmall from './components/BetMatchCardSmall';
|
|
8
8
|
import { SocialOrderHelpers } from '../SocialComponents/api';
|
|
9
9
|
import moment from 'moment-mini';
|
|
10
10
|
import { useColors } from '../constants/useColors';
|
|
11
11
|
import BetMatchCard from './components/BetMatchCard';
|
|
12
|
+
import Pagination from '../Components/Pagination';
|
|
12
13
|
|
|
13
14
|
type BetMatchProps = {
|
|
14
15
|
player_filter_id:string,
|
|
15
16
|
style?:any,
|
|
16
|
-
|
|
17
|
+
mode:'desktop'|'mobile',
|
|
18
|
+
player_id:string,
|
|
19
|
+
insets?:{ top:number, bottom:number, right?:number, left?:number }
|
|
20
|
+
show_grades?:boolean,
|
|
21
|
+
show_external_prices?:boolean,
|
|
22
|
+
onViewPremium?:() => void,
|
|
23
|
+
onViewPlayer:(player:PublicPlayerProps) => void,
|
|
24
|
+
onSelectGrade:(order:OrderProps) => void,
|
|
25
|
+
onOrder:(order:OrderProps) => void
|
|
17
26
|
}
|
|
18
27
|
const sections = ['filter','orders', 'bet']
|
|
19
|
-
const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
28
|
+
const BetMatch = ({ player_filter_id, mode, insets, onViewPlayer, onSelectGrade, onOrder, onViewPremium }:BetMatchProps) => {
|
|
20
29
|
const Colors = useColors();
|
|
30
|
+
|
|
21
31
|
const [ module_size, setModuleSize ] = useState({ width:0, height:0 });
|
|
22
|
-
const [
|
|
32
|
+
const [ viewing_order_index, setViewingOrderIndex ] = useState<number>(-1);
|
|
23
33
|
const [ static_data, setStaticData ] = useState<{
|
|
24
34
|
static_loading:boolean,
|
|
25
35
|
leagues:LeagueProps[],
|
|
@@ -31,12 +41,13 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
31
41
|
const [ filter_data, setFilterData ] = useState<{
|
|
32
42
|
loading:boolean,
|
|
33
43
|
player_filter?:PlayerFilterProps,
|
|
44
|
+
action_loading:boolean,
|
|
34
45
|
orders:OrderProps[],
|
|
35
46
|
}>({
|
|
36
|
-
loading:false, orders:[]
|
|
47
|
+
loading:false, orders:[], action_loading:false
|
|
37
48
|
});
|
|
38
|
-
const { loading, player_filter, orders } = filter_data;
|
|
39
|
-
const viewing_order = orders
|
|
49
|
+
const { loading, player_filter, orders, action_loading } = filter_data;
|
|
50
|
+
const viewing_order = orders[viewing_order_index];
|
|
40
51
|
const [ contest_data, setContestData ] = useState<{
|
|
41
52
|
contest_loading:boolean,
|
|
42
53
|
players:PublicPlayerProps[],
|
|
@@ -48,7 +59,7 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
48
59
|
}>({
|
|
49
60
|
contest_loading: false, players: [], events: [], tournaments: [], matches: [], teams:[], athletes: []
|
|
50
61
|
});
|
|
51
|
-
const { players, events, tournaments, matches, teams, athletes } = contest_data;
|
|
62
|
+
const { contest_loading, players, events, tournaments, matches, teams, athletes } = contest_data;
|
|
52
63
|
|
|
53
64
|
useEffect(() => {
|
|
54
65
|
BetMatchApi.setEnvironment()
|
|
@@ -93,6 +104,7 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
93
104
|
const tms = await BetMatchApi.getTeamsByIds(team_ids);
|
|
94
105
|
setContestData({
|
|
95
106
|
...contest_data,
|
|
107
|
+
contest_loading: false,
|
|
96
108
|
players: plyers,
|
|
97
109
|
events: evs,
|
|
98
110
|
tournaments: tourns,
|
|
@@ -102,6 +114,25 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
102
114
|
})
|
|
103
115
|
}
|
|
104
116
|
|
|
117
|
+
const handleReject = async(order:OrderProps) => {
|
|
118
|
+
setFilterData({ ...filter_data, action_loading: true });
|
|
119
|
+
await BetMatchApi.saveBetMatchResponse({
|
|
120
|
+
order_id: order.order_id,
|
|
121
|
+
response:'decline',
|
|
122
|
+
be_type: 'market',
|
|
123
|
+
bet_match_response_id:'',
|
|
124
|
+
player_id: '',
|
|
125
|
+
create_datetime:'', last_update_datetime:''
|
|
126
|
+
})
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
setFilterData({
|
|
129
|
+
...filter_data,
|
|
130
|
+
orders: orders.filter(o => o.order_id != order.order_id)
|
|
131
|
+
})
|
|
132
|
+
}, 250);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
105
136
|
const renderOrders = (data:{ item:OrderProps, index:number }) => {
|
|
106
137
|
const player = players.find(p => p.player_id == data.item.player_id);
|
|
107
138
|
if(!player){ return <></> }
|
|
@@ -115,8 +146,9 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
115
146
|
contest_title={title}
|
|
116
147
|
time_detail={time}
|
|
117
148
|
league={league}
|
|
149
|
+
|
|
118
150
|
order={data.item}
|
|
119
|
-
onOrder={(
|
|
151
|
+
onOrder={() => setViewingOrderIndex(data.index)}
|
|
120
152
|
/>
|
|
121
153
|
</View>
|
|
122
154
|
)
|
|
@@ -126,7 +158,6 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
126
158
|
switch(data.item){
|
|
127
159
|
case 'filter':
|
|
128
160
|
if(!player_filter){ return <></> }
|
|
129
|
-
if(viewing_order){ return <></> }
|
|
130
161
|
return (
|
|
131
162
|
<View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10 }}>
|
|
132
163
|
<View transparent style={{ flex:1, marginRight:10 }}>
|
|
@@ -140,53 +171,89 @@ const BetMatch = ({ player_filter_id }:BetMatchProps) => {
|
|
|
140
171
|
</View>
|
|
141
172
|
)
|
|
142
173
|
case 'orders':
|
|
143
|
-
if(viewing_order){ return <></> }
|
|
144
174
|
return (
|
|
145
|
-
<View
|
|
146
|
-
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
<View style={{ flex:1, padding:20 }}>
|
|
158
|
-
<BetMatchCard
|
|
159
|
-
player={player}
|
|
160
|
-
height={module_size.height - 60}
|
|
161
|
-
order={viewing_order}
|
|
162
|
-
team={team}
|
|
163
|
-
athlete={athlete}
|
|
164
|
-
league={league}
|
|
165
|
-
time_detail={time}
|
|
166
|
-
contest_title={title}
|
|
167
|
-
onOrder={(order) => console.log(order)}
|
|
168
|
-
/>
|
|
175
|
+
<View>
|
|
176
|
+
{loading || contest_loading ?
|
|
177
|
+
<View transparent style={{ justifyContent:'center', alignItems:'center', padding:50 }}>
|
|
178
|
+
<ActivityIndicator size='large' color={Colors.text.h1} />
|
|
179
|
+
<Text theme='h1' color={Colors.text.h1} style={{ marginTop:10 }}>Running Your Filter...</Text>
|
|
180
|
+
</View>
|
|
181
|
+
:<></>}
|
|
182
|
+
<View style={{ flexDirection:'row', flexWrap:'wrap' }}>
|
|
183
|
+
{orders.map((item, index) => {
|
|
184
|
+
return renderOrders({ item, index })
|
|
185
|
+
})}
|
|
186
|
+
</View>
|
|
169
187
|
</View>
|
|
170
188
|
)
|
|
189
|
+
|
|
171
190
|
default: return <></>
|
|
172
191
|
}
|
|
173
192
|
}
|
|
193
|
+
|
|
194
|
+
const viewing_player = players.find(p => p.player_id == viewing_order?.player_id);
|
|
195
|
+
const { team, athlete, league, title, time } = SocialOrderHelpers.getContestDetails(viewing_order, events, tournaments, matches, athletes, teams, leagues)
|
|
174
196
|
return (
|
|
175
197
|
<View style={{ flex:1 }} onLayout={(ev) => {
|
|
176
198
|
const { width, height } = ev.nativeEvent.layout;
|
|
177
199
|
setModuleSize({ width, height })
|
|
178
200
|
}}>
|
|
179
|
-
{loading ?
|
|
180
|
-
<ActivityIndicator size='large' color={Colors.text.h1} />
|
|
181
|
-
:<></>}
|
|
182
201
|
<FlatList
|
|
183
202
|
data={sections}
|
|
184
203
|
key={'filter_sections'}
|
|
185
204
|
keyExtractor={item => item}
|
|
186
205
|
renderItem={renderSections}
|
|
187
206
|
/>
|
|
207
|
+
<Modal
|
|
208
|
+
style={styles.modalContainer}
|
|
209
|
+
animationType={mode=='desktop' ? 'fade' : 'slide'}
|
|
210
|
+
transparent
|
|
211
|
+
visible={viewing_order ? true : false}
|
|
212
|
+
>
|
|
213
|
+
<TouchableWithoutFeedback style={{ flex:1 }} onPress={() => setViewingOrderIndex(-1)}>
|
|
214
|
+
<View type="blur" style={mode=='desktop' ? styles.desktopContainer : { ...styles.viewContainer }}>
|
|
215
|
+
<TouchableWithoutFeedback>
|
|
216
|
+
<View transparent style={mode=='desktop' ?{ width:500,maxHeight:750, borderRadius:22 }:{ flex:1, maxHeight:module_size.height }}>
|
|
217
|
+
{viewing_order ?
|
|
218
|
+
<View transparent style={{ padding:20 }}>
|
|
219
|
+
<BetMatchCard
|
|
220
|
+
player={viewing_player}
|
|
221
|
+
order={viewing_order}
|
|
222
|
+
team={team}
|
|
223
|
+
athlete={athlete}
|
|
224
|
+
league={league}
|
|
225
|
+
action_loading={action_loading}
|
|
226
|
+
time_detail={time}
|
|
227
|
+
contest_title={title}
|
|
228
|
+
onViewPlayer={onViewPlayer}
|
|
229
|
+
onViewPremium={onViewPremium}
|
|
230
|
+
onSelectGrade={onSelectGrade}
|
|
231
|
+
onOrder={(order) => onOrder(order)}
|
|
232
|
+
onReject={(order) => handleReject(order)}
|
|
233
|
+
/>
|
|
234
|
+
</View>
|
|
235
|
+
:<></>}
|
|
236
|
+
<View style={{ padding:5, paddingBottom: (insets?.bottom ?? 0) + 5 }}>
|
|
237
|
+
<Pagination
|
|
238
|
+
pages={orders.length}
|
|
239
|
+
onNext={() => setViewingOrderIndex(viewing_order_index + 1)}
|
|
240
|
+
onPrevious={() => setViewingOrderIndex(viewing_order_index - 1)}
|
|
241
|
+
offset={viewing_order_index}
|
|
242
|
+
/>
|
|
243
|
+
</View>
|
|
244
|
+
</View>
|
|
245
|
+
</TouchableWithoutFeedback>
|
|
246
|
+
</View>
|
|
247
|
+
</TouchableWithoutFeedback>
|
|
248
|
+
</Modal>
|
|
188
249
|
</View>
|
|
189
250
|
)
|
|
190
251
|
}
|
|
191
252
|
|
|
253
|
+
const styles = StyleSheet.create({
|
|
254
|
+
modalContainer: { flex:1 },
|
|
255
|
+
viewContainer: { flex:1, justifyContent:'flex-end' },
|
|
256
|
+
desktopContainer:{ flex:1, justifyContent:'center', alignItems:'center' }
|
|
257
|
+
})
|
|
258
|
+
|
|
192
259
|
export default BetMatch
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type NativeScrollEvent,
|
|
8
8
|
type NativeSyntheticEvent,
|
|
9
9
|
Platform,
|
|
10
|
+
Dimensions,
|
|
10
11
|
} from 'react-native';
|
|
11
12
|
|
|
12
13
|
type AutoScrollingFlatListProps<T> = {
|
|
@@ -38,7 +39,7 @@ const AutoScrollingFlatList = <T,>({
|
|
|
38
39
|
const scrollStartTime = useRef<number | null>(null);
|
|
39
40
|
|
|
40
41
|
const [ready, setReady] = useState(false);
|
|
41
|
-
const [isPaused, setIsPaused] = useState(false);
|
|
42
|
+
const [isPaused, setIsPaused] = useState(false);
|
|
42
43
|
const [containerSize, setContainerSize] = useState(0);
|
|
43
44
|
|
|
44
45
|
const handleLayout = (e: LayoutChangeEvent) => {
|
|
@@ -53,40 +54,34 @@ const AutoScrollingFlatList = <T,>({
|
|
|
53
54
|
? e.nativeEvent.layout.width
|
|
54
55
|
: e.nativeEvent.layout.height;
|
|
55
56
|
|
|
57
|
+
if(size == 0){ return }
|
|
56
58
|
itemSizes.current[index] = size;
|
|
57
|
-
|
|
58
|
-
const allMeasured =
|
|
59
|
-
itemSizes.current.length === data.length &&
|
|
60
|
-
itemSizes.current.every((v) => typeof v === 'number');
|
|
61
|
-
|
|
59
|
+
const allMeasured = itemSizes.current.length === data.length && itemSizes.current.every((v): v is number => typeof v === 'number');
|
|
62
60
|
if (allMeasured && !ready) {
|
|
63
61
|
totalSize.current = itemSizes.current
|
|
64
62
|
.filter((v): v is number => typeof v === 'number')
|
|
65
63
|
.reduce((acc, val) => acc + val, 0);
|
|
66
64
|
setReady(true);
|
|
67
65
|
}
|
|
66
|
+
|
|
68
67
|
};
|
|
69
68
|
|
|
70
69
|
const handleScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
71
70
|
const currentOffset = horizontal
|
|
72
71
|
? e.nativeEvent.contentOffset.x
|
|
73
72
|
: e.nativeEvent.contentOffset.y;
|
|
74
|
-
|
|
75
73
|
offset.current = currentOffset;
|
|
76
74
|
};
|
|
77
75
|
|
|
78
76
|
useEffect(() => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!ready || (isWeb && isPaused) || speed <= 0 || containerSize === 0) return;
|
|
82
|
-
|
|
77
|
+
if (!ready || isPaused || speed <= 0 || containerSize === 0) return;
|
|
78
|
+
if(totalSize.current == 0){ return }
|
|
83
79
|
const frameInterval = 16;
|
|
84
80
|
const pixelsPerFrame = (speed * frameInterval) / 1000;
|
|
85
81
|
scrollStartTime.current = Date.now();
|
|
86
82
|
|
|
87
83
|
scrollTimer.current = setInterval(() => {
|
|
88
84
|
offset.current += pixelsPerFrame;
|
|
89
|
-
|
|
90
85
|
const maxOffset = totalSize.current - containerSize;
|
|
91
86
|
const now = Date.now();
|
|
92
87
|
const reachedEnd = offset.current >= maxOffset;
|
|
@@ -114,6 +109,13 @@ const AutoScrollingFlatList = <T,>({
|
|
|
114
109
|
};
|
|
115
110
|
}, [ready, speed, isPaused, containerSize, onCompleteScroll, minDuration]);
|
|
116
111
|
|
|
112
|
+
// Kick off scroll once ready
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (ready && !isPaused && speed > 0 && containerSize > 0) {
|
|
115
|
+
listRef.current?.scrollToOffset({ offset: offset.current, animated: false });
|
|
116
|
+
}
|
|
117
|
+
}, [ready, isPaused, speed, containerSize]);
|
|
118
|
+
|
|
117
119
|
// Reset state/refs on resetKey change
|
|
118
120
|
useEffect(() => {
|
|
119
121
|
if (scrollTimer.current) clearInterval(scrollTimer.current);
|
|
@@ -125,6 +127,20 @@ const AutoScrollingFlatList = <T,>({
|
|
|
125
127
|
setIsPaused(false);
|
|
126
128
|
}, [resetKey]);
|
|
127
129
|
|
|
130
|
+
// Ensure auto-scroll works after first mobile touch
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (Platform.OS !== 'web') return;
|
|
133
|
+
|
|
134
|
+
const unlock = () => {
|
|
135
|
+
setIsPaused(false);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
document.addEventListener('touchstart', unlock, { once: true });
|
|
139
|
+
return () => {
|
|
140
|
+
document.removeEventListener('touchstart', unlock);
|
|
141
|
+
};
|
|
142
|
+
}, []);
|
|
143
|
+
|
|
128
144
|
const wrappedRenderItem = ({ item, index }: { item: T; index: number }) => (
|
|
129
145
|
<View onLayout={(e) => updateItemLayout(index, e)} style={{ flexShrink: 0 }}>
|
|
130
146
|
{renderItem({ item, index })}
|
|
@@ -136,19 +152,36 @@ const AutoScrollingFlatList = <T,>({
|
|
|
136
152
|
? {
|
|
137
153
|
onMouseEnter: () => setIsPaused(true),
|
|
138
154
|
onMouseLeave: () => setIsPaused(false),
|
|
139
|
-
onTouchStart: () =>
|
|
155
|
+
onTouchStart: () => {
|
|
156
|
+
if (scrollStartTime.current !== null) {
|
|
157
|
+
setIsPaused(true);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
140
160
|
onTouchEnd: () => setIsPaused(false),
|
|
141
161
|
}
|
|
142
162
|
: {
|
|
143
|
-
onTouchStart: () =>
|
|
163
|
+
onTouchStart: () => {
|
|
164
|
+
if (scrollStartTime.current !== null) {
|
|
165
|
+
setIsPaused(true);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
144
168
|
onTouchEnd: () => setIsPaused(false),
|
|
145
169
|
};
|
|
146
170
|
|
|
171
|
+
const windowSize = Dimensions.get('window');
|
|
172
|
+
|
|
147
173
|
return (
|
|
148
174
|
<View
|
|
149
175
|
{...(wrapperProps as any)}
|
|
150
176
|
onLayout={handleLayout}
|
|
151
|
-
style={[
|
|
177
|
+
style={[
|
|
178
|
+
{
|
|
179
|
+
overflow: 'hidden', flex:1,
|
|
180
|
+
height: horizontal ? '100%' : windowSize.height,
|
|
181
|
+
width: horizontal ? windowSize.width : '100%',
|
|
182
|
+
},
|
|
183
|
+
style,
|
|
184
|
+
]}
|
|
152
185
|
>
|
|
153
186
|
<FlatList
|
|
154
187
|
ref={listRef}
|
|
@@ -157,6 +190,8 @@ const AutoScrollingFlatList = <T,>({
|
|
|
157
190
|
keyExtractor={(_, i) => i.toString()}
|
|
158
191
|
horizontal={horizontal}
|
|
159
192
|
scrollEnabled={true}
|
|
193
|
+
initialNumToRender={data.length}
|
|
194
|
+
//removeClippedSubviews={true}
|
|
160
195
|
onScroll={handleScroll}
|
|
161
196
|
scrollEventThrottle={16}
|
|
162
197
|
showsHorizontalScrollIndicator={false}
|