4.9.0 • Published 20 days ago

react-native-safe-area-context v4.9.0

Weekly downloads
344,849
License
MIT
Repository
github
Last release
20 days ago

react-native-safe-area-context

npm CI Supports Android, iOS and web MIT License

A flexible way to handle safe area, also works on Android and Web!

Getting started

Install the library using either Yarn:

yarn add react-native-safe-area-context

or npm:

npm install --save react-native-safe-area-context

You then need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:

react-native link react-native-safe-area-context

If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):

Either follow the instructions in the React Native documentation to manually link the framework or link using Cocoapods by adding this to your Podfile:

pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'

Make the following changes:

android/settings.gradle

include ':react-native-safe-area-context'
project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')

android/app/build.gradle

dependencies {
   ...
   implementation project(':react-native-safe-area-context')
}

android/app/src/main/.../MainApplication.java

On top, where imports are:

import com.th3rdwave.safeareacontext.SafeAreaContextPackage;

Add the SafeAreaContextPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.asList(
            new MainReactPackage(),
            ...
            new SafeAreaContextPackage()
    );
}

Usage

Add SafeAreaProvider in your app root component:

import { SafeAreaProvider } from 'react-native-safe-area-context';

function App() {
  return <SafeAreaProvider>...</SafeAreaProvider>;
}

Usage with hooks api:

import { useSafeArea } from 'react-native-safe-area-context';

function HookComponent() {
  const insets = useSafeArea();

  return <View style={{ paddingTop: insets.top }} />;
}

Usage with consumer api:

import { SafeAreaConsumer } from 'react-native-safe-area-context';

class ClassComponent extends React.Component {
  render() {
    return (
      <SafeAreaConsumer>
        {insets => <View style={{ paddingTop: insets.top }} />}
      </SafeAreaConsumer>
    );
  }
}

Usage with SafeAreaView:

import { SafeAreaView } from 'react-native-safe-area-context';

function SomeComponent() {
  return (
    <SafeAreaView>
      <View />
    </SafeAreaView>
  );
}

Web SSR

If you are doing server side rendering on the web you can use initialSafeAreaInsets to inject insets value based on the device the user has, or simply pass zero values. Since insets measurement is async it will break rendering your page content otherwise.

Optimization

To speed up the initial render, you can import initialWindowSafeAreaInsets from this package and set as the initialSafeAreaInsets prop on the provider as described in Web SSR. You cannot do this if your provider remounts, or you are using react-native-navigation.

import {
  SafeAreaProvider,
  initialWindowSafeAreaInsets
} from 'react-native-safe-area-context';

function App() {
  return (
    <SafeAreaProvider initialSafeAreaInsets={initialWindowSafeAreaInsets}>
      ...
    </SafeAreaProvider>
  );
}

Resources

whitedarkcomponent-library-template2@neur0base/app-sdk@borderfreefinancial/revoshowmobileui-test@borderfreefinancial/revoshowui-test@haris523/expo-starter-template@applicaster/quick-brick-core@thirdweb-dev/react-nativereact-native-lib-gareact-native-sdafpeakcomponentspeak-custom-componentsuc-browserassociacao-digital-completeassociacao-digital-widgetslashbracket-custom-expo-bare-templatereact-native-login-drawer-templatereact-native-payment-integratereact-native-payment1react-native-paymentpackagereact-native-payment_integrationtw-reactnativetemplatereact-native-twitter-clonehipposdkfirebase-expo-templatebestbet55@snooper/coregenesyschatpluginsommario-appcustomsreactnativecode-avenue-design-systemspiktor-profile-trial-v3profile-piktorprofile-piktor-v3testdemo007testdemo008react-native-template-workflowreact-native-template-rfbasecomic-packagesharpsports-mobile-linkreact-native-template-herbertdesousasemantic-ui-react-nativemhk-solidreact-native-diario-republica-modulern-diario-republica-modulei-invest-wealthsezzle-apploggin-appcultgearreact-native-holper-storybookreact-native-tc-conversations-testgenesyschatsdkvtex.loginreact-native-uni-componentsreact-native-queue-online-sdk@bravemaster619/interview-uipublishtestformeinreactnativewebtestcomponent@toansajxuko/wowpay-react-native-sdkwowpay_react_nativeexpo-template-nativebaseexpo-template-nativebase-typescriptolx-mallreact-native-twilio-video-callkitreact-native-twilio-video-testreact-native-video-call-v1iusify-module-codigos_ptiusify-module-diario-republicaiusify-module-iuslexmira-test-3tinh-mirareact-native-isw-starter@code503/sds-react-native-componentshotqa-sdkreact-native-wocode-frameworkairasia1222expo-bare-templatemomo-component-kitsrework-nativeexpo-template-stack-navigatorexpo-template-bottom-navigatorairmoddictionarymacmillaninterpro-calendar@pab-source/mobile-p2pubi-test-ui-rcjitsi-meet-rndice-uireact-native-jitsi-meet-libenmeshnativecore-native-boilerplatebert-component-librarygkashpaysdk1ki-smart-base-rnraodaor-appraodaor-app-poetryraodaor-app1wowpay-reactnative-sdkcorbeappragu-react-native-form-updatereact-native-trust-sdk-mobile
4.10.0-rc.1

20 days ago

4.10.0-rc.0

30 days ago

4.9.0

2 months ago

4.8.2

3 months ago

4.8.1

4 months ago

4.8.0

4 months ago

4.7.4

5 months ago

4.7.3

5 months ago

4.8.0-rc.0

4 months ago

4.5.4

9 months ago

4.5.5

9 months ago

4.7.0

9 months ago

4.7.2

7 months ago

4.7.1

9 months ago

4.6.1

9 months ago

4.6.0

9 months ago

4.6.3

9 months ago

4.6.2

9 months ago

4.6.4

9 months ago

4.5.3

11 months ago

4.5.0

1 year ago

4.5.2

11 months ago

4.5.1

12 months ago

4.4.1

2 years ago

4.4.0

2 years ago

4.3.4

2 years ago

4.3.2

2 years ago

4.3.1

2 years ago

4.3.3

2 years ago

4.3.0

2 years ago

4.2.5

2 years ago

4.2.3

2 years ago

4.2.2

2 years ago

4.2.4

2 years ago

4.2.1

2 years ago

4.2.0

2 years ago

4.1.4

2 years ago

4.1.3

2 years ago

4.0.2

2 years ago

4.1.0

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

3.4.0

2 years ago

4.0.1-rc.0

2 years ago

3.4.1

2 years ago

4.0.1-rc.5

2 years ago

4.0.1-rc.2

2 years ago

4.0.1-rc.1

2 years ago

4.0.1-rc.4

2 years ago

4.0.1-rc.3

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.3.2

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.9

3 years ago

3.1.8

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.0-beta.1

4 years ago

3.1.0-beta.0

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.0-beta.3

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-beta.1

4 years ago

3.0.0-beta.2

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

2.0.0-beta.1

4 years ago

2.0.0-beta.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago

1.0.0-beta.0

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.3

4 years ago

0.6.4

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago