14c880123c
Expo app with dashboard, time clock, invoices, and settings — native tabs, glass UI, theme-aware components, and iOS Live Activities. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { Platform, useWindowDimensions } from "react-native";
|
|
import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context";
|
|
|
|
import { spacing } from "@/constants/theme";
|
|
|
|
/** Standard UITabBar content height (home indicator is separate). */
|
|
const IOS_TAB_BAR_HEIGHT = 49;
|
|
|
|
/** Slightly less than measured inset so content sits closer to the tab bar. */
|
|
const TAB_BAR_PADDING_TRIM = spacing.sm;
|
|
|
|
/**
|
|
* Pixels between the bottom of the safe-area layout frame and the window bottom.
|
|
*/
|
|
function useBelowLayoutFrame(): number {
|
|
const { height: windowHeight } = useWindowDimensions();
|
|
const frame = useSafeAreaFrame();
|
|
|
|
return Math.max(0, windowHeight - frame.y - frame.height);
|
|
}
|
|
|
|
/** Native tab bar height excluding the home-indicator inset. */
|
|
export function useNativeTabBarHeight(): number {
|
|
const belowLayoutFrame = useBelowLayoutFrame();
|
|
const { bottom: homeIndicator } = useSafeAreaInsets();
|
|
const measured = Math.max(0, belowLayoutFrame - homeIndicator);
|
|
|
|
if (measured > 0) return measured;
|
|
return Platform.OS === "ios" ? IOS_TAB_BAR_HEIGHT : 0;
|
|
}
|
|
|
|
/**
|
|
* Bottom padding so scroll content can clear the floating native tab bar.
|
|
* Uses layout-frame measurement when available, otherwise tab bar + home indicator.
|
|
*/
|
|
export function useTabBarScrollPadding(): number {
|
|
const belowLayoutFrame = useBelowLayoutFrame();
|
|
const { bottom: homeIndicator } = useSafeAreaInsets();
|
|
const tabBar = useNativeTabBarHeight();
|
|
|
|
const raw =
|
|
belowLayoutFrame > 0 ? belowLayoutFrame : tabBar + homeIndicator;
|
|
|
|
return Math.max(tabBar + homeIndicator - TAB_BAR_PADDING_TRIM, raw - TAB_BAR_PADDING_TRIM);
|
|
}
|
|
|
|
/** @deprecated Use useTabBarScrollPadding */
|
|
export function useTabBarInset() {
|
|
return useTabBarScrollPadding();
|
|
}
|