🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-native-safe-area-view

Package Overview
Dependencies
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-safe-area-view

JS only version of SafeAreaView for supporting iPhone X safe area insets.

0.14.9
legacy
Source
npm
Version published
Weekly downloads
98K
1.41%
Maintainers
3
Weekly downloads
 
Created
Source

react-native-safe-area-view

This is a JS-only version of React Native's SafeAreaView, it adds a small api that makes SafeAreaView more flexible for complex UIs.

Installation

npm install react-native-safe-area-view

Usage

Wrap components that touch any edge of the screen with SafeAreaView.

<SafeAreaView>
  <View>
    <Text>Look, I'm safe!</Text>
  </View>
</SafeAreaView>

Get height of a specific side from the SafeArea.

...
const { width, height } = Dimensions.get('window');
import { getInset } from 'react-native-safe-area-view';

const landScape = width > height;
const bottomPadding = getInset('bottom', landScape);

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.

With HOC

Sometimes you would prefer to use a higher-order component to wrap components.

withSafeArea()(Component);

// Or with forceInset props
withSafeArea({ top: 'always' })(Component);

Keywords

react-native

FAQs

Package last updated on 07 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts