diff --git a/.gitignore b/.gitignore index 03e85dc..07f06ed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .AppleDouble .LSOverride +yarn.lock # Icon must end with two \r Icon diff --git a/index.d.ts b/index.d.ts index 9022703..1b2d6cc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,6 +11,7 @@ declare module 'react-native-safe-area' { // from `SafeArea.[ios|android].js` export default class SafeArea { + static getInitialInsets(): SafeAreaInsets static getSafeAreaInsetsForRootView(): Promise static addEventListener(eventType: EventType, listener: (payload: EventPayload) => void): void static removeEventListener(eventType: EventType, listener: (payload: EventPayload) => void): void diff --git a/ios/RNSafeArea/RNSafeArea.m b/ios/RNSafeArea/RNSafeArea.m index f0f5359..1878872 100644 --- a/ios/RNSafeArea/RNSafeArea.m +++ b/ios/RNSafeArea/RNSafeArea.m @@ -32,6 +32,18 @@ - (id)init { return self; } +- (NSDictionary *)constantsToExport { + UIEdgeInsets safeAreaInsets = [self safeAreaInsetsForRootView]; + return @{ + @"initialInsets": @{ + @"top": @(safeAreaInsets.top), + @"left": @(safeAreaInsets.left), + @"bottom": @(safeAreaInsets.bottom), + @"right": @(safeAreaInsets.right), + }, + }; +} + + (BOOL)requiresMainQueueSetup { return YES; } diff --git a/lib/SafeArea.android.js b/lib/SafeArea.android.js index d1232ad..bcfbdd0 100644 --- a/lib/SafeArea.android.js +++ b/lib/SafeArea.android.js @@ -4,6 +4,10 @@ import type EmitterSubscription from 'EmitterSubscription' import type { SafeAreaInsets } from './TypeDefinition' class SafeArea { + getInitialInsets() { + return { top: 0, left: 0, bottom: 0, right: 0 }; + } + getSafeAreaInsetsForRootView(): Promise<{ safeAreaInsets: SafeAreaInsets }> { return Promise.resolve({ safeAreaInsets: { top: 0, left: 0, bottom: 0, right: 0 } }) } diff --git a/lib/SafeArea.ios.js b/lib/SafeArea.ios.js index e3892aa..8243d6d 100644 --- a/lib/SafeArea.ios.js +++ b/lib/SafeArea.ios.js @@ -8,6 +8,9 @@ const nativeModule = NativeModules.RNSafeArea const nativeEventEmitter = new NativeEventEmitter(nativeModule) class SafeArea { + getInitialInsets() { + return nativeModule.initialInsets; + } getSafeAreaInsetsForRootView(): Promise<{ safeAreaInsets: SafeAreaInsets }> { return nativeModule.getSafeAreaInsetsForRootView() }