-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Horizontal slider add and HomeScreen update
- Loading branch information
1 parent
a7e4ebd
commit 957c04c
Showing
15 changed files
with
350 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { NavigationContainer } from "@react-navigation/native"; | ||
import FavoriteContextProvider from "./src/Context/FavoritesContextProvider"; | ||
import CartContextProvider from "./src/Context/CartContext/CartContextProvider"; | ||
import FavoriteContextProvider from "./src/Context/FavoriteContext/FavoritesContextProvider"; | ||
import { Navigator } from "./src/Navigator/Navigator"; | ||
|
||
export default function App() { | ||
return ( | ||
<FavoriteContextProvider> | ||
<NavigationContainer> | ||
<Navigator /> | ||
</NavigationContainer> | ||
<CartContextProvider> | ||
<NavigationContainer> | ||
<Navigator /> | ||
</NavigationContainer> | ||
</CartContextProvider> | ||
</FavoriteContextProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useContext } from "react"; | ||
import { | ||
TouchableOpacity, | ||
View, | ||
Image, | ||
Pressable, | ||
StyleSheet, | ||
} from "react-native"; | ||
import { FontAwesome } from "@expo/vector-icons"; | ||
import { Text } from "./Text"; | ||
import CartContext from "../Context/CartContext/CartContext"; | ||
export const CartItem = ({ item, id }) => { | ||
const { removeFromCart } = useContext(CartContext); | ||
return ( | ||
<TouchableOpacity style={styles.container}> | ||
<View style={styles.innerContainer}> | ||
<Image style={styles.image} source={{ uri: item.imageURL }} /> | ||
<Text>{item.productName}</Text> | ||
<Text>{item.size}</Text> | ||
<Text>$ {item.productPrice}</Text> | ||
<Pressable | ||
style={{ zIndex: 10 }} | ||
onPress={() => { | ||
console.log("PRESSED"); | ||
removeFromCart({ id, productPrice: item.productPrice }); | ||
}} | ||
> | ||
<FontAwesome name="times" size={24} color="red" /> | ||
</Pressable> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginVertical: 10, | ||
marginHorizontal: 20, | ||
borderRadius: 5, | ||
backgroundColor: "#f1f3f5", | ||
}, | ||
innerContainer: { | ||
display: "flex", | ||
flexDirection: "row", | ||
justifyContent: "space-around", | ||
alignItems: "center", | ||
}, | ||
image: { | ||
width: 100, | ||
height: 100, | ||
resizeMode: "contain", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import { FlatList, StyleSheet } from "react-native"; | ||
import { SliderProductItem } from "./SliderProductItem"; | ||
import { Text } from "./Text"; | ||
export const HorizontalSlider = ({ products, title }) => { | ||
return ( | ||
<> | ||
<Text style={styles.headline}>{title}</Text> | ||
{products && ( | ||
<FlatList | ||
style={styles.list} | ||
horizontal | ||
data={products} | ||
renderItem={({ item }) => <SliderProductItem item={item} />} | ||
showsHorizontalScrollIndicator={false} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
list: { | ||
marginHorizontal: 20, | ||
}, | ||
headline: { | ||
marginTop: 20, | ||
fontSize: 20, | ||
color: "#ffffff", | ||
marginLeft: 24, | ||
textTransform: "uppercase", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { View, Image, StyleSheet, TouchableOpacity } from "react-native"; | ||
import { Text } from "./Text"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
|
||
export const SliderProductItem = ({ item }) => { | ||
const navigator = useNavigation(); | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
navigator.navigate("ProductDetailScreen", item); | ||
}} | ||
style={styles.outerContainer} | ||
> | ||
<View style={styles.container}> | ||
<View style={styles.imageContainer}> | ||
<Image style={styles.image} source={{ uri: item.imageURL }} /> | ||
</View> | ||
<View style={styles.textContainer}> | ||
<Text style={styles.textStyle}>{item.productName}</Text> | ||
<Text>${item.productPrice}</Text> | ||
</View> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
outerContainer: { | ||
marginHorizontal: 4, | ||
}, | ||
container: { | ||
width: 300, | ||
marginTop: 10, | ||
marginHorizontal: 20, | ||
paddingVertical: 20, | ||
marginRight: "auto", | ||
marginLeft: "auto", | ||
backgroundColor: "#a8edf599", | ||
borderRadius: 10, | ||
}, | ||
imageContainer: { | ||
width: 180, | ||
height: 180, | ||
marginRight: "auto", | ||
marginLeft: "auto", | ||
}, | ||
image: { | ||
widht: 180, | ||
height: 180, | ||
resizeMode: "contain", | ||
}, | ||
textStyle: { | ||
textAlign: "left", | ||
color: "#ffffff", | ||
fontSize: 16, | ||
}, | ||
textContainer: { | ||
display: "flex", | ||
justifyContent: "space-around", | ||
alignItems: "center", | ||
flexDirection: "row", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createContext } from "react"; | ||
|
||
const CartContext = createContext(); | ||
|
||
export const { Provider } = CartContext; | ||
|
||
export default CartContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
import { Provider } from "./CartContext"; | ||
|
||
const CartContextProvider = ({ children }) => { | ||
const [cartItems, setCartItems] = useState([]); | ||
const [totalCost, setTotalCost] = useState(0); | ||
const addToCart = (item) => { | ||
if (cartItems.includes(item)) return; | ||
setCartItems([...cartItems, item]); | ||
setTotalCost(totalCost + item.productPrice); | ||
}; | ||
|
||
const removeFromCart = (item) => { | ||
console.log("entre"); | ||
let updatedCartItems = cartItems.filter( | ||
(cartItem, index) => index !== item.id | ||
); | ||
setCartItems(updatedCartItems); | ||
setTotalCost(totalCost - item.productPrice); | ||
}; | ||
|
||
return ( | ||
<Provider | ||
value={{ | ||
cartItems, | ||
addToCart, | ||
removeFromCart, | ||
totalCost, | ||
}} | ||
> | ||
{children} | ||
</Provider> | ||
); | ||
}; | ||
|
||
export default CartContextProvider; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { useContext } from "react"; | ||
import { View, SafeAreaView, StyleSheet } from "react-native"; | ||
import { Text } from "../Components/Text"; | ||
import { LinearGradient } from "expo-linear-gradient"; | ||
import CartContext from "../Context/CartContext/CartContext"; | ||
import { FlatList } from "react-native-gesture-handler"; | ||
import { CartItem } from "../Components/CartItem"; | ||
|
||
export const CartScreen = () => { | ||
const { cartItems, totalCost } = useContext(CartContext); | ||
|
||
return ( | ||
<LinearGradient | ||
// Button Linear Gradient | ||
colors={["#E58C8A", "#EEC0C6"]} | ||
style={{ flex: 1 }} | ||
> | ||
<SafeAreaView> | ||
<View> | ||
<Text style={styles.headline}>Cart Items</Text> | ||
</View> | ||
{cartItems.length > 0 ? ( | ||
<FlatList | ||
data={cartItems} | ||
keyExtractor={(item, index) => { | ||
return `${item.id}${index}`; | ||
}} | ||
renderItem={({ item, index }) => ( | ||
<CartItem id={index} item={item} /> | ||
)} | ||
/> | ||
) : ( | ||
<Text style={styles.alternativeText}>No Items On Cart...</Text> | ||
)} | ||
{cartItems.length > 0 && ( | ||
<View style={styles.costContainer}> | ||
<Text style={{ fontSize: 20 }}>Total cost:</Text> | ||
<Text style={{ fontSize: 20 }}>$ {totalCost}</Text> | ||
</View> | ||
)} | ||
</SafeAreaView> | ||
</LinearGradient> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
headline: { | ||
color: "#ffffff", | ||
textAlign: "center", | ||
fontSize: 40, | ||
letterSpacing: 4, | ||
marginTop: 20, | ||
}, | ||
costContainer: { | ||
display: "flex", | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
marginHorizontal: 20, | ||
borderTopWidth: 4, | ||
borderTopColor: "black", | ||
}, | ||
alternativeText: { | ||
fontSize: 30, | ||
textAlign: "center", | ||
marginTop: 200, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.