React Navigation get stack header height

Avery235 picture Avery235 · Aug 17, 2017 · Viewed 21k times · Source

How do i get the height of the StackNavigator header programmatically?

I need to detect if component A's position is within component B when pan gesture (drag) on A is released. However, the position from onPanResponderRelease's gesture.moveY is measured with respect to the entire screen, whereas the position returned from A's onLayoutis measured with respect to the parent view. So i'd need to know the parent view's current height to reconcile the differences.

Answer

Florent Roques picture Florent Roques · Sep 4, 2017

React navigation V5

import { useHeaderHeight } from '@react-navigation/stack';
const headerHeight = useHeaderHeight();

or with React Context's API (not recommended)

React navigation V4

import { Header } from 'react-navigation-stack';
const headerHeight = Header.HEIGHT;

React navigation V2-V3

import { Header } from 'react-navigation';
const headerHeight = Header.HEIGHT;

Another answer to this problem