preparing for large layouts

This commit is contained in:
balzack 2022-09-17 00:22:12 -07:00
parent c1141b2102
commit 74589ce5ad
4 changed files with 45 additions and 30 deletions

View File

@ -1,5 +1,6 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { useWindowDimensions } from 'react-native'; import { useWindowDimensions } from 'react-native';
import config from 'constants/Config';
export function useAccess() { export function useAccess() {
@ -13,7 +14,7 @@ export function useAccess() {
} }
useEffect(() => { useEffect(() => {
if (dimensions.width > 650) { if (dimensions.width > config.tabbedWidth) {
updateState({ split: true }); updateState({ split: true });
} }
else { else {

View File

@ -0,0 +1,5 @@
export const Config = {
tabbedWidth: 650,
};
export default Config;

View File

@ -47,6 +47,7 @@ export function Session() {
return ( return (
<SafeAreaProvider> <SafeAreaProvider>
<NavigationContainer> <NavigationContainer>
{ state.tabbed && (
<Tab.Navigator <Tab.Navigator
screenOptions={({ route }) => ({ screenOptions={({ route }) => ({
tabBarStyle: styles.tabBar, tabBarStyle: styles.tabBar,
@ -71,6 +72,7 @@ export function Session() {
<Tab.Screen name="Profile" component={ProfileStackScreen} /> <Tab.Screen name="Profile" component={ProfileStackScreen} />
<Tab.Screen name="Contacts" component={ContactStackScreen} /> <Tab.Screen name="Contacts" component={ContactStackScreen} />
</Tab.Navigator> </Tab.Navigator>
)}
</NavigationContainer> </NavigationContainer>
</SafeAreaProvider> </SafeAreaProvider>
); );

View File

@ -2,12 +2,14 @@ import { useState, useEffect, useContext } from 'react';
import { useWindowDimensions } from 'react-native'; import { useWindowDimensions } from 'react-native';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { AppContext } from 'context/AppContext'; import { AppContext } from 'context/AppContext';
import config from 'constants/Config';
export function useSession() { export function useSession() {
const [state, setState] = useState({ const [state, setState] = useState({
tabbled: null,
}); });
const dimensions = useWindowDimensions();
const app = useContext(AppContext); const app = useContext(AppContext);
const navigate = useNavigate(); const navigate = useNavigate();
@ -15,11 +17,16 @@ export function useSession() {
setState((s) => ({ ...s, ...value })); setState((s) => ({ ...s, ...value }));
} }
useEffect(() => {
if (dimensions.width > config.tabbedWidth) {
updateState({ tabbed: false });
}
else {
updateState({ tabbed: true });
}
}, [dimensions]);
const actions = { const actions = {
logout: async () => {
await app.actions.logout();
navigate('/');
},
}; };
return { state, actions }; return { state, actions };