Skip to content

Commit

Permalink
Slightly less glitchy
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewTurk247 committed Sep 12, 2023
1 parent b70c582 commit 47bab5f
Showing 1 changed file with 61 additions and 8 deletions.
69 changes: 61 additions & 8 deletions components/screens/Section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Layout, List, Tab, TabBar, Text, TopNavigation, ViewPager } from "@ui-k
import { DeviceType } from "expo-device";
import React, { useContext, useEffect, useState } from "react";
import { ActivityIndicator, StyleSheet, View } from "react-native";
import PagerView from "react-native-pager-view";

import { ThemeContext } from "../../theme-context";
import { Spacing } from "../../utils/constants";
Expand Down Expand Up @@ -61,6 +62,7 @@ export default function Section({ route, navigation }) {
};

const Container = theme === "dark" ? Layout : View;
const pagerViewRef = React.useRef(null);

const ContainerSelection = ({ data }) => (
<Container>
Expand Down Expand Up @@ -100,15 +102,66 @@ export default function Section({ route, navigation }) {
return (
<>
<TopNavigation title={category.name} alignment="center" />
<TabBar selectedIndex={selection} onSelect={(index) => setSelection(index)}>
{Object.values(category.desks)?.map((section) => <Tab title={section.name} />)}
<TabBar
selectedIndex={selection}
onSelect={(index) => {
setSelection(index);
pagerViewRef.current.setPage(index);
}}
>
{Object.values(category.desks)?.map((section) => (
<Tab
title={() => (
<Text category="c2" style={{ textAlign: "center" }}>
{section.name}
</Text>
)}
/>
))}
</TabBar>
{Object.values(category.desks)?.map((section, index) => {
if (selection === index) {
return <ContainerSelection data={articles[section.slug]} />;
}
})}

<PagerView
ref={pagerViewRef}
// onPageScrollStateChanged={(e) => {
// console.log(e.nativeEvent.pageScrollState);
// if (e.nativeEvent.pageScrollState === "idle") {
// setSelection(e.nativeEvent.position);
// }
// }}
onPageSelected={(e) => {
console.log(e.nativeEvent.position);
setSelection(e.nativeEvent.position);
}}
style={{ flex: 1 }}
initialPage={0}
overdrag
>
{Object.values(category.desks)?.map((section, index) => (
<Container>
<List
data={articles[section.slug]}
style={{ backgroundColor: "transparent" }}
numColumns={columnCount}
key={columnCount}
scrollEventThrottle={BATCH_SIZE}
showsVerticalScrollIndicator={false}
onEndReachedThreshold={1}
onEndReached={() => {
if (!articlesLoading) {
//setPageNumber(pageNumber + 1);
}
}}
renderItem={({ item, index }) => (
<Wildcard key={item.id} item={item} index={index} navigation={navigation} verbose />
)}
ListFooterComponent={() => {
if (!possiblyReachedEnd || articlesLoading) {
return <Text>{pageNumber}</Text>;
}
}}
/>
</Container>
))}
</PagerView>
</>
);
}
Expand Down

0 comments on commit 47bab5f

Please sign in to comment.