Skip to content

Commit

Permalink
Some fixes and props improvings
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeHop committed May 8, 2021
1 parent cb37254 commit 202855e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion components/Container.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import {ScrollView} from 'react-native';

export default function Container({stickyHeaderEnabled, children, scrollableContainer, ...rest}) {
export default function Container({stickyHeaderEnabled, children, scrollableContainer, containerRef, stickyHeaderIndex, ...rest}) {
return(
scrollableContainer ? (
<ScrollView
ref={containerRef}
stickyHeaderIndices={stickyHeaderEnabled ? [1] : null}
{...rest}
>
Expand Down
11 changes: 9 additions & 2 deletions components/StaticPills.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import React from 'react';
import {useWindowDimensions, Text, TouchableOpacity, View} from "react-native";
import {getOpacity} from "../helpers/getOpacity";

export default function StaticPills({data, style, x, currentIndex, onPillPress}) {
export default function StaticPills({data, style, x, currentIndex, onPillPress, containerRef, scrollableContainer}) {
const width = useWindowDimensions().width;
return (
<View style={styles.container}>
{!!data?.length && data.map((item, index) => (
<View key={index}>
<TouchableOpacity onPress={onPillPress(index)} style={[
<TouchableOpacity
onPress={() => {
onPillPress(index)

if (index === currentIndex && scrollableContainer)
containerRef?.current?.scrollTo({ x: 0, y: 0, animated: true })
}}
style={[
{
paddingHorizontal: 5,
width: width / data.length,
Expand Down
7 changes: 6 additions & 1 deletion components/Swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {usePrevious} from "../helpers/usePrevious";
const isJSX = element => typeof element !== 'function' && typeof element?.type === 'object';
const isMemo = element => typeof element !== 'function' && typeof element?.type === 'function';

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

return (
<Container
containerRef={containerRef}
stickyHeaderEnabled={stickyHeaderEnabled}
scrollableContainer={scrollableContainer}
stickyHeaderIndex={stickyHeaderIndex}
>
{children}
<View style={[style?.pillsOverflow]}>
Expand All @@ -71,6 +74,8 @@ export default function Swiper({style, data, isStaticPills, initialScrollIndex,
]}>
{!!isStaticPills && (
<StaticPills
containerRef={containerRef}
scrollableContainer={scrollableContainer}
data={data}
currentIndex={currentIndex}
x={x}
Expand Down

0 comments on commit 202855e

Please sign in to comment.