Browse Source

Implemented Recent News Carousel

Savio Fernando 1 year ago
parent
commit
c1529faaaf
3 changed files with 85 additions and 34 deletions
  1. 79 34
      components/organisms/Sections/RecentNewsSection.js
  2. 5 0
      package-lock.json
  3. 1 0
      package.json

+ 79 - 34
components/organisms/Sections/RecentNewsSection.js

@@ -1,53 +1,98 @@
 import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
 import React from 'react'
-import Header from '../../atoms/Header'
-import { List } from 'react-native-paper'
 import fonts from '../../../theme/fonts'
 import colors from '../../../theme/colors'
 import ImageBGCard from '../Cards/ImageBGCard'
 import images from '../../../assets/images/images'
 import SectionHeader from '../Headers/SectionHeader'
+import metrics from '../../../theme/metrics'
+import Carousel from 'react-native-reanimated-carousel';
+import MaterialComIcon from 'react-native-vector-icons/MaterialCommunityIcons'
 
 
+const ITEM_WIDTH = Math.round(metrics.screenWidth * 0.9);
+const ITEM_HEIGHT = Math.round(ITEM_WIDTH * 3 / 4);
+const entries = [...new Array(6).keys()]
+
 const RecentNewsSection = () => {
+
+  const [currentCardIndex, setCurrentCardIndex] = React.useState(0)
+  const updateCurrentIndex = (index) => {
+    console.log('current index:', index)
+    setCurrentCardIndex(index)
+  }
   return (
     <View>
-            <SectionHeader label={"Recent News"}/>
-          <View style={styles.recentCardContainer}>
-            <ImageBGCard 
-              image={images.imageCard}
-              author={"Ryan Browne"}
-              headline={"Shadow Wizard Money Gang We love casting Spells"}
-            />
-          </View>
-        </View>
+      <SectionHeader label={"Recent News"} />
+      <View style={styles.recentCardContainer}>
+        <Carousel
+          loop
+          width={metrics.screenWidth}
+          height={ITEM_HEIGHT}
+          style={styles.recentCardContainer}
+          autoPlay={true}
+          data={entries}
+          scrollAnimationDuration={1000}
+          mode="parallax"
+          modeConfig={{
+            parallaxScrollingScale: 1,
+            parallaxScrollingOffset: 1,
+          }}
+          onSnapToItem={(index) => updateCurrentIndex(index)}
+          renderItem={({ index }) => (
+            <View style={{ paddingHorizontal: 16 }}>
+              <ImageBGCard
+                image={images.imageCard}
+                author={"Ryan Browne"}
+                headline={`Shadow Wizard Money Gang We love casting Spells ${index}`}
+              />
+            </View>
+
+          )}
+        />
+       
+      </View>
+      <View style={styles.paginationContainer}>
+        {entries.map((item) => {
+          const index = entries.indexOf(item)
+          return <MaterialComIcon name={"checkbox-blank-circle"} color={currentCardIndex === index ? colors.tertiaryColor: colors.lightGray} size={12} />
+        })}
+      </View>
+    </View>
   )
 }
 
 export default RecentNewsSection
 
 const styles = StyleSheet.create({
-    recentHeader: {
-        paddingHorizontal: 16,
-      },
-      recentHeaderText: {
-        fontFamily: fonts.type.semibold,
-        fontSize: fonts.getSize(16),
-        color: colors.black
-      },
-      seeAllText: {
-        fontFamily: fonts.type.semibold,
-        color: colors.topColor,
-        paddingRight: 16,
-        alignSelf: 'stretch'
-    
-      },
-      recentHeaderIcon: {
-    
-      },
-      recentCardContainer: {
-        flexDirection: 'column',
-        paddingHorizontal: 16,
-        overflow: 'hidden'
-      },
+  recentHeader: {
+    paddingHorizontal: 16,
+  },
+  recentHeaderText: {
+    fontFamily: fonts.type.semibold,
+    fontSize: fonts.getSize(16),
+    color: colors.black
+  },
+  seeAllText: {
+    fontFamily: fonts.type.semibold,
+    color: colors.topColor,
+    paddingRight: 16,
+    alignSelf: 'stretch'
+
+  },
+  recentHeaderIcon: {
+
+  },
+  recentCardContainer: {
+    alignItems: 'center',
+    paddingHorizontal: 8
+  },
+  paginationContainer:{
+    justifyContent:'flex-end',
+    alignItems:'center',
+    paddingHorizontal: 16,
+    paddingTop:8,
+    paddingBottom:4,
+    flexDirection:'row',
+    gap:2}
 })

+ 5 - 0
package-lock.json

@@ -7806,6 +7806,11 @@
         }
       }
     },
+    "react-native-reanimated-carousel": {
+      "version": "3.5.1",
+      "resolved": "https://registry.npmjs.org/react-native-reanimated-carousel/-/react-native-reanimated-carousel-3.5.1.tgz",
+      "integrity": "sha512-9BBQV6JAYSQm2lV7MFtT4mzapXmW4IZO6s38gfiJL84Jg23ivGB1UykcNQauKgtHyhtW2NuZJzItb1s42lM+hA=="
+    },
     "react-native-safe-area-context": {
       "version": "4.6.4",
       "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-4.6.4.tgz",

+ 1 - 0
package.json

@@ -22,6 +22,7 @@
     "react-native-linear-gradient": "^2.6.2",
     "react-native-paper": "^5.8.0",
     "react-native-reanimated": "^3.3.0",
+    "react-native-reanimated-carousel": "^3.5.1",
     "react-native-safe-area-context": "^4.6.4",
     "react-native-screens": "^3.20.0",
     "react-native-vector-icons": "^9.2.0"