Skip to content

Commit

Permalink
refactor(layout): simplify layout components by removing unnecessary …
Browse files Browse the repository at this point in the history
…padding and views
  • Loading branch information
Robert27 committed Dec 6, 2024
1 parent 456a9db commit 7131482
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 118 deletions.
35 changes: 9 additions & 26 deletions src/app/(tabs)/(food)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
import { Stack } from 'expo-router'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { Platform, View } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function FoodStack(): JSX.Element {
const { styles, theme } = useStyles(stylesheet)
const { t } = useTranslation('navigation')
const safeArea = useSafeAreaInsets()
const topInset = safeArea.top
const hasDynamicIsland = Platform.OS === 'ios' && topInset > 50
const paddingTop = hasDynamicIsland ? topInset : 0
return (
<View
style={{
...styles.page,
paddingTop,
<Stack
screenOptions={{
headerShown: true,
headerStyle: styles.headerBackground,
headerTitleStyle: styles.headerTextStyle,
headerTintColor: theme.colors.primary,
contentStyle: styles.background,
title: t('navigation.food'),
}}
>
<Stack
screenOptions={{
headerShown: true,
headerStyle: styles.headerBackground,
headerTitleStyle: styles.headerTextStyle,
headerTintColor: theme.colors.primary,
contentStyle: styles.background,
title: t('navigation.food'),
}}
></Stack>
</View>
></Stack>
)
}

const stylesheet = createStyleSheet((theme) => ({
background: { backgroundColor: theme.colors.background },
headerBackground: { backgroundColor: theme.colors.card },
headerTextStyle: { color: theme.colors.text },
page: {
backgroundColor: theme.colors.card,
flex: 1,
},
}))
38 changes: 10 additions & 28 deletions src/app/(tabs)/(index)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ import { router } from 'expo-router'
import Head from 'expo-router/head'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Dimensions, LayoutAnimation, Platform, View } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { Dimensions, LayoutAnimation, View } from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function HomeRootScreen(): JSX.Element {
const [isPageOpen, setIsPageOpen] = useState(false)
const { styles } = useStyles(stylesheet)
const safeArea = useSafeAreaInsets()
const topInset = safeArea.top
const hasDynamicIsland = Platform.OS === 'ios' && topInset > 50
const paddingTop = hasDynamicIsland ? topInset : 0
useEffect(() => {
setIsPageOpen(true)
}, [])
Expand All @@ -37,22 +31,15 @@ export default function HomeRootScreen(): JSX.Element {
<meta property="expo:spotlight" content="true" />
</Head>

<View
style={{
...styles.header,
paddingTop,
}}
>
<WorkaroundStack
name={'dashboard'}
titleKey={'navigation.dashboard'}
component={isPageOpen ? HomeScreen : () => <></>}
largeTitle={true}
transparent={!hasDynamicIsland}
headerRightElement={IndexHeaderRight}
androidFallback
/>
</View>
<WorkaroundStack
name={'dashboard'}
titleKey={'navigation.dashboard'}
component={isPageOpen ? HomeScreen : () => <></>}
largeTitle={true}
transparent={true}
headerRightElement={IndexHeaderRight}
androidFallback
/>
</>
)
}
Expand Down Expand Up @@ -158,11 +145,6 @@ const stylesheet = createStyleSheet((theme) => ({
paddingTop: 6,
},
errorContainer: { flex: 1, paddingTop: 110 },

header: {
backgroundColor: theme.colors.card,
flex: 1,
},
item: {
gap: 0,
marginHorizontal: theme.margins.page,
Expand Down
32 changes: 10 additions & 22 deletions src/app/(tabs)/(timetable)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
import { Stack } from 'expo-router'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { Platform, View } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

export default function TimetableStack(): JSX.Element {
const { t } = useTranslation('navigation')
const safeArea = useSafeAreaInsets()
const topInset = safeArea.top
const hasDynamicIsland = Platform.OS === 'ios' && topInset > 50
const paddingTop = hasDynamicIsland ? topInset : 0
const { styles, theme } = useStyles(stylesheet)
return (
<View style={{ ...styles.page, paddingTop }}>
<Stack
screenOptions={{
headerShown: true,
title: t('navigation.timetable'),
headerStyle: styles.headerBackground,
headerTitleStyle: styles.headerTextStyle,
headerTintColor: theme.colors.primary,
contentStyle: styles.background,
}}
></Stack>
</View>
<Stack
screenOptions={{
headerShown: true,
title: t('navigation.timetable'),
headerStyle: styles.headerBackground,
headerTitleStyle: styles.headerTextStyle,
headerTintColor: theme.colors.primary,
contentStyle: styles.background,
}}
></Stack>
)
}

const stylesheet = createStyleSheet((theme) => ({
background: { backgroundColor: theme.colors.background },
headerBackground: { backgroundColor: theme.colors.card },
headerTextStyle: { color: theme.colors.text },
page: {
backgroundColor: theme.colors.card,
flex: 1,
},
}))
13 changes: 2 additions & 11 deletions src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function RootLayout(): JSX.Element {
subscription.remove()
}
}, [])
const { styles, theme } = useStyles(stylesheet)
const { styles } = useStyles(stylesheet)
return (
<>
<Head>
Expand All @@ -108,14 +108,7 @@ function RootLayout(): JSX.Element {
}
/>
)}
<Stack
screenOptions={{
contentStyle: styles.background,
headerStyle: styles.headerBackground,
headerTintColor: theme.colors.primary,
headerTitleStyle: styles.headerTextStyle,
}}
>
<Stack>
<Stack.Screen
name="(tabs)"
options={{
Expand Down Expand Up @@ -454,7 +447,5 @@ const ProviderComponent = (): JSX.Element => {

export default ProviderComponent
const stylesheet = createStyleSheet((theme) => ({
background: { backgroundColor: theme.colors.background },
headerBackground: { backgroundColor: theme.colors.card },
headerTextStyle: { color: theme.colors.text },
}))
33 changes: 4 additions & 29 deletions src/components/Layout/DefaultTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import PlatformIcon from '@/components/Universal/Icon'
import { BlurView } from 'expo-blur'
import { Tabs } from 'expo-router'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { Platform } from 'react-native'
import {
UnistylesRuntime,
createStyleSheet,
useStyles,
} from 'react-native-unistyles'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

const DefaultTabs = (): JSX.Element => {
const { styles, theme: styleTheme } = useStyles(stylesheet)
const { t } = useTranslation('navigation')
const BlurTab = (): JSX.Element => (
<BlurView
tint={UnistylesRuntime.themeName === 'dark' ? 'dark' : 'light'}
intensity={75}
style={styles.blurTab}
/>
)

return (
<>
Expand Down Expand Up @@ -54,9 +42,7 @@ const DefaultTabs = (): JSX.Element => {
/>
),

tabBarStyle: styles.tabbarStyle(true),
tabBarBackground: () =>
Platform.OS === 'ios' ? <BlurTab /> : null,
tabBarStyle: styles.tabbarStyle(false),
}}
/>

Expand All @@ -81,9 +67,7 @@ const DefaultTabs = (): JSX.Element => {
}}
/>
),
tabBarStyle: styles.tabbarStyle(true),
tabBarBackground: () =>
Platform.OS === 'ios' ? <BlurTab /> : null,
tabBarStyle: styles.tabbarStyle(false),
}}
/>

