From 8eb524cc8146371782b15838d63d3a43bc2db4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 30 Mar 2023 22:16:10 +0200 Subject: [PATCH] v1 of TabRowNavigator --- front/Navigation.tsx | 2 +- front/components/forms/changePasswordForm.tsx | 6 - .../components/navigators/TabRowNavigator.tsx | 130 ++++++++++++++++++ front/views/SettingsView.tsx | 22 +-- 4 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 front/components/navigators/TabRowNavigator.tsx diff --git a/front/Navigation.tsx b/front/Navigation.tsx index 91d7be7..71efac4 100644 --- a/front/Navigation.tsx +++ b/front/Navigation.tsx @@ -7,7 +7,7 @@ import SongLobbyView from './views/SongLobbyView'; import AuthenticationView from './views/AuthenticationView'; import HomeView from './views/HomeView'; import SearchView from './views/SearchView'; -import SetttingsNavigator from './views/settings/SettingsView'; +import SetttingsNavigator from './views/SettingsView'; import { useQuery } from 'react-query'; import API from './API'; import PlayView from './views/PlayView'; diff --git a/front/components/forms/changePasswordForm.tsx b/front/components/forms/changePasswordForm.tsx index fd27c6e..647f9aa 100644 --- a/front/components/forms/changePasswordForm.tsx +++ b/front/components/forms/changePasswordForm.tsx @@ -40,12 +40,6 @@ const ChangePasswordForm = ({ onSubmit }: ChangePasswordFormProps) => { password: string() .min(4, translate("passwordTooShort")) .max(100, translate("passwordTooLong")) - .matches( - /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})/, - translate( - "Must Contain 8 Characters, One Uppercase, One Lowercase, One Number and One Special Case Character" - ) - ) .required("Password is required"), }; const toast = useToast(); diff --git a/front/components/navigators/TabRowNavigator.tsx b/front/components/navigators/TabRowNavigator.tsx new file mode 100644 index 0000000..40503bb --- /dev/null +++ b/front/components/navigators/TabRowNavigator.tsx @@ -0,0 +1,130 @@ +import * as React from "react"; +import { + View, + Text, + Pressable, + StyleProp, + ViewStyle, + StyleSheet, +} from "react-native"; +import { Box } from "native-base"; +import { + createNavigatorFactory, + DefaultNavigatorOptions, + ParamListBase, + CommonActions, + TabActionHelpers, + TabNavigationState, + TabRouter, + TabRouterOptions, + useNavigationBuilder, +} from "@react-navigation/native"; + +// Props accepted by the view +type TabNavigationConfig = { + tabBarStyle: StyleProp; + contentStyle: StyleProp; +}; + +// Supported screen options +type TabNavigationOptions = { + title?: string; +}; + +// Map of event name and the type of data (in event.data) +// +// canPreventDefault: true adds the defaultPrevented property to the +// emitted events. +type TabNavigationEventMap = { + tabPress: { + data: { isAlreadyFocused: boolean }; + canPreventDefault: true; + }; +}; + +// The props accepted by the component is a combination of 3 things +type Props = DefaultNavigatorOptions< + ParamListBase, + TabNavigationState, + TabNavigationOptions, + TabNavigationEventMap +> & + TabRouterOptions & + TabNavigationConfig; + +function TabNavigator({ + initialRouteName, + children, + screenOptions, + tabBarStyle, + contentStyle, +}: Props) { + const { state, navigation, descriptors, NavigationContent } = + useNavigationBuilder< + TabNavigationState, + TabRouterOptions, + TabActionHelpers, + TabNavigationOptions, + TabNavigationEventMap + >(TabRouter, { + children, + screenOptions, + initialRouteName, + }); + + return ( + + + + {state.routes.map((route) => ( + { + const event = navigation.emit({ + type: "tabPress", + target: route.key, + canPreventDefault: true, + data: { + isAlreadyFocused: route.key === state.routes[state.index].key, + }, + }); + + if (!event.defaultPrevented) { + navigation.dispatch({ + ...CommonActions.navigate(route), + target: state.key, + }); + } + }} + style={{ flex: 1 }} + > + {descriptors[route.key].options.title || route.name} + + ))} + + + {state.routes.map((route, i) => { + return ( + + {descriptors[route.key].render()} + + ); + })} + + + + ); +} + +export default createNavigatorFactory< + TabNavigationState, + TabNavigationOptions, + TabNavigationEventMap, + typeof TabNavigator +>(TabNavigator); diff --git a/front/views/SettingsView.tsx b/front/views/SettingsView.tsx index f1da527..3de0c1e 100644 --- a/front/views/SettingsView.tsx +++ b/front/views/SettingsView.tsx @@ -9,6 +9,7 @@ import { useLanguage } from "../state/LanguageSlice"; import { SettingsState, updateSettings } from '../state/SettingsSlice'; import { AvailableLanguages, translate, Translate } from "../i18n/i18n"; import TextButton from '../components/TextButton'; +import createTabRowNavigator from '../components/navigators/TabRowNavigator'; import API from '../API'; @@ -239,7 +240,6 @@ export const ChangeEmailView = ({navigation}) => { return (
-
) } @@ -253,17 +253,19 @@ export const GoogleAccountView = ({navigation}) => { ) } +const TabRow = createTabRowNavigator(); + const SetttingsNavigator = () => { return ( - - - - - - - - - + + + + + + + + + ) }