1.1.1 • Published 4 years ago

react-native-safe-area-view v1.1.1

Weekly downloads
224,032
License
MIT
Repository
github
Last release
4 years ago

react-native-safe-area-view

You are reading the README for 1.0.0-alpha! Unless you intend to be here, you should probably just read the README from the master branch

This library provides automatic padding when a view intersects with a safe area (notch, status bar, home indicator).

Installation

yarn add react-native-safe-area-view react-native-safe-area-context

# or if you use npm
npm install react-native-safe-area-view react-native-safe-area-context

If you are using the Expo >= SDK 35, you are done!

If you have a bare React Native project, you need to link react-native-safe-area-context. If you are using autolinking, just run pod install again. If not, follow these instructions.

Usage

First you need to wrap the root of your app with the SafeAreaProvider.

Note: If you are using react-navigation@>=4 this will be done for you you do not need to add the SafeAreaProvider in that case.

import * as React from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import MyAwesomeApp from './src/MyAwesomeApp';

export default function App() {
  return (
    <SafeAreaProvider>
      <MyAwesomeApp />
    </SafeAreaProvider>
  );
}

Now you can wrap components that touch any edge of the screen with a SafeAreaView.

import SafeAreaView from 'react-native-safe-area-view';

export default function MyAwesomeApp() {
  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flex: 1 }}>
        <Text>
          Look, I'm safe! Not under a status bar or notch or home indicator or
          anything! Very cool
        </Text>
      </View>
    </SafeAreaView>
  );
}

forceInset

Sometimes you will observe unexpected behavior and jank because SafeAreaView uses onLayout then calls measureInWindow on the view. If you know your view will touch certain edges, use forceInset to force it to apply the inset padding on the view.

<SafeAreaView forceInset={{ top: 'always' }}>
  <View>
    <Text>Yeah, I'm safe too!</Text>
  </View>
</SafeAreaView>

forceInset takes an object with the keys top | bottom | left | right | vertical | horizontal and the values 'always' | 'never'. Or you can override the padding altogether by passing an integer.

Accessing safe area inset values

Sometimes it's useful to know what the insets are for the top, right, bottom, and left of the screen. See the documentation for react-native-safe-area-context for more information.

@invoice-simple/react-navigationuc-browserreact-navigation-tabs-k4react-native-react-native-uireact-native-country-picker-modal-with-testidddt-react-nativeenmeshnativebert-component-libraryraodaor-appraodaor-app-poetryraodaor-app1@react-navigation/react-navigation-experimentalreact-native-trust-sdk-mobilewilscanner@infinitebrahmanuniverse/nolb-react-native-sa@everything-registry/sub-chunk-2590@andyto/react-native-country-picker-modal@dfeidao/fd-m000021@bibletags/bibletags-react-native-app@brighte/react-native-paper@getdemos/react-native-ant-designsalespalzy-react-navigationwhitetown-uizh-react-navigationthornus-react-native-country-picker-modalzoom-image-viewersmartspace-react-navigationsm-react-native-templatessw-react-native-country-picker-modalrn-hero-designrn-inspection-navigationrn_bottom_animationrn-country-picker-modal@choose/react-navigation-tabs@hoangnguyen1247/react-native-paper@heytea/taro-router-rn@iammattburns/react-native-activity-feed-core@app2one/react-native-country-picker-modal@apzelos/react-native-activity-feed-core@foreword/react-native-paper@fentest/comps@jstarmx/react-navigation-tabs@kiwicom/account-native@kiwicom/account-web@kodefox/react-native-paper@kmart/design@jemmyphan/react-navigation@lytrax/react-navigation-tabs@mobilecards/mobilecards-react-native-country-picker-modal-master@jafri/react-native-paper@zhigang1992/react-native-paperexpo-multiple-media-imagepickernativewind-startermobilecards-react-native-country-picker-modalmobilecards-react-native-country-picker-modal-v2@sishuguojixuefu/antd-mobile-rn@swdenglian/antd-react-native@unpourtous/react-navigationforceclouds-react-navigation@yoeven/react-native-modular-datetime-picker@tuyaworks/tpl-docs-demoebuy-mobile-dev@propulse/navigation-view-ios@propulse/sheet-modals-ios@pandarose/react-native-paper@reactseals/renative-template-chat@sigmadigital/react-native-paper@thenetcircle/react-navigation@rotarsebastian/react-navigation-tabs@spring-mobility/react-native-paper@starling-tech/react-navigation-tabs@zalastax/nolb-react-native-sagefen-loggerhero-design-rnhuangge-react-navigationproductmodule-bncitizenship_app_newsinspire-ignitecollegekonnectreact-native-activity-anantreact-native-activity-feed-corereact-native-activity-feed-core-mbrakshit-react-native-paperreact-archive-navigationreact-native-country-picker-modal_forkreact-native-country-picker-modal2react-native-dynamic-formsreact-native-gender-picker-modalreact-native-onboarding-safeview-swiperreact-native-paper-lightreact-native-paper-dark-theme-fixreact-native-navigation-cusreact-native-awesome-date-time-pickerreact-native-base-typescript-hungtruongreact-native-material-backdropreact-native-livelo-componentsreact-native-material-bottom-tabs-navigationreact-native-simple-instagramreact-native-radio-trimmer
2.0.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

0.14.9

4 years ago

1.0.0

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

0.14.8

5 years ago

1.0.0-alpha.0

5 years ago

0.14.7

5 years ago

0.14.6

5 years ago

0.14.5

5 years ago

0.14.4

5 years ago

0.14.3

5 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.2

5 years ago

0.13.1

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago