Skip to content

Commit

Permalink
app navigation design related methods added
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Oct 1, 2022
1 parent c12c043 commit c5c94d1
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions src/utils/designSystem.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {DarkTheme, DefaultTheme, Theme} from '@react-navigation/native';
import {NativeStackNavigationOptions} from '@react-navigation/native-stack';
import {BottomTabNavigationOptions} from '@react-navigation/bottom-tabs';
import {StatusBarStyle} from 'expo-status-bar';
import {reaction} from 'mobx';
import {useState} from 'react';
import {Appearance as RNAppearance, useColorScheme} from 'react-native';
import {Appearance as RNAppearance, Platform} from 'react-native';
import {Colors, Typography} from 'react-native-ui-lib';

import {stores} from '../stores';
import {Icon} from '../components/icon';
import {Appearance} from './types/enums';

// =============
// | RN UI Lib |
// =============

const colors = {
primary: '#5383b8', // blue
secondary: '#469c57', // green
Expand Down Expand Up @@ -55,6 +60,9 @@ const setColorsScheme = (appearance: Appearance) => {
else Colors.setScheme(appearance);
};

// ==============
// | Navigation |
// ==============
export const getStatusBarStyle = (): StatusBarStyle => {
const {ui} = stores;

Expand Down Expand Up @@ -124,3 +132,46 @@ export const getHeaderBlurEffect = (): 'regular' | 'light' | 'dark' => {

return ui.isAppearanceSystem ? 'regular' : (ui.appearance as 'light' | 'dark');
};

// Default options
export const screenDefaultOptions = (): NativeStackNavigationOptions => ({
headerShadowVisible: false,
headerTintColor: Colors.primary,

// this setup makes large title work on iOS
...Platform.select({
ios: {
headerLargeTitle: true,
headerTransparent: true,
headerBlurEffect: getHeaderBlurEffect(), // this sets up blurred nav bar
// if you'd like to have a solid color for a nav bar, then you should
// set up `headerStyle: {backgroundColor: Colors.bg2Color}`
},
}),
});

export const tabDefaultOptions = (): BottomTabNavigationOptions => ({
headerShown: false,
tabBarActiveTintColor: Colors.primary,
tabBarInactiveTintColor: Colors.grey40,
tabBarStyle: {backgroundColor: Colors.bgColor, borderTopWidth: 0, elevation: 0},
});

export const getTabBarIcon =
(tabName: string) =>
({focused, color, size}: {focused: boolean; color: string; size: number}) =>
<Icon name={getTabIconName(tabName, focused)} size={size} color={color} />;

const getTabIconName = (tabName: string, focused: boolean): string => {
if (tabName === 'MainTab') {
return focused ? 'home' : 'home-outline';
}
if (tabName === 'PlaygroundTab') {
return focused ? 'construct' : 'construct-outline';
}
if (tabName === 'SettingsTab') {
return focused ? 'settings' : 'settings-outline';
}

return 'list';
};

0 comments on commit c5c94d1

Please sign in to comment.