Skip to content
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

Fixed deep links functionality #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
66 changes: 35 additions & 31 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
import React, { useEffect, useState } from "react";
import { GluestackUIProvider, Text, Box } from "@gluestack-ui/themed";
import { config } from "@gluestack-ui/config"; // Optional if you want to use default theme
import React from "react";
import { useEffect, useState } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import Navigation from "./navigation/Navigation";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import * as Linking from "expo-linking";
// { LinkingEvent } from "expo-linking" // Import LinkingEvent
import { GluestackUIProvider, Text, Box } from "@gluestack-ui/themed";
import { config } from "@gluestack-ui/config";
import Login from "./screens/Login";
import { createStackNavigator } from "@react-navigation/stack";
import Navigation from "./navigation/Navigation";

const prefix = Linking.createURL("/");
const Stack = createStackNavigator();

const Stack = createNativeStackNavigator();

export default function App() {
const [data, setData] = useState(null);

const linking = {
prefixes:[prefix],
config:{
screens: {
Home: "home",
Camera: "camera",
Events: "events",
Profile: "profile",
Shop: "shop"
}
}
}

const handleDeepLink = (event: { url: string; }) => {
prefixes: [prefix],
config: {
screens: {
login: "login",
Main: {
screens: {
Home: "home",
// Add other screens in your Navigation.tsx here
},
},
},
},
};

const handleDeepLink = (event: LinkingEvent) => {
let parsedData = Linking.parse(event.url);
setData(parsedData);
// console.log(data);
};

useEffect(() => {
async function getInitialURL() {
const initialURL = await Linking.getInitialURL();
if (initialURL) setData(Linking.parse(initialURL));
}
async function getInitialURL() {
const initialURL = await Linking.getInitialURL();
if (initialURL) setData(Linking.parse(initialURL));
}

const listener = Linking.addEventListener("url", handleDeepLink);
if (!data) {
getInitialURL();
}
if (!data) {
getInitialURL();
}
return () => listener.remove();
}, []);

return (
<GluestackUIProvider config={config}>
<SafeAreaProvider>
<NavigationContainer linking={linking}>
<Stack.Navigator screenOptions={{ headerShown: false}}>
<Stack.Screen name="Login" component={Login}/>
<Stack.Screen name="Main" component={Navigation}/>
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="login" component={Login} />
<Stack.Screen name="Main" component={Navigation} />
</Stack.Navigator>
</NavigationContainer>
</NavigationContainer>
</SafeAreaProvider>
</GluestackUIProvider>
);
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,32 @@
"@react-navigation/native": "^6.1.17",
"@react-navigation/native-stack": "^6.9.26",
"@react-navigation/stack": "^6.3.29",
"@reduxjs/toolkit": "^2.2.3",
"@types/react": "~18.2.79",
"babel-preset-fbjs": "^3.4.0",
"eas": "^0.1.0",
"eas-cli": "^8.0.0",
"expo": "^51.0.8",
"expo-camera": "~15.0.9",
"expo-constants": "~16.0.1",
"expo-device": "~6.0.2",
"expo-linking": "~6.3.1",
"expo-notifications": "~0.28.3",
"expo-status-bar": "~1.12.1",
"expo-updates": "~0.25.14",
"install": "^0.13.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dom": "18.2.0"
"react-native": "0.74.1",
"react-native-gesture-handler": "~2.16.1",
"react-native-modal": "^13.0.1",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "4.10.1",
"react-native-safe-area-context": "^4.10.1",
"react-native-screens": "3.31.1",
"react-native-svg": "15.2.0",
"react-native-web": "~0.19.6",
"react-navigation": "^5.0.0"
"react-navigation": "^5.0.0",
"react-redux": "^9.1.0",
"react-native-web": "~0.19.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
5 changes: 5 additions & 0 deletions screens/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from "react";
import { GluestackUIProvider, Text, Box } from "@gluestack-ui/themed";
import { Button, ButtonText, ButtonIcon, AddIcon } from "@gluestack-ui/themed";
import { useRoute } from "@react-navigation/native";

const Home: React.FC = () => {
const route = useRoute();
const { params } = route;
console.log(paramsg);

return (
<Box width="100%" height="100%" justifyContent="center" alignItems="center">
<Text>Open up App.js to start working on your app!</Text>
Expand Down
Loading
Loading