Skip to content

Commit 202855e

Browse files
committed
Some fixes and props improvings
1 parent cb37254 commit 202855e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

components/Container.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import {ScrollView} from 'react-native';
33

4-
export default function Container({stickyHeaderEnabled, children, scrollableContainer, ...rest}) {
4+
export default function Container({stickyHeaderEnabled, children, scrollableContainer, containerRef, stickyHeaderIndex, ...rest}) {
55
return(
66
scrollableContainer ? (
77
<ScrollView
8+
ref={containerRef}
89
stickyHeaderIndices={stickyHeaderEnabled ? [1] : null}
910
{...rest}
1011
>

components/StaticPills.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ import React from 'react';
22
import {useWindowDimensions, Text, TouchableOpacity, View} from "react-native";
33
import {getOpacity} from "../helpers/getOpacity";
44

5-
export default function StaticPills({data, style, x, currentIndex, onPillPress}) {
5+
export default function StaticPills({data, style, x, currentIndex, onPillPress, containerRef, scrollableContainer}) {
66
const width = useWindowDimensions().width;
77
return (
88
<View style={styles.container}>
99
{!!data?.length && data.map((item, index) => (
1010
<View key={index}>
11-
<TouchableOpacity onPress={onPillPress(index)} style={[
11+
<TouchableOpacity
12+
onPress={() => {
13+
onPillPress(index)
14+
15+
if (index === currentIndex && scrollableContainer)
16+
containerRef?.current?.scrollTo({ x: 0, y: 0, animated: true })
17+
}}
18+
style={[
1219
{
1320
paddingHorizontal: 5,
1421
width: width / data.length,

components/Swiper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {usePrevious} from "../helpers/usePrevious";
77
const isJSX = element => typeof element !== 'function' && typeof element?.type === 'object';
88
const isMemo = element => typeof element !== 'function' && typeof element?.type === 'function';
99

10-
export default function Swiper({style, data, isStaticPills, initialScrollIndex, stickyHeaderEnabled, children, scrollableContainer, ...rest}) {
10+
export default function Swiper({style, data, isStaticPills, initialScrollIndex, stickyHeaderEnabled, children, stickyHeaderIndex, scrollableContainer, ...rest}) {
1111
const width = useWindowDimensions().width;
1212
const flatList = useRef(null);
13+
const containerRef = useRef(null);
1314
const scrollViewRef = useRef(null);
1415
const [currentIndex, setCurrentIndex] = useState(initialScrollIndex || 0);
1516
const prevIndex = usePrevious(currentIndex);
@@ -58,8 +59,10 @@ export default function Swiper({style, data, isStaticPills, initialScrollIndex,
5859

5960
return (
6061
<Container
62+
containerRef={containerRef}
6163
stickyHeaderEnabled={stickyHeaderEnabled}
6264
scrollableContainer={scrollableContainer}
65+
stickyHeaderIndex={stickyHeaderIndex}
6366
>
6467
{children}
6568
<View style={[style?.pillsOverflow]}>
@@ -71,6 +74,8 @@ export default function Swiper({style, data, isStaticPills, initialScrollIndex,
7174
]}>
7275
{!!isStaticPills && (
7376
<StaticPills
77+
containerRef={containerRef}
78+
scrollableContainer={scrollableContainer}
7479
data={data}
7580
currentIndex={currentIndex}
7681
x={x}

0 commit comments

Comments
 (0)