Проблема: я реализовал FlatList с помощью snapToInterval, но на Android наблюдается «странное» поведение прокрутки:
- Выбор часто останавливается «на полпути» между двумя числами.
- Выбранное число выглядит немного смещенным от центра (слишком низко) по сравнению с полосой выделения.
- Иногда прокрутка подпрыгивает или заметно корректируется после того, как пользователь поднимает палец.
const ITEM_HEIGHT = 50;
const PickerColumn = ({ data, onValueChange }) => {
// ... setup refs
// I tried correcting the offset manually here, but it conflicts with native momentum
const handleScrollEnd = (event) => {
const offsetY = event.nativeEvent.contentOffset.y;
const index = Math.round(offsetY / ITEM_HEIGHT);
const targetOffset = index * ITEM_HEIGHT;
// If we landed on a decimal pixel (e.g. 48.5), force a snap
if (Math.abs(offsetY - targetOffset) > 1) {
flatListRef.current?.scrollToOffset({
offset: targetOffset,
animated: true
});
}
};
return (
({
length: ITEM_HEIGHT,
offset: ITEM_HEIGHT * index,
index,
})}
/>
);
};
Подробнее здесь: https://stackoverflow.com/questions/798 ... act-native
Мобильная версия