Skip to content

Commit

Permalink
Merge pull request #202 from thornbill/add-tab-labels-setting
Browse files Browse the repository at this point in the history
Add setting to toggle tab labels
  • Loading branch information
thornbill authored Jan 2, 2021
2 parents e6cb203 + 322e9eb commit a07c07d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"version": "Version: {{version}}",
"keepAwake": "Keep Screen Awake",
"rotationLock": "Rotation Lock",
"tabLabels": "Show Tab Labels",
"expoVersion": "Expo Version: {{version}}"
},
"links": {
Expand Down
10 changes: 9 additions & 1 deletion navigation/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import React, { useContext, useEffect } from 'react';
import { ThemeContext } from 'react-native-elements';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import {
NavigationContainer,
getFocusedRouteNameFromRoute,
Expand Down Expand Up @@ -78,16 +79,23 @@ const Home = observer(() => {
});

const Main = observer(() => {
const { rootStore } = useStores();
const insets = useSafeAreaInsets();
const { t } = useTranslation();
const { theme } = useContext(ThemeContext);

// Use a smaller height for the tab bar when labels are disabled
const tabBarStyle = !rootStore.settingStore.isTabLabelsEnabled ? { height: insets.bottom + 28 } : {};

return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ color, size }) => TabIcon(route.name, color, size)
})}
tabBarOptions={{
inactiveTintColor: theme.colors.grey1
inactiveTintColor: theme.colors.grey1,
showLabel: rootStore.settingStore.isTabLabelsEnabled,
style: tabBarStyle
}}
>
<Tab.Screen
Expand Down
7 changes: 7 additions & 0 deletions screens/SettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ const SettingsScreen = observer(() => {
});
}

settingsData.push({
key: 'tab-labels-switch',
title: t('settings.tabLabels'),
value: rootStore.settingStore.isTabLabelsEnabled,
onValueChange: action(value => rootStore.settingStore.isTabLabelsEnabled = value)
});

return [
{
title: t('headings.servers'),
Expand Down
7 changes: 7 additions & 0 deletions stores/SettingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ export default class SettingStore {
*/
isScreenLockEnabled = Platform.OS === 'ios' ? (parseInt(Platform.Version, 10) < 14) : true

/**
* Are tab labels enabled
*/
isTabLabelsEnabled = true

reset() {
this.activeServer = 0;
this.isRotationLockEnabled = Platform.OS === 'ios' && !Platform.isPad;
this.isScreenLockEnabled = Platform.OS === 'ios' ? (parseInt(Platform.Version, 10) < 14) : true;
this.isTabLabelsEnabled = true;
}
}

decorate(SettingStore, {
activeServer: observable,
isRotationLockEnabled: observable,
isScreenLockEnabled: observable,
isTabLabelsEnabled: observable,
reset: action
});

0 comments on commit a07c07d

Please sign in to comment.