wip
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
|||||||
ParamListBase,
|
ParamListBase,
|
||||||
useNavigation as navigationHook,
|
useNavigation as navigationHook,
|
||||||
} from '@react-navigation/native';
|
} from '@react-navigation/native';
|
||||||
import React, { useEffect, useMemo } from 'react';
|
import React, { Component, ComponentProps, ComponentType, ReactElement, ReactNode, useEffect, useMemo } from 'react';
|
||||||
import { DarkTheme, DefaultTheme, NavigationContainer } from '@react-navigation/native';
|
import { DarkTheme, DefaultTheme, NavigationContainer } from '@react-navigation/native';
|
||||||
import { RootState, useSelector } from './state/Store';
|
import { RootState, useSelector } from './state/Store';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
@@ -33,6 +33,7 @@ import ForgotPasswordView from './views/ForgotPasswordView';
|
|||||||
import DiscoveryView from './views/V2/DiscoveryView';
|
import DiscoveryView from './views/V2/DiscoveryView';
|
||||||
import MusicView from './views/MusicView';
|
import MusicView from './views/MusicView';
|
||||||
import Leaderboardiew from './views/LeaderboardView';
|
import Leaderboardiew from './views/LeaderboardView';
|
||||||
|
import { LinearGradient } from 'expo-linear-gradient';
|
||||||
|
|
||||||
// Util function to hide route props in URL
|
// Util function to hide route props in URL
|
||||||
const removeMe = () => '';
|
const removeMe = () => '';
|
||||||
@@ -126,7 +127,7 @@ const publicRoutes = () =>
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type Route<Props = any> = {
|
type Route<Props = any> = {
|
||||||
component: (arg: RouteProps<Props>) => JSX.Element | (() => JSX.Element);
|
component: ComponentType<Props>;
|
||||||
options: object;
|
options: object;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,7 +135,7 @@ type OmitOrUndefined<T, K extends string> = T extends undefined ? T : Omit<T, K>
|
|||||||
|
|
||||||
type RouteParams<Routes extends Record<string, Route>> = {
|
type RouteParams<Routes extends Record<string, Route>> = {
|
||||||
[RouteName in keyof Routes]: OmitOrUndefined<
|
[RouteName in keyof Routes]: OmitOrUndefined<
|
||||||
Parameters<Routes[RouteName]['component']>[0],
|
ComponentProps<Routes[RouteName]['component']>,
|
||||||
keyof NativeStackScreenProps<{}>
|
keyof NativeStackScreenProps<{}>
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
@@ -145,23 +146,31 @@ type AppRouteParams = PrivateRoutesParams & PublicRoutesParams;
|
|||||||
|
|
||||||
const Stack = createNativeStackNavigator<AppRouteParams & { Loading: never; Oops: never }>();
|
const Stack = createNativeStackNavigator<AppRouteParams & { Loading: never; Oops: never }>();
|
||||||
|
|
||||||
const RouteToScreen =
|
const RouteToScreen = <T extends {}>(Component: Route<T>['component']) =>
|
||||||
<T extends {}>(component: Route<T>['component']) =>
|
function Route(props: NativeStackScreenProps<T & ParamListBase>) {
|
||||||
// eslint-disable-next-line react/display-name
|
const colorScheme = useColorScheme();
|
||||||
(props: NativeStackScreenProps<T & ParamListBase>) => (
|
|
||||||
<>
|
return (
|
||||||
{component({ ...props.route.params, route: props.route } as Parameters<
|
<LinearGradient
|
||||||
Route<T>['component']
|
colors={colorScheme === 'dark' ? ['#101014', '#6075F9'] : ['#cdd4fd']}
|
||||||
>[0])}
|
style={{
|
||||||
</>
|
width: '100%',
|
||||||
);
|
height: '100%',
|
||||||
|
position: 'absolute',
|
||||||
|
zIndex: -2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Component {...props.route.params as T} route={props.route} />
|
||||||
|
</LinearGradient>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) =>
|
const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) =>
|
||||||
Object.entries(routes).map(([name, route], routeIndex) => (
|
Object.entries(routes).map(([name, route], routeIndex) => (
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
key={'route-' + routeIndex}
|
key={'route-' + routeIndex}
|
||||||
name={name as keyof AppRouteParams}
|
name={name as keyof AppRouteParams}
|
||||||
options={route.options}
|
options={{ ...route.options, headerTransparent: true }}
|
||||||
component={RouteToScreen(route.component)}
|
component={RouteToScreen(route.component)}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -68,17 +68,6 @@ const ScaffoldCC = ({
|
|||||||
{children}
|
{children}
|
||||||
</ScaffoldDesktopCC>
|
</ScaffoldDesktopCC>
|
||||||
)}
|
)}
|
||||||
{colorScheme === 'dark' && (
|
|
||||||
<LinearGradient
|
|
||||||
colors={['#101014', '#6075F9']}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
position: 'absolute',
|
|
||||||
zIndex: -2,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const HomeView = (props: RouteProps<{}>) => {
|
|||||||
const suggestions = suggestionsQuery.data?.slice(4) ?? [];
|
const suggestions = suggestionsQuery.data?.slice(4) ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScaffoldCC routeName={props.route.name}>
|
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
@@ -84,7 +83,6 @@ const HomeView = (props: RouteProps<{}>) => {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</ScaffoldCC>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user