Вот функции изменения страницы:
Код: Выделить всё
const pagerRef = useRef(null);
const [ currentPage, setCurrentPage ] = useState(0)
Код: Выделить всё
const goToNextPage = () => {
//console.log("Pager ref: ", pagerRef.current)
const currentPageIndex = currentPage;
const nextPageIndex = currentPageIndex + 1
if (currentPageIndex < 3) {
console.log("Current page index: ", currentPageIndex)
console.log("Going to page index: ", nextPageIndex)
setCurrentPage(nextPageIndex);
}
pagerRef.current?.setPage(nextPageIndex);
};
const goToPreviousPage = () => {
const currentPageIndex = currentPage;
const previousPageIndex = currentPageIndex - 1;
if (currentPageIndex > 0) {
console.log("Current page index: ", currentPageIndex)
console.log("Going to page index: ", previousPageIndex)
setCurrentPage(previousPageIndex);
}
pagerRef.current?.setPage(previousPageIndex);
};
Код: Выделить всё
style={styles.pager}
ref={pagerRef}
initialPage={0}
scrollEnabled={true}
>
Page 1
Page 2
Page 3
Page 4
Код: Выделить всё
useEffect(() => {pagerRef.current?.setPage(currentPage)}, [currentPage])
-обновление. Не уверен, что это вообще поможет. Но перестает работать не сама прокрутка. У меня на страницах было несколько компонентов, и они тоже перестали отвечать на запросы. Кажется, что весь компонент PagerView просто перестает отвечать на запросы. Эта проблема все еще возникала, когда я удалил эти пользовательские компоненты и использовал компоненты View, как показано выше.
Подробнее здесь: https://stackoverflow.com/questions/784 ... ime-on-ios