question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to measure header height?

See original GitHub issue

I implement padding to KeyboardAvoidingView. In react-navigation I could get header height through useHeaderHeight hook.

import { useHeaderHeight } from '@react-navigation/stack';

// ...

const headerHeight = useHeaderHeight();

Could you mind share ideas to measure that header height?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
msvargascommented, Apr 10, 2020

Hi, I use useSafeArea and add value for default platform:

import * as React from 'react';
import { KeyboardAvoidingView, KeyboardAvoidingViewProps } from 'react-native';
import { useSafeArea } from 'react-native-safe-area-view';

type Props = KeyboardAvoidingViewProps & {
  children: React.ReactNode;
  extraOffset?: number;
};
const isIOS = Platform.OS == 'ios'
const HEADER_HEIGHT = Platform.OS === 'ios' ? 44 : 56;

const KeyboardAvoiding: React.FC<Props> = React.memo(({ children, extraOffset, ...rest }: Props) => {
  const insets = useSafeArea();

  return (
    <KeyboardAvoidingView
      keyboardVerticalOffset={insets.top + HEADER_HEIGHT + (extraOffset as number)}
      behavior={isIOS ? 'padding' : undefined}
      enabled
      {...rest}
    >
      {children}
    </KeyboardAvoidingView>
  );
});

KeyboardAvoiding.displayName = 'KeyboardAvoiding';
KeyboardAvoiding.defaultProps = {
  extraOffset: 0,
};

export default KeyboardAvoiding;

This works with headerLargeTitle=true ??, and what extraOffset is I don’t understand that part , if you could help me please thanks!!!

Not working with headerLargeTitle, and extraOffset working with tabs or others components with you add

2reactions
WoLewickicommented, Aug 12, 2020

I think the best way to do it is to use react-native-safe-area-context. On iOS, it should always be safeArea.top + 96 for large header and safeArea.top + 44 for small header. Does it solve your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule of Thumb for Sizing Headers - JLC Online
It went like this: Measure the span in feet and add 2 to that number. The sum will be the height of your...
Read more >
How to Size a Header in My House - Hunker
Figure out the type of header you'll need. If you are creating an opening no wider than 4 feet, for a door or...
Read more >
How to Determine Header Size in Construction - eHow
Look at a beam matrix, if you have engineering calculations indicating how much strength you need for a specific header. Custom lumber and...
Read more >
How to calculate the height of a header in <body> tag?
If you don't have time to learn JavaScript the easiest the thing to do is to give the header a fixed height. Than...
Read more >
How to measure header size? - CorvetteForum
How to measure header size ? ... I hate to sound obvious, but measure the diameter of the pipe. ... Find a straight...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found