Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions example/src/CustomRenderFunctionExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const slides: ISliderIntroItem[] = [
},
];

// Do not forget to add the following wrapper inside your map to make sure each slide uses the maximum size of the screen:
// <View style={{ width: Dimensions.get('window').width }} key={index}>{YOUR ITEM}</View>

const CustomRenderFunctionExample = ({
closeExample,
}: {
Expand Down Expand Up @@ -67,37 +70,39 @@ const CustomRenderFunctionExample = ({
const language = activeLanguage || 'en';
const slideHeight = deviceMaxHeight * (slideMaxHeightPercent || 0.78);
return (
<View key={index} style={[styles.slide, { backgroundColor }]}>
<View
style={[
styles.container,
{
height: slideHeight,
maxHeight: slideHeight,
},
]}
>
<Text style={styles.title}>
{Array.isArray(title)
? title[language as unknown as number]
: title}
</Text>
{image && <Image style={styles.image} source={image} />}
<View>
<Text style={styles.language}>
{Array.isArray(text)
? text[language as unknown as number]
: text}
<View style={{ width: width }} key={index}>
<View style={[styles.slide, { backgroundColor }]}>
<View
style={[
styles.container,
{
height: slideHeight,
maxHeight: slideHeight,
},
]}
>
<Text style={styles.title}>
{Array.isArray(title)
? title[language as unknown as number]
: title}
</Text>
{link && (
<TouchableWithoutFeedback
onPressIn={() => {
Linking.openURL(link);
}}
>
<Text style={styles.link}>{link}</Text>
</TouchableWithoutFeedback>
)}
{image && <Image style={styles.image} source={image} />}
<View>
<Text style={styles.language}>
{Array.isArray(text)
? text[language as unknown as number]
: text}
</Text>
{link && (
<TouchableWithoutFeedback
onPressIn={() => {
Linking.openURL(link);
}}
>
<Text style={styles.link}>{link}</Text>
</TouchableWithoutFeedback>
)}
</View>
</View>
</View>
</View>
Expand Down
101 changes: 53 additions & 48 deletions example/src/UsingThirdPartyLibrariesExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { createShimmerPlaceholder } from 'react-native-shimmer-placeholder';

const ShimmerPlaceHolder = createShimmerPlaceholder(LinearGradient as any);

const { width, height } = Dimensions.get('window');

const slides: ISliderIntroItem[] = [
{
index: 1,
Expand Down Expand Up @@ -47,6 +49,9 @@ const slides: ISliderIntroItem[] = [

const deviceMaxHeight = Dimensions.get('screen').height;

// Do not forget to add the following wrapper inside your map to make sure each slide uses the maximum size of the screen:
// <View style={{ width: Dimensions.get('window').width }} key={index}>{YOUR ITEM}</View>

const UsingThirdPartyLibrariesExample = ({
closeExample,
}: {
Expand Down Expand Up @@ -87,54 +92,56 @@ const UsingThirdPartyLibrariesExample = ({
const language = activeLanguage || 'en';
const slideHeight = deviceMaxHeight * (slideMaxHeightPercent || 0.78);
return (
<View key={index} style={[styles.slide, { backgroundColor }]}>
<View
style={[
styles.container,
{
height: slideHeight,
maxHeight: slideHeight,
},
]}
>
<ShimmerPlaceHolder visible={fakeLoading} height={30}>
<Text style={styles.title}>
{Array.isArray(title)
? title[language as unknown as number]
: title}
</Text>
</ShimmerPlaceHolder>
{icon && (
<ShimmerPlaceHolder visible={fakeLoading} height={260}>
<FontAwesomeIcon
icon={icon}
color={'steelblue'}
size={200}
/>
</ShimmerPlaceHolder>
)}
<ShimmerPlaceHolder
visible={fakeLoading}
height={50}
width={250}
<View style={{ width: width }} key={index}>
<View key={index} style={[styles.slide, { backgroundColor }]}>
<View
style={[
styles.container,
{
height: slideHeight,
maxHeight: slideHeight,
},
]}
>
<View>
<Text style={styles.language}>
{Array.isArray(text)
? text[language as unknown as number]
: text}
<ShimmerPlaceHolder visible={fakeLoading} height={30}>
<Text style={styles.title}>
{Array.isArray(title)
? title[language as unknown as number]
: title}
</Text>
{link && (
<TouchableWithoutFeedback
onPressIn={() => {
Linking.openURL(link);
}}
>
<Text style={styles.link}>{link}</Text>
</TouchableWithoutFeedback>
)}
</View>
</ShimmerPlaceHolder>
</ShimmerPlaceHolder>
{icon && (
<ShimmerPlaceHolder visible={fakeLoading} height={260}>
<FontAwesomeIcon
icon={icon}
color={'steelblue'}
size={200}
/>
</ShimmerPlaceHolder>
)}
<ShimmerPlaceHolder
visible={fakeLoading}
height={50}
width={250}
>
<View>
<Text style={styles.language}>
{Array.isArray(text)
? text[language as unknown as number]
: text}
</Text>
{link && (
<TouchableWithoutFeedback
onPressIn={() => {
Linking.openURL(link);
}}
>
<Text style={styles.link}>{link}</Text>
</TouchableWithoutFeedback>
)}
</View>
</ShimmerPlaceHolder>
</View>
</View>
</View>
);
Expand All @@ -144,8 +151,6 @@ const UsingThirdPartyLibrariesExample = ({
);
};

const { width, height } = Dimensions.get('window');

const styles = StyleSheet.create({
container: {
paddingTop: 9,
Expand Down
9 changes: 4 additions & 5 deletions src/components/SliderProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const SliderContext = createContext<ISliderContextProps>({
goToNewSlide: () => void 0,
isLastSlide: false,
setDefaultState: () => void 0,
isCustomRender: false,
});

const deviceMaxWidth = Dimensions.get('window').width;
Expand All @@ -65,11 +64,12 @@ const SliderProvider = (props: ISliderProviderProps) => {
animateDotSpeed,
hasReactNavigation,
useCustomBackHandlerEffect,
isCustomRender,
data,
children,
} = props;
const isCustomRender = !data?.length && !!children;
const numberOfSlides = data?.length ?? props?.numberOfSlides ?? 1;
const numberOfSlides = isCustomRender
? props?.numberOfSlides
: data?.length ?? 1;
const panResponderState = useState<PanResponderInstance>(
PanResponder.create(Object.create(null))
);
Expand Down Expand Up @@ -342,7 +342,6 @@ const SliderProvider = (props: ISliderProviderProps) => {
isLastSlide,
goToNewSlide,
setDefaultState,
isCustomRender,
};

return (
Expand Down
13 changes: 6 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const styles = StyleSheet.create({

const deviceMaxWidth = Dimensions.get('window').width;

const SliderIntroContainer = () => {
const SliderIntroContainer = ({ children }: { children: React.ReactNode }) => {
const {
showStatusBar,
renderStatusBar,
Expand All @@ -25,10 +25,9 @@ const SliderIntroContainer = () => {
data,
animations: { _moveSlideX },
numberOfSlides,
isCustomRender,
children,
} = useContext(SliderContext);
const [panResponder] = panResponderState;

return (
<>
{showStatusBar && renderStatusBar(statusBarColor)}
Expand All @@ -42,8 +41,8 @@ const SliderIntroContainer = () => {
]}
{...panResponder.panHandlers}
>
{isCustomRender ? (
children
{children ? (
<>{children}</>
) : (
<>
{data?.map((item: ISliderIntroItem) => {
Expand All @@ -69,8 +68,8 @@ const SliderIntroContainer = () => {

function SliderIntro(props: ISliderIntro) {
return (
<SliderProvider {...props}>
<SliderIntroContainer />
<SliderProvider {...props} isCustomRender={!!props.children}>
<SliderIntroContainer children={props.children} />
</SliderProvider>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ISliderProvider.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface ISliderContextProps extends ISliderIntro {
goToNewSlide: (newSlide: number) => void;
setDefaultState: () => void;
isLastSlide: boolean;
isCustomRender: boolean;
}

export interface ISliderProviderProps extends ISliderIntro {
children: React.ReactNode;
isCustomRender: boolean;
}