You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-native-safe-area

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-safe-area - npm Package Compare versions

Comparing version

to
0.2.0

.flowconfig

9

.eslintrc.json

@@ -8,3 +8,4 @@ {

"eslint:recommended",
"plugin:react/recommended"
"plugin:react/recommended",
"plugin:flowtype/recommended"
],

@@ -20,3 +21,4 @@ "parser": "babel-eslint",

"plugins": [
"react"
"react",
"flowtype"
],

@@ -39,4 +41,5 @@ "rules": {

"never"
]
],
"no-unused-vars": ["warn", { "args": "none" }]
}
}

@@ -0,9 +1,23 @@

/**
* @flow
*/
'use strict'
import type EmitterSubscription from 'EmitterSubscription'
export type SafeAreaInsets = { top: number, left: number, bottom: number, right: number };
class SafeArea {
getSafeAreaInsetsForRootView() {
getSafeAreaInsetsForRootView(): Promise<{ safeAreaInsets: SafeAreaInsets }> {
return Promise.resolve({ safeAreaInsets: { top: 0, left: 0, bottom: 0, right: 0 } })
}
addEventListener(eventType: string, listener: Function, context: ?Object): ?EmitterSubscription {
return null
}
removeEventListener(eventType: string, listener: Function): void {
}
}
module.exports = new SafeArea()
export default new SafeArea()

@@ -0,7 +1,28 @@

/**
* @flow
*/
'use strict'
import { NativeModules } from 'react-native'
import { NativeModules, NativeEventEmitter } from 'react-native'
import type EmitterSubscription from 'EmitterSubscription'
const SafeArea = NativeModules.RNSafeArea
export type SafeAreaInsets = { top: number, left: number, bottom: number, right: number };
module.exports = SafeArea
const nativeModule = NativeModules.RNSafeArea
const nativeEventEmitter = new NativeEventEmitter(nativeModule)
class SafeArea {
getSafeAreaInsetsForRootView(): Promise<{ safeAreaInsets: SafeAreaInsets }> {
return nativeModule.getSafeAreaInsetsForRootView()
}
addEventListener(eventType: string, listener: Function, context: ?Object): ?EmitterSubscription {
return nativeEventEmitter.addListener(eventType, listener, context)
}
removeEventListener(eventType: string, listener: Function): void {
nativeEventEmitter.removeListener(eventType, listener)
}
}
export default new SafeArea()
{
"name": "react-native-safe-area",
"version": "0.1.3",
"version": "0.2.0",
"description": "React Native module to get Safe Area Insets for iOS 11 or later",

@@ -8,2 +8,3 @@ "main": "index",

"lint": "eslint .",
"flow": "flow --show-all-errors",
"test": "npm run lint"

@@ -27,6 +28,10 @@ },

"babel-eslint": "^8.0.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-react-native": "^3.0.2",
"eslint": "^4.6.1",
"eslint-plugin-react": "^7.3.0"
"eslint-plugin-flowtype": "^2.38.0",
"eslint-plugin-react": "^7.3.0",
"flow-bin": "^0.53.1",
"react-native": "^0.48.4"
}
}
# react-native-safe-area
React Native module to get Safe Area Insets for iOS 11 or later.
# Installation
React Native module to retrieve safe area insets for iOS 11 or later.
## Installation
```shell
npm install --save react-native-safe-area
react-native link
react-native link react-native-safe-area
```
# How to use
## Usage
```jsx
import SafeArea from 'react-native-safe-area'
```
If you want to use `SafeAreaInsets` type, you can import it like below:
```jsx
import SafeArea, { type SafeAreaInsets } from 'react-native-safe-area'
```
### Retrieve safe area insets for root view
```jsx
SafeArea.getSafeAreaInsetsForRootView()
.then((result) => {
console.log(result) // { safeAreaInsets: { bottom: 0, top: 0, left: 0, right: 0 } }
console.log(result)
// { safeAreaInsets: { top: 44, left: 0, bottom: 34, right: 0 } }
})
```
### Handle safe area insets changed event
```jsx
class App extends Component<{}> {
// To keep the context of 'this'
onSafeAreaInsetsForRootViewChange = this.onSafeAreaInsetsForRootViewChange.bind(this)
componentDidMount() {
// Add event listener
SafeArea.addEventListener('safeAreaInsetsForRootViewDidChange', this.onSafeAreaInsetsForRootViewChange)
}
componentWillUnmount() {
// Remove event listener
SafeArea.removeEventListener('safeAreaInsetsForRootViewDidChange', this.onSafeAreaInsetsForRootViewChange)
}
onSafeAreaInsetsForRootViewChange(result) {
// Called every time that safe area insets changed
console.log(result)
// { safeAreaInsets: { top: 0, left: 44, bottom: 21, right: 44 } }
}
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet