├── .watchmanconfig ├── .gitattributes ├── ios ├── .npmignore └── SafeAreaView │ ├── RNCSafeAreaShadowView.h │ ├── RNCSafeAreaViewManager.h │ ├── RNCSafeAreaProviderManager.h │ ├── RNCSafeAreaViewMode.h │ ├── RNCSafeAreaProvider.h │ ├── RNCSafeAreaViewEdges.h │ ├── RNCSafeAreaViewMode.m │ ├── RNCSafeAreaViewLocalData.m │ ├── RNCSafeAreaViewEdges.m │ ├── RCTView+SafeAreaCompat.h │ ├── RNCSafeAreaView.h │ ├── RNCSafeAreaViewLocalData.h │ ├── RNCSafeAreaViewManager.m │ ├── RNCSafeAreaProviderManager.m │ ├── RNCSafeAreaProvider.m │ ├── RCTView+SafeAreaCompat.m │ ├── RNCSafeAreaView.m │ └── RNCSafeAreaShadowView.m ├── src ├── SafeAreaView.macos.tsx ├── SafeAreaView.windows.tsx ├── index.tsx ├── NativeSafeAreaProvider.macos.tsx ├── NativeSafeAreaProvider.windows.tsx ├── InitialWindow.ts ├── SafeAreaView.native.tsx ├── NativeSafeAreaProvider.native.tsx ├── InitialWindow.native.ts ├── __tests__ │ ├── __snapshots__ │ │ ├── SafeAreaView-test.tsx.snap │ │ └── SafeAreaContext-test.tsx.snap │ ├── SafeAreaView-test.tsx │ ├── InitialWindow-test.tsx │ └── SafeAreaContext-test.tsx ├── CompatNativeSafeAreaProvider.tsx ├── SafeArea.types.ts ├── useWindowDimensions.tsx ├── SafeAreaView.tsx ├── NativeSafeAreaProvider.tsx └── SafeAreaContext.tsx ├── .eslintignore ├── .prettierrc ├── example ├── android │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── values-v28 │ │ │ │ │ │ └── styles.xml │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── safeareaviewexample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ └── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── safeareaviewexample │ │ │ │ └── ReactNativeFlipper.java │ │ ├── proguard-rules.pro │ │ ├── build_defs.bzl │ │ ├── _BUCK │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── ios │ ├── SafeAreaViewExample │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── File.swift │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── Info.plist │ │ ├── AppDelegate.m │ │ └── Base.lproj │ │ │ └── LaunchScreen.xib │ ├── SafeAreaViewExample-Bridging-Header.h │ ├── SafeAreaViewExample.xcworkspace │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── contents.xcworkspacedata │ ├── Podfile │ ├── SafeAreaViewExample.xcodeproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── SafeAreaViewExample.xcscheme │ └── Podfile.lock ├── index.expo.js ├── index.js ├── src │ ├── types │ │ └── Navigation.tsx │ ├── components │ │ ├── withProvider.tsx │ │ ├── DataView.tsx │ │ ├── ReactNavigationHomeScreen.tsx │ │ ├── ReactNavigationSettingsScreen.tsx │ │ ├── ReactNavigationDetailScreen.tsx │ │ ├── ReactNavigationModalDetailScreen.tsx │ │ └── SafeAreaViewVisualizer.tsx │ ├── ReactNativeSafeAreaView.tsx │ ├── ReactNavigation4Example.tsx │ ├── ReactNavigation5Example.tsx │ ├── NativeStackExample.tsx │ ├── HooksExample.tsx │ ├── App.tsx │ └── SafeAreaViewExample.tsx ├── app.json ├── package.json └── .gitignore ├── .eslintrc.js ├── react-native.config.js ├── android ├── .npmignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── th3rdwave │ │ └── safeareacontext │ │ ├── SafeAreaViewMode.java │ │ ├── SafeAreaViewEdges.java │ │ ├── Rect.java │ │ ├── EdgeInsets.java │ │ ├── SafeAreaViewLocalData.java │ │ ├── SafeAreaContextPackage.java │ │ ├── InsetsChangeEvent.java │ │ ├── SerializationUtils.java │ │ ├── SafeAreaProvider.java │ │ ├── SafeAreaViewManager.java │ │ ├── SafeAreaProviderManager.java │ │ ├── SafeAreaUtils.java │ │ ├── SafeAreaView.java │ │ └── SafeAreaViewShadowNode.java └── build.gradle ├── babel.config.js ├── tsconfig.json ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── android.yml │ ├── js.yml │ └── ios.yml ├── react-native-safe-area-context.podspec ├── .gitignore ├── jest └── mock.js ├── LICENSE ├── CONTRIBUTING.md ├── package.json └── README.md /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /ios/.npmignore: -------------------------------------------------------------------------------- 1 | */project.xcworkspace/ 2 | */xcuserdata/ 3 | .DS_Store 4 | .npmignore 5 | Pods/ 6 | build/ 7 | -------------------------------------------------------------------------------- /src/SafeAreaView.macos.tsx: -------------------------------------------------------------------------------- 1 | import { View } from 'react-native'; 2 | 3 | export const SafeAreaView = View; 4 | -------------------------------------------------------------------------------- /src/SafeAreaView.windows.tsx: -------------------------------------------------------------------------------- 1 | import { View } from 'react-native'; 2 | 3 | export const SafeAreaView = View; 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | typings 2 | node_modules 3 | example/android-bundle.js 4 | example/ios-bundle.js 5 | 6 | # generated by bob 7 | lib/ 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "bracketSpacing": true, 5 | "jsxBracketSameLine": false 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Hello App Display Name 3 | 4 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@react-native-community'], 3 | rules: { 4 | 'react-native/no-inline-styles': 'off', 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependency: { 3 | platforms: { 4 | macos: null, 5 | windows: null, 6 | }, 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | export * from './SafeAreaContext'; 2 | export * from './SafeAreaView'; 3 | export * from './InitialWindow'; 4 | export * from './SafeArea.types'; 5 | -------------------------------------------------------------------------------- /android/.npmignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .DS_Store 3 | .gradle/ 4 | .idea/ 5 | .npmignore 6 | build/ 7 | gradle/ 8 | gradlew 9 | gradlew.bat 10 | local.properties 11 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | -------------------------------------------------------------------------------- /src/NativeSafeAreaProvider.macos.tsx: -------------------------------------------------------------------------------- 1 | import { CompatNativeSafeAreaProvider } from './CompatNativeSafeAreaProvider'; 2 | 3 | export default CompatNativeSafeAreaProvider; 4 | -------------------------------------------------------------------------------- /example/index.expo.js: -------------------------------------------------------------------------------- 1 | import registerRootComponent from 'expo/build/launch/registerRootComponent'; 2 | 3 | import App from './src/App'; 4 | 5 | registerRootComponent(App); 6 | -------------------------------------------------------------------------------- /src/NativeSafeAreaProvider.windows.tsx: -------------------------------------------------------------------------------- 1 | import { CompatNativeSafeAreaProvider } from './CompatNativeSafeAreaProvider'; 2 | 3 | export default CompatNativeSafeAreaProvider; 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.java: -------------------------------------------------------------------------------- 1 | package com.th3rdwave.safeareacontext; 2 | 3 | public enum SafeAreaViewMode { 4 | PADDING, 5 | MARGIN 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.java: -------------------------------------------------------------------------------- 1 | package com.th3rdwave.safeareacontext; 2 | 3 | public enum SafeAreaViewEdges { 4 | TOP, 5 | RIGHT, 6 | BOTTOM, 7 | LEFT 8 | } 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wordpress-mobile/react-native-safe-area-context/trunk/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaShadowView.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | 5 | @interface RNCSafeAreaShadowView : RCTShadowView 6 | 7 | @end 8 | 9 | NS_ASSUME_NONNULL_END 10 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewManager.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | 5 | @interface RNCSafeAreaViewManager : RCTViewManager 6 | 7 | @end 8 | 9 | NS_ASSUME_NONNULL_END 10 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaProviderManager.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | 5 | @interface RNCSafeAreaProviderManager : RCTViewManager 6 | 7 | @end 8 | 9 | NS_ASSUME_NONNULL_END 10 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewMode.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | typedef NS_ENUM(NSInteger, RNCSafeAreaViewMode) { 4 | RNCSafeAreaViewModePadding, 5 | RNCSafeAreaViewModeMargin, 6 | RNCSafeAreaViewModeBorder, 7 | }; 8 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // SafeAreaViewExample 4 | // 5 | // Created by Janic Duplessis on 2020-05-02. 6 | // Copyright © 2020 Facebook. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | -------------------------------------------------------------------------------- /src/InitialWindow.ts: -------------------------------------------------------------------------------- 1 | import { EdgeInsets, Metrics } from './SafeArea.types'; 2 | 3 | export const initialWindowMetrics: Metrics | null = null; 4 | 5 | /** 6 | * @deprecated 7 | */ 8 | export const initialWindowSafeAreaInsets: EdgeInsets | null = null; 9 | -------------------------------------------------------------------------------- /src/SafeAreaView.native.tsx: -------------------------------------------------------------------------------- 1 | import { requireNativeComponent } from 'react-native'; 2 | import { NativeSafeAreaViewProps } from './SafeArea.types'; 3 | 4 | export const SafeAreaView = 5 | requireNativeComponent('RNCSafeAreaView'); 6 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : UIResponder 5 | 6 | @property (nonatomic, strong) UIWindow *window; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/NativeSafeAreaProvider.native.tsx: -------------------------------------------------------------------------------- 1 | import { requireNativeComponent } from 'react-native'; 2 | import { NativeSafeAreaProviderProps } from './SafeArea.types'; 3 | 4 | export default requireNativeComponent( 5 | 'RNCSafeAreaProvider', 6 | ); 7 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char * argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-v28/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | plugins: [ 4 | [ 5 | 'module-resolver', 6 | { 7 | alias: { 8 | 'react-native-safe-area-context': './src', 9 | }, 10 | }, 11 | ], 12 | ], 13 | }; 14 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaProvider.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import 4 | 5 | NS_ASSUME_NONNULL_BEGIN 6 | 7 | @interface RNCSafeAreaProvider : RCTView 8 | 9 | @property (nonatomic, copy) RCTBubblingEventBlock onInsetsChange; 10 | 11 | @end 12 | 13 | NS_ASSUME_NONNULL_END 14 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/src/types/Navigation.tsx: -------------------------------------------------------------------------------- 1 | import type { StackScreenProps } from '@react-navigation/stack'; 2 | 3 | export type Routes = { 4 | Home: undefined; 5 | Details: undefined; 6 | ModalDetails: undefined; 7 | Settings: undefined; 8 | }; 9 | 10 | export type ScreenProps = StackScreenProps; 11 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/SafeAreaViewExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewEdges.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | typedef NS_ENUM(NSInteger, RNCSafeAreaViewEdges) { 4 | RNCSafeAreaViewEdgesTop = 0b1000, 5 | RNCSafeAreaViewEdgesRight = 0b0100, 6 | RNCSafeAreaViewEdgesBottom = 0b0010, 7 | RNCSafeAreaViewEdgesLeft = 0b0001, 8 | RNCSafeAreaViewEdgesAll = 0b1111, 9 | }; 10 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewMode.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "RNCSafeAreaViewMode.h" 3 | 4 | @implementation RCTConvert (RNCSafeAreaView) 5 | 6 | RCT_MULTI_ENUM_CONVERTER(RNCSafeAreaViewMode, (@{ 7 | @"padding": @(RNCSafeAreaViewModePadding), 8 | @"margin": @(RNCSafeAreaViewModeMargin), 9 | }), RNCSafeAreaViewModePadding, integerValue); 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /example/src/components/withProvider.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { SafeAreaProvider } from 'react-native-safe-area-view'; 3 | 4 | export function withProvider(Component: React.ComponentType) { 5 | return function WrappedScreen(props: T) { 6 | return ( 7 | 8 | 9 | 10 | ); 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewLocalData.m: -------------------------------------------------------------------------------- 1 | #import "RNCSafeAreaViewLocalData.h" 2 | 3 | @implementation RNCSafeAreaViewLocalData 4 | 5 | - (instancetype)initWithInsets:(UIEdgeInsets)insets mode:(RNCSafeAreaViewMode)mode edges:(RNCSafeAreaViewEdges)edges 6 | { 7 | if (self = [super init]) { 8 | _insets = insets; 9 | _mode = mode; 10 | _edges = edges; 11 | } 12 | 13 | return self; 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SafeAreaViewExample", 3 | "displayName": "SafeAreaViewExample", 4 | "expo": { 5 | "entryPoint": "./example/index.expo", 6 | "name": "react-native-safe-area-context", 7 | "slug": "react-native-safe-area-context", 8 | "version": "0.1.0", 9 | "platforms": ["android", "ios", "web"], 10 | "web": { 11 | "display": "fullscreen", 12 | "barStyle": "black-translucent" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewEdges.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "RNCSafeAreaViewEdges.h" 3 | 4 | @implementation RCTConvert (RNCSafeAreaView) 5 | 6 | RCT_MULTI_ENUM_CONVERTER(RNCSafeAreaViewEdges, (@{ 7 | @"top": @(RNCSafeAreaViewEdgesTop), 8 | @"right": @(RNCSafeAreaViewEdgesRight), 9 | @"bottom": @(RNCSafeAreaViewEdgesBottom), 10 | @"left": @(RNCSafeAreaViewEdgesLeft), 11 | }), RNCSafeAreaViewEdgesAll, integerValue); 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RCTView+SafeAreaCompat.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | 5 | RCT_EXTERN BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold); 6 | 7 | NS_ASSUME_NONNULL_BEGIN 8 | 9 | @interface UIView(SafeAreaCompat) 10 | 11 | - (BOOL)nativeSafeAreaSupport; 12 | - (UIEdgeInsets)safeAreaInsetsOrEmulate; 13 | 14 | @end 15 | 16 | NS_ASSUME_NONNULL_END 17 | -------------------------------------------------------------------------------- /example/src/components/DataView.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { Text } from 'react-native'; 3 | 4 | export function DataView({ data }: { data: object | null | undefined }) { 5 | return ( 6 | 7 | {data == null 8 | ? 'null' 9 | : Object.entries(data) 10 | .map(([key, value]) => `${key}: ${value}`) 11 | .join('\n')} 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaView.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | 5 | #import "RNCSafeAreaViewMode.h" 6 | #import "RNCSafeAreaViewEdges.h" 7 | 8 | NS_ASSUME_NONNULL_BEGIN 9 | 10 | @class RNCSafeAreaView; 11 | 12 | @interface RNCSafeAreaView: RCTView 13 | 14 | - (instancetype)initWithBridge:(RCTBridge *)bridge; 15 | 16 | @property (nonatomic, assign) RNCSafeAreaViewMode mode; 17 | @property (nonatomic, assign) RNCSafeAreaViewEdges edges; 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /example/src/ReactNativeSafeAreaView.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { View } from 'react-native'; 3 | import { SafeAreaProvider } from 'react-native-safe-area-context'; 4 | import SafeAreaView from 'react-native-safe-area-view'; 5 | 6 | export default function ReactNativeSafeAreaView() { 7 | return ( 8 | 9 | 10 | 11 | 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "src/**/*.ts", 4 | "src/**/*.tsx", 5 | "example/**/*.ts", 6 | "example/**/*.tsx" 7 | ], 8 | "compilerOptions": { 9 | "target": "es5", 10 | "module": "commonjs", 11 | "strict": true, 12 | "moduleResolution": "node", 13 | "skipLibCheck": true, 14 | "lib": ["dom", "es2015", "es2016", "esnext"], 15 | "jsx": "react-native", 16 | "baseUrl": ".", 17 | "paths": { 18 | "react-native-safe-area-context": ["./src"] 19 | } 20 | }, 21 | "exclude": ["node_modules"] 22 | } 23 | -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewLocalData.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "RNCSafeAreaViewMode.h" 4 | #import "RNCSafeAreaViewEdges.h" 5 | 6 | NS_ASSUME_NONNULL_BEGIN 7 | 8 | @interface RNCSafeAreaViewLocalData : NSObject 9 | 10 | - (instancetype)initWithInsets:(UIEdgeInsets)insets mode:(RNCSafeAreaViewMode)mode edges:(RNCSafeAreaViewEdges)edges; 11 | 12 | @property (atomic, readonly) UIEdgeInsets insets; 13 | @property (atomic, readonly) RNCSafeAreaViewMode mode; 14 | @property (atomic, readonly) RNCSafeAreaViewEdges edges; 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Summary 4 | 5 | 6 | 7 | 8 | ## Test Plan 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/InitialWindow.native.ts: -------------------------------------------------------------------------------- 1 | import { UIManager } from 'react-native'; 2 | import { Metrics } from './SafeArea.types'; 3 | 4 | const RNCSafeAreaProviderConfig = UIManager.getViewManagerConfig( 5 | 'RNCSafeAreaProvider', 6 | ) as any; 7 | 8 | export const initialWindowMetrics = ( 9 | RNCSafeAreaProviderConfig != null && 10 | RNCSafeAreaProviderConfig.Constants != null 11 | ? RNCSafeAreaProviderConfig.Constants.initialWindowMetrics 12 | : null 13 | ) as Metrics | null; 14 | 15 | /** 16 | * @deprecated 17 | */ 18 | export const initialWindowSafeAreaInsets = initialWindowMetrics?.insets; 19 | -------------------------------------------------------------------------------- /android/src/main/java/com/th3rdwave/safeareacontext/Rect.java: -------------------------------------------------------------------------------- 1 | package com.th3rdwave.safeareacontext; 2 | 3 | /* package */ class Rect { 4 | float x; 5 | float y; 6 | float width; 7 | float height; 8 | 9 | Rect(float x, float y, float width, float height) { 10 | this.x = x; 11 | this.y = y; 12 | this.width = width; 13 | this.height = height; 14 | } 15 | 16 | boolean equalsToRect(Rect other) { 17 | if (this == other) { 18 | return true; 19 | } 20 | return this.x == other.x && this.y == other.y && this.width == other.width && this.height == other.height; 21 | } 22 | } -------------------------------------------------------------------------------- /ios/SafeAreaView/RNCSafeAreaViewManager.m: -------------------------------------------------------------------------------- 1 | #import "RNCSafeAreaViewManager.h" 2 | 3 | #import "RNCSafeAreaShadowView.h" 4 | #import "RNCSafeAreaView.h" 5 | #import "RNCSafeAreaViewMode.h" 6 | #import "RNCSafeAreaViewEdges.h" 7 | 8 | @implementation RNCSafeAreaViewManager 9 | 10 | RCT_EXPORT_MODULE(RNCSafeAreaView) 11 | 12 | - (UIView *)view 13 | { 14 | return [[RNCSafeAreaView alloc] initWithBridge:self.bridge]; 15 | } 16 | 17 | - (RNCSafeAreaShadowView *)shadowView 18 | { 19 | return [RNCSafeAreaShadowView new]; 20 | } 21 | 22 | RCT_EXPORT_VIEW_PROPERTY(mode, RNCSafeAreaViewMode) 23 | RCT_EXPORT_VIEW_PROPERTY(edges, RNCSafeAreaViewEdges) 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.java: -------------------------------------------------------------------------------- 1 | package com.th3rdwave.safeareacontext; 2 | 3 | /* package */ class EdgeInsets { 4 | float top; 5 | float right; 6 | float bottom; 7 | float left; 8 | 9 | EdgeInsets(float top, float right, float bottom, float left) { 10 | this.top = top; 11 | this.right = right; 12 | this.bottom = bottom; 13 | this.left = left; 14 | } 15 | 16 | boolean equalsToEdgeInsets(EdgeInsets other) { 17 | if (this == other) { 18 | return true; 19 | } 20 | return this.top == other.top && this.right == other.right && this.bottom == other.bottom && this.left == other.left; 21 | } 22 | } -------------------------------------------------------------------------------- /example/android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /react-native-safe-area-context.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "react-native-safe-area-context" 7 | s.version = package['version'] 8 | s.summary = package['description'] 9 | s.license = package['license'] 10 | 11 | s.authors = package['author'] 12 | s.homepage = package['homepage'] 13 | s.platforms = { :ios => "9.0", :tvos => "9.2" } 14 | 15 | s.source = { :git => "https://github.com/th3rdwave/react-native-safe-area-context.git", :tag => "v#{s.version}" } 16 | s.source_files = "ios/**/*.{h,m}" 17 | 18 | s.dependency 'React-Core' 19 | end 20 | -------------------------------------------------------------------------------- /example/src/components/ReactNavigationHomeScreen.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { Button, Text } from 'react-native'; 3 | import { ScreenProps } from '../types/Navigation'; 4 | import { SafeAreaViewVisualizer } from './SafeAreaViewVisualizer'; 5 | 6 | export default function ReactNavigationHomeScreen({ 7 | navigation, 8 | }: ScreenProps<'Home'>) { 9 | return ( 10 | 11 | Home Screen 12 |