-
Notifications
You must be signed in to change notification settings - Fork 5
The AutoCarousel Is Done it's in the component folder #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module.exports = function (api) { | ||
| api.cache(true); | ||
| return { | ||
| presets: [ | ||
| ["babel-preset-expo", { jsxImportSource: "nativewind" }], | ||
| "nativewind/babel", | ||
| ], | ||
| }; | ||
| }; |
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wasn't expecting a new component.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh sorry for that taught i will make a new one let me fix that quickly |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { | ||
| View , | ||
| FlatList, | ||
| Image, | ||
| useWindowDimensions, | ||
| Text , | ||
| Pressable , | ||
| StyleSheet} from 'react-native' | ||
| import React from 'react' | ||
| import Animated, { useAnimatedScrollHandler, useSharedValue , SharedValue , useAnimatedStyle , interpolate , FadeIn, FadeOut} from 'react-native-reanimated' | ||
|
|
||
| import { BlurView } from 'expo-blur'; | ||
| export default function Autocarousel() { | ||
| // This are varibles for the height and width of the image | ||
| const width = useWindowDimensions().width | ||
|
|
||
| // This are the properties for the widths and height | ||
| const _imageWidth = width * 0.7; | ||
| const _imageHeight = _imageWidth * 1.76; | ||
|
|
||
| // Gap spacing for the images since it's horizontal | ||
| const _spacing = 12; | ||
|
|
||
| // For the buttton to appear | ||
| const [button , showButton] = React.useState(false) | ||
|
|
||
|
|
||
| type item = any; | ||
|
|
||
| const datai = [ | ||
| {i: require("@/assets/images/carouselimg/carouselautoi.jpg") , id: 1}, | ||
| {i: require("@/assets/images/carouselimg/carouselautoii.jpg") , id: 2}, | ||
| {i: require("@/assets/images/carouselimg/carouselautoiii.jpg") , id: 3}, | ||
| {i: require("@/assets/images/carouselimg/carouselautoiv.jpg") , id: 4} | ||
| ] | ||
|
|
||
| // This is for the auto-Scroll | ||
| const flatListRef = React.useRef<FlatList<item>>(null); | ||
| const [currentIndex, setCurrentIndex] = React.useState(0); | ||
|
|
||
|
|
||
| React.useEffect(() => { | ||
| const interval = setInterval(() => { | ||
| if (flatListRef.current) { | ||
| if (currentIndex < datai.length - 1) { | ||
| setCurrentIndex(prevIndex => prevIndex + 1); | ||
| flatListRef.current?.scrollToIndex({ index: currentIndex + 1, animated: true}) | ||
| } else { | ||
| clearInterval(interval); | ||
| } | ||
| } | ||
|
|
||
| return () => clearInterval(interval); | ||
|
|
||
| }, 2000); // Auto-scroll every 3 seconds | ||
|
|
||
| return () => clearInterval(interval); // Cleanup on unmount | ||
| }, [currentIndex]); | ||
|
|
||
|
|
||
|
|
||
| const BackdropImages =( | ||
| { items , index , scrollX }:{items : item , index: number , scrollX: SharedValue<number>})=>{ | ||
|
|
||
| // For the animated stylez | ||
| const stylez = useAnimatedStyle(()=>{ | ||
| return{ | ||
| opacity: interpolate( | ||
| scrollX.value , | ||
| [index -1 ,index, index + 1] , | ||
| [0 , 1 ,0] , | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| return( | ||
| <BlurView intensity={80} tint='dark'> | ||
| <Animated.Image | ||
| source={items.i} | ||
| style ={[StyleSheet.absoluteFillObject , stylez]} | ||
| blurRadius={50} | ||
| /> | ||
| </BlurView> | ||
| ) | ||
| } | ||
|
|
||
| // This is the render for the Flatlist | ||
| const renderItems = ( | ||
| {item , index , scrollX }: | ||
| { | ||
| item:item , | ||
| index: number , | ||
| scrollX: SharedValue<number> | ||
| } | ||
| ) => { | ||
|
|
||
| return( | ||
| <View | ||
| className={'flex-1 overflow-hidden rounded-xl'} | ||
| style={{ | ||
| width: _imageWidth, | ||
| height: _imageHeight | ||
| }} | ||
| > | ||
| <Animated.Image | ||
| source={item.i} | ||
| className='flex-1' | ||
| style={{flex:1 }} | ||
| /> | ||
| </View> | ||
| ) | ||
| } | ||
|
|
||
| // For the smooth animation in the sliding | ||
| const scrollX = useSharedValue(0); | ||
| const onScroll = useAnimatedScrollHandler((e) =>{ | ||
| // Giving the exact position the picture index are | ||
| scrollX.value = e.contentOffset.x / (_imageWidth + _spacing) | ||
| // Show button if at the last item | ||
| // if (scrollX.value >= datai.length - 1) { | ||
| // showButton(true); | ||
| // } else { | ||
| // showButton(false); | ||
| // } | ||
|
|
||
| }) | ||
| return ( | ||
| <View className='justify-center items-center bg-white' style={{flex: 1}}> | ||
| <View | ||
| style ={StyleSheet.absoluteFillObject} | ||
| > | ||
| { | ||
| datai.map((item , index) =>( | ||
| <BackdropImages items={item} index={index} scrollX={scrollX}/> | ||
| ) | ||
| ) | ||
| } | ||
| </View> | ||
|
|
||
| <Animated.FlatList | ||
| ref={flatListRef} | ||
| data={datai} | ||
| renderItem={({ item , index})=>renderItems({item , index , scrollX})} | ||
| keyExtractor={(item, index: number) => index.toString()} | ||
| className={'flex-grow-0'} | ||
| snapToInterval={_imageWidth + _spacing } | ||
| decelerationRate={"fast"} | ||
| contentContainerStyle = {{ | ||
| gap: _spacing , | ||
| paddingHorizontal : (40) | ||
| }} | ||
| horizontal = {true} | ||
| onScroll={onScroll} | ||
| scrollEventThrottle={ 1000 / 60 } // 16.6 ms | ||
| showsHorizontalScrollIndicator = {false} | ||
| /> | ||
|
|
||
| {/* {showButton && | ||
| <Button title="Next Step" onPress={() => alert('Button Clicked!')} /> | ||
| } */} | ||
|
|
||
| { | ||
| button && | ||
| <Pressable> | ||
| <Animated.View | ||
| className='bg-blue-600 w-20 h-20 rounded-full items-center justify-center position: absolute top-[60] left-[90]' | ||
| entering={FadeIn.duration(300)} | ||
| exiting={FadeOut.duration(300)} | ||
| > | ||
| <Text | ||
| className='color-white' | ||
| > | ||
| Next | ||
| </Text> | ||
| </Animated.View> | ||
| </Pressable> | ||
| } | ||
|
|
||
| </View> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @import "tailwindcss/base"; | ||
|
|
||
| @import "tailwindcss/components"; | ||
|
|
||
| @import "tailwindcss/utilities"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| // Learn more https://docs.expo.io/guides/customizing-metro | ||
| const { getDefaultConfig } = require('expo/metro-config'); | ||
| const { withNativeWind } = require('nativewind/metro'); | ||
|
|
||
| /** @type {import('expo/metro-config').MetroConfig} */ | ||
| const config = getDefaultConfig(__dirname); | ||
|
|
||
| module.exports = config; | ||
| module.exports = withNativeWind(config, { input: './global.css' }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /// <reference types="nativewind/types" /> | ||
|
|
||
| // NOTE: This file should not be edited and should be committed with your source code. It is generated by NativeWind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are to use the previous images there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i will work on that now