Skip to content

Commit 1c0aac4

Browse files
committed
refactor(layout): extract IOS_TAB_BAR_HEIGHT to shared constants
- Create constants/layout.ts with IOS_TAB_BAR_HEIGHT constant - Add getTabBarScrollPadding() helper function for common scroll padding pattern - Update profile.tsx, tasks.tsx, and steps/[id].tsx to use shared constant - Eliminates duplicate constant definitions across three files
1 parent 52b0e6f commit 1c0aac4

4 files changed

Lines changed: 38 additions & 23 deletions

File tree

app/(tabs)/profile.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ import { logger, LogCategory } from '@/lib/logger';
3434
import { formatDateWithTimezone, parseDateAsLocal, getUserTimezone } from '@/lib/date';
3535
import SettingsSheet, { SettingsSheetRef } from '@/components/SettingsSheet';
3636
import LogSlipUpSheet, { LogSlipUpSheetRef } from '@/components/sheets/LogSlipUpSheet';
37-
38-
// =============================================================================
39-
// Constants
40-
// =============================================================================
41-
42-
/** Standard iOS tab bar height (49pt) - used for scroll padding */
43-
const IOS_TAB_BAR_HEIGHT = 49;
37+
import { getTabBarScrollPadding } from '@/constants/layout';
4438

4539
// =============================================================================
4640
// Helper Components
@@ -173,7 +167,7 @@ export default function ProfileScreen() {
173167
// Get safe area insets for scroll padding
174168
const insets = useSafeAreaInsets();
175169
// Account for native tab bar height on iOS
176-
const scrollPadding = Platform.OS === 'ios' ? insets.bottom + IOS_TAB_BAR_HEIGHT + 16 : 16;
170+
const scrollPadding = getTabBarScrollPadding(insets.bottom);
177171
const settingsSheetRef = useRef<SettingsSheetRef>(null);
178172
const logSlipUpSheetRef = useRef<LogSlipUpSheetRef>(null);
179173
const scrollViewRef = useRef<ScrollView>(null);

app/(tabs)/steps/[id].tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ import { supabase } from '@/lib/supabase';
2020
import { StepContent, UserStepProgress } from '@/types/database';
2121
import { logger, LogCategory } from '@/lib/logger';
2222
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
23-
24-
// =============================================================================
25-
// Constants
26-
// =============================================================================
27-
28-
/** Standard iOS tab bar height (49pt) - used for footer padding when nested in tabs */
29-
const IOS_TAB_BAR_HEIGHT = 49;
23+
import { getTabBarScrollPadding } from '@/constants/layout';
3024

3125
// =============================================================================
3226
// Component
@@ -486,7 +480,7 @@ const createStyles = (theme: ThemeColors, insets: { top: number; bottom: number
486480
},
487481
bottomPadding: {
488482
// Account for native tab bar height plus safe area so content isn't hidden
489-
height: Platform.OS === 'ios' ? insets.bottom + IOS_TAB_BAR_HEIGHT + 16 : 24,
483+
height: getTabBarScrollPadding(insets.bottom, Platform.OS === 'ios' ? 16 : 24),
490484
},
491485
navigation: {
492486
flexDirection: 'row',

app/(tabs)/tasks.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ import { formatProfileName } from '@/lib/format';
2828
import { logger, LogCategory } from '@/lib/logger';
2929
import { parseDateAsLocal } from '@/lib/date';
3030
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
31-
32-
// =============================================================================
33-
// Constants
34-
// =============================================================================
35-
36-
/** Standard iOS tab bar height (49pt) - used for FAB positioning */
37-
const IOS_TAB_BAR_HEIGHT = 49;
31+
import { IOS_TAB_BAR_HEIGHT } from '@/constants/layout';
3832

3933
// =============================================================================
4034
// Types & Interfaces

constants/layout.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// =============================================================================
2+
// Layout Constants
3+
// =============================================================================
4+
// Shared layout constants used across the app for consistent spacing and sizing
5+
6+
import { Platform } from 'react-native';
7+
8+
/**
9+
* Default iOS tab bar height in points.
10+
* Used to calculate safe scroll padding when content appears above the tab bar.
11+
*
12+
* @remarks
13+
* This value matches the standard UITabBar height (49pt) on iOS.
14+
* On Android, the navigation bar height varies and is handled differently.
15+
*/
16+
export const IOS_TAB_BAR_HEIGHT = 49;
17+
18+
/**
19+
* Calculates the bottom padding needed for scrollable content above the tab bar.
20+
*
21+
* @param bottomInset - The bottom safe area inset from useSafeAreaInsets()
22+
* @param extraPadding - Additional padding to add (defaults to 16)
23+
* @returns The calculated padding for iOS, or extraPadding for other platforms
24+
*
25+
* @example
26+
* ```tsx
27+
* const insets = useSafeAreaInsets();
28+
* const paddingBottom = getTabBarScrollPadding(insets.bottom);
29+
* ```
30+
*/
31+
export function getTabBarScrollPadding(bottomInset: number, extraPadding: number = 16): number {
32+
return Platform.OS === 'ios' ? bottomInset + IOS_TAB_BAR_HEIGHT + extraPadding : extraPadding;
33+
}

0 commit comments

Comments
 (0)