Expand Down Expand Up @@ -133,9 +117,7 @@ const DefaultTabs = (): JSX.Element => {
/>
),

tabBarStyle: styles.tabbarStyle(true),
tabBarBackground: () =>
Platform.OS === 'ios' ? <BlurTab /> : null,
tabBarStyle: styles.tabbarStyle(false),
}}
/>
</Tabs>
Expand All @@ -144,13 +126,6 @@ const DefaultTabs = (): JSX.Element => {
}

const stylesheet = createStyleSheet((theme) => ({
blurTab: {
bottom: 0,
left: 0,
position: 'absolute',
right: 0,
top: 0,
},
tabbarStyle: (blur: boolean) => ({
borderTopColor: theme.colors.border,
backgroundColor: blur
Expand Down
12 changes: 10 additions & 2 deletions src/components/Universal/WorkaroundStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { createStackNavigator } from '@react-navigation/stack'
import React, { type ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import { Platform } from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'
import {
UnistylesRuntime,
createStyleSheet,
useStyles,
} from 'react-native-unistyles'

export interface WorkaroundStackProps {
name: string
Expand Down Expand Up @@ -33,6 +37,7 @@ function WorkaroundStack({
name,
titleKey,
component,
transparent = false,
largeTitle = false,
headerRightElement = undefined,
headerSearchBarOptions = undefined,
Expand Down Expand Up @@ -82,13 +87,16 @@ function WorkaroundStack({
headerLargeTitle: Platform.OS === 'ios' && largeTitle,
headerRight: headerRightElement,
headerLargeStyle: styles.headerBackground,
headerStyle: styles.headerBackground,
headerStyle: undefined,
headerSearchBarOptions,
headerTintColor: theme.colors.primary,
contentStyle: styles.background,
headerTitleStyle: {
color: theme.colors.text,
},
headerShadowVisible: transparent,
headerTransparent: true,
headerBlurEffect: UnistylesRuntime.themeName,
}}
component={component}
initialParams={params}
Expand Down

0 comments on commit 7131482

Please sign in to comment.