• This repository has been archived on 30/Jan/2021
  • Stars
    star
    660
  • Rank 68,297 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚠️ Deprecated: use the successor react-native-safe-area-context instead!

react-native-safe-area-view

⚠️ This library is deprecated. It is no longer used in React Navigation and it has been succeeded by the excellent react-native-safe-area-context. Please use react-native-safe-area-context instead, or you are likely to have a bad time.


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

Installation

💡 The latest release is currently marked as 1.1.1 and depends on react-native-safe-area-context@^0.7.3. To use react-native-safe-area-context@^1.0.0, you will need to install [email protected] - this currently has the next tag on npm.

In the Expo managed workflow:

expo install react-native-safe-area-view react-native-safe-area-context

In bare React Native projects:

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

Next, you need to link react-native-safe-area-context. If you are using autolinking, run npx pod-install again. If not, follow these instructions. Then re-build your app binary.

Usage

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

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.

More Repositories

1

react-navigation

Routing and navigation for your React Native apps
TypeScript
23,453
star
2

hooks

React hooks for convenient react-navigation use
TypeScript
576
star
3

navigation-ex

Routing and navigation for your React Native apps
TypeScript
494
star
4

stack

Stack navigator for React Navigation
TypeScript
391
star
5

tabs

Tab navigators for React Navigation
TypeScript
327
star
6

react-navigation.github.io

Home of the documentation and other miscellanea
JavaScript
311
star
7

redux-helpers

Redux middleware and utils for React Navigation
JavaScript
295
star
8

material-bottom-tabs

A Material Design bottom tab navigator for React Navigation
TypeScript
174
star
9

animated-switch

A switch navigator but with transitions between screens powered by the react-native-reanimated Transitions API
TypeScript
159
star
10

drawer

Drawer navigator for React Navigation
TypeScript
144
star
11

search-layout

A basic search screen layout for usage with React Navigation.
JavaScript
125
star
12

web

Tools for react-navigation on web browsers and servers
JavaScript
95
star
13

rfcs

RFCs for changes to React Navigation
88
star
14

experimental-transitioner

A navigator for custom screen transitions with React Navigation and React Native
JavaScript
73
star
15

deep-linking-example

Example of usage of deep linking for blog post in React Navigation
TypeScript
67
star
16

core

Core utilities for the react-navigation framework shared between the native and web implementations.
JavaScript
62
star
17

native

React Native support for React Navigation. You probably don't need to use this directly, it's included in the react-navigation package.
JavaScript
46
star
18

web-server-example

Example for react-navigation and server-side rendering
JavaScript
44
star
19

create-react-app-example

Example create-react-app using react navigation
JavaScript
38
star
20

reanimated-stacks

TypeScript
21
star
21

boilerplate

Boilerplate app using React Navigation
TypeScript
13
star
22

theme-example

An example project with themes
Objective-C
12
star
23

ci-webhook

JavaScript
3
star
24

check-versions-action

Check for missing or outdated versions of packages mentioned in the issue
JavaScript
3
star
25

bot

A GitHub bot for react-navigation issues (currently unused)
JavaScript
2
star
26

deprecated-tab-navigator

Don't use this unless you have to. You will know if you have to
JavaScript
2
star
27

react-navigation-4

Code of React Navigation 4 for archiving
TypeScript
1
star