Skip to content

Commit

Permalink
added bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
vickkie committed Jul 28, 2024
1 parent 29c3960 commit e367529
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 45 deletions.
82 changes: 45 additions & 37 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import "react-native-gesture-handler";
import { enableScreens } from "react-native-screens";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { StyleSheet, Text, View } from "react-native";
import { StyleSheet, View } from "react-native";
import { useFonts } from "expo-font";
import * as SplashScreen from "expo-splash-screen";
import { useCallback, useEffect } from "react";
import BottomTabNavigation from "./navigation/BottomTabNavigation";
import { useEffect } from "react";
import Toast from "react-native-toast-message";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";

import BottomTabNavigation from "./navigation/BottomTabNavigation";
import { AuthProvider } from "./components/auth/AuthContext";
import { CartProvider } from "./contexts/CartContext";
import { WishProvider } from "./contexts/WishContext";
import { chatScreenOptions, systemScreenOptions } from "./screens_options/AppHeaderOptions";
import {
Cart,
ProductDetails,
Expand All @@ -25,14 +32,8 @@ import {
Faqs,
SystemMessages,
} from "./screens";
import { AuthProvider } from "./components/auth/AuthContext";
import { CartProvider } from "./contexts/CartContext";
import { WishProvider } from "./contexts/WishContext";

import { chatScreenOptions, faqScreenOptions, systemScreenOptions } from "./screens_options/AppHeaderOptions";

enableScreens();

const Stack = createNativeStackNavigator();

export default function App() {
Expand All @@ -52,7 +53,6 @@ export default function App() {
await SplashScreen.hideAsync();
}
};

prepare();
}, [fontsLoaded]);

Expand All @@ -61,33 +61,41 @@ export default function App() {
}

return (
<AuthProvider>
<CartProvider>
<WishProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Bottom Navigation" component={BottomTabNavigation} options={{ headerShown: false }} />
<Stack.Screen name="Login" component={LoginPage} options={{ headerShown: false }} />
<Stack.Screen name="ProductDetails" component={ProductDetails} options={{ headerShown: false }} />
<Stack.Screen name="ProductList" component={Products} options={{ headerShown: false }} />
<Stack.Screen name="Favourites" component={Favourites} options={{ headerShown: false }} />
<Stack.Screen name="Categories" component={Categories} options={{ headerShown: true }} />
<Stack.Screen name="Cart" component={Cart} options={{ headerShown: false }} />
<Stack.Screen name="Checkout" component={Checkout} options={{ headerShown: false }} />
<Stack.Screen name="Orders" component={Orders} options={{ headerShown: false }} />
<Stack.Screen name="Register" component={Register} options={{ headerShown: false }} />
<Stack.Screen name="UserDetails" component={UserDetails} options={{ headerShown: false }} />
<Stack.Screen name="Message" component={MessageCenter} options={{ headerShown: false }} />
<Stack.Screen name="Help" component={Help} options={chatScreenOptions} />
<Stack.Screen name="About" component={About} options={{ headerShown: true }} />
<Stack.Screen name="Faqs" component={Faqs} options={{ headerShown: false }} />
<Stack.Screen name="SystemMessages" component={SystemMessages} options={systemScreenOptions} />
</Stack.Navigator>
<Toast />
</NavigationContainer>
</WishProvider>
</CartProvider>
</AuthProvider>
<GestureHandlerRootView style={{ flex: 1 }}>
<BottomSheetModalProvider>
<AuthProvider>
<CartProvider>
<WishProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Bottom Navigation"
component={BottomTabNavigation}
options={{ headerShown: false }}
/>
<Stack.Screen name="Login" component={LoginPage} options={{ headerShown: false }} />
<Stack.Screen name="ProductDetails" component={ProductDetails} options={{ headerShown: false }} />
<Stack.Screen name="ProductList" component={Products} options={{ headerShown: false }} />
<Stack.Screen name="Favourites" component={Favourites} options={{ headerShown: false }} />
<Stack.Screen name="Categories" component={Categories} options={{ headerShown: true }} />
<Stack.Screen name="Cart" component={Cart} options={{ headerShown: false }} />
<Stack.Screen name="Checkout" component={Checkout} options={{ headerShown: false }} />
<Stack.Screen name="Orders" component={Orders} options={{ headerShown: false }} />
<Stack.Screen name="Register" component={Register} options={{ headerShown: false }} />
<Stack.Screen name="UserDetails" component={UserDetails} options={{ headerShown: false }} />
<Stack.Screen name="Message" component={MessageCenter} options={{ headerShown: false }} />
<Stack.Screen name="Help" component={Help} options={chatScreenOptions} />
<Stack.Screen name="About" component={About} options={{ headerShown: true }} />
<Stack.Screen name="Faqs" component={Faqs} options={{ headerShown: false }} />
<Stack.Screen name="SystemMessages" component={SystemMessages} options={systemScreenOptions} />
</Stack.Navigator>
<Toast />
</NavigationContainer>
</WishProvider>
</CartProvider>
</AuthProvider>
</BottomSheetModalProvider>
</GestureHandlerRootView>
);
}

Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function (api) {
allowUndefined: true,
},
],
"react-native-reanimated/plugin",
],
};
};
52 changes: 52 additions & 0 deletions components/bottomsheets/HomeMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useRef, useMemo, forwardRef, useCallback } from "react";
import { StyleSheet, Text, View, Modal } from "react-native";
import { BottomSheetBackdrop, BottomSheetModal } from "@gorhom/bottom-sheet";
import { COLORS } from "../../constants";

