ADD: onScrollToIndexFailed for Wallet Carousel

This commit is contained in:
Marcos Rodriguez Vélez 2021-07-24 11:01:11 -04:00
parent 0a7d027544
commit 1204032b20
2 changed files with 15 additions and 2 deletions

View File

@ -353,6 +353,17 @@ const WalletsCarousel = forwardRef((props, ref) => {
},
}));
const onScrollToIndexFailed = error => {
console.log('onScrollToIndexFailed');
console.log(error);
flatListRef.current.scrollToOffset({ offset: error.averageItemLength * error.index, animated: true });
setTimeout(() => {
if (props.data.length !== 0 && flatListRef.current !== null) {
flatListRef.scrollToIndex({ index: error.index, animated: true });
}
}, 100);
};
const { width } = useWindowDimensions();
const sliderHeight = 190;
const itemWidth = width * 0.82 > 375 ? 375 : width * 0.82;
@ -360,7 +371,7 @@ const WalletsCarousel = forwardRef((props, ref) => {
<FlatList
ref={flatListRef}
renderItem={renderItem}
extraData={renderItem}
extraData={props.data}
keyExtractor={(_, index) => index.toString()}
showsVerticalScrollIndicator={false}
pagingEnabled
@ -373,6 +384,7 @@ const WalletsCarousel = forwardRef((props, ref) => {
initialNumToRender={10}
ListHeaderComponent={ListHeaderComponent}
style={props.horizontal ? { height: sliderHeight + 9 } : {}}
onScrollToIndexFailed={onScrollToIndexFailed}
{...props}
/>
);
@ -383,6 +395,7 @@ WalletsCarousel.propTypes = {
selectedWallet: PropTypes.string,
onPress: PropTypes.func.isRequired,
handleLongPress: PropTypes.func.isRequired,
data: PropTypes.array,
};
export default WalletsCarousel;

View File

@ -5,7 +5,7 @@ import App from './App';
import { BlueStorageProvider } from './blue_modules/storage-context';
import { enableScreens } from 'react-native-screens';
const A = require('./blue_modules/analytics');
enableScreens(false)
enableScreens(false);
if (!Error.captureStackTrace) {
// captureStackTrace is only available when debugging
Error.captureStackTrace = () => {};