React Native package that exposes the Safe Area insets as constants (iOS and Android notch are supported).
$ yarn add react-native-static-safe-area-insets
$ react-native link react-native-static-safe-area-insets
$ cd ios && pod install && cd ..
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-static-safe-area-insets
and addRNStaticSafeAreaInsets.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNStaticSafeAreaInsets.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.gaspardbruno.staticsafeareainsets.RNStaticSafeAreaInsetsPackage;
to the imports at the top of the file - Add
new RNStaticSafeAreaInsetsPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-static-safe-area-insets' project(':react-native-static-safe-area-insets').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-static-safe-area-insets/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-static-safe-area-insets')
import StaticSafeAreaInsets from 'react-native-static-safe-area-insets';
console.log('SafeArea insets top:', StaticSafeAreaInsets.safeAreaInsetsTop)
// SafeArea insets top: 44
console.log('SafeArea insets bottom:', StaticSafeAreaInsets.safeAreaInsetsBottom)
// SafeArea insets bottom: 34
console.log('SafeArea insets left:', StaticSafeAreaInsets.safeAreaInsetsLeft)
// SafeArea insets left: 44
console.log('SafeArea insets right:', StaticSafeAreaInsets.safeAreaInsetsRight)
// SafeArea insets right: 44