// HomeMenu.js
const HomeMenu = React.forwardRef((props, ref) => {
const snapPoints = useMemo(() => ["25%", "50%"], []);

const renderBackdrop = useCallback(
(props) => <BottomSheetBackdrop appearsOnIndex={0} disappearsOnIndex={-1} {...props} opacity={0.5} />,
[]
);

return (
<BottomSheetModal
ref={ref}
index={1}
snapPoints={snapPoints}
onChange={(index) => console.log("Changed", index)}
enablePanDownToClose={true}
backgroundStyle={{ backgroundColor: COLORS.themeg }}
backdropComponent={renderBackdrop}
>
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Swipe down to close</Text>
</View>
</BottomSheetModal>
);
});

export default HomeMenu;

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
contentContainer: {
flex: 1,
alignItems: "center",
},
bottomSheetBackground: {
backgroundColor: "white",
},
backdrop: {
...StyleSheet.absoluteFillObject,
backgroundColor: "black",
opacity: 0.5,
},
});
54 changes: 54 additions & 0 deletions components/bottomsheets/Map.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useRef, useMemo } from "react";
import { StyleSheet, Text, View } from "react-native";
import BottomSheet, { BottomSheetModal } from "@gorhom/bottom-sheet";
import { GestureHandlerRootView } from "react-native-gesture-handler";

export default function Map() {
const snapPoints = useMemo(() => ["25%", "50%", "60%"], []);
const sheetRef = useRef(null);

// callbacks
const handleSheetChanges = (index) => {
console.log("handleSheetChanges", index);
};

return (
<GestureHandlerRootView style={{ flex: 1 }}>
{/* <View style={styles.container}></View> */}

<BottomSheetModal
ref={sheetRef}
index={1}
snapPoints={snapPoints}
onChange={handleSheetChanges}
enablePanDownToClose={true}
backgroundStyle={styles.bottomSheetBackground}
backdropComponent={() => <View style={styles.backdrop} />}
>
<View style={styles.contentContainer}>
<Text>Swipe down to close</Text>
</View>
</BottomSheetModal>
</GestureHandlerRootView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
contentContainer: {
flex: 1,
alignItems: "center",
},
bottomSheetBackground: {
backgroundColor: "white",
},
backdrop: {
...StyleSheet.absoluteFillObject,
backgroundColor: "black",
opacity: 0.5,
},
});
98 changes: 98 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"web": "expo start --web"
},
"dependencies": {
"@gorhom/bottom-sheet": "^4.6.3",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-navigation/bottom-tabs": "^6.5.8",
"@react-navigation/native": "^6.1.7",
Expand All @@ -31,6 +32,8 @@
"react-native-gesture-handler": "~2.12.0",
"react-native-gifted-chat": "^2.4.0",
"react-native-image-slider-box": "^2.0.7",
"react-native-maps": "1.7.1",
"react-native-reanimated": "~3.3.0",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-snap-carousel": "^4.0.0-beta.6",
Expand Down
Loading

0 comments on commit e367529

Please sign in to comment.