Skip to content
This repository was archived by the owner on Jan 30, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,22 @@ Sometimes you will observe unexpected behavior and jank because SafeAreaView use
```

`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.

## methods

### getInset(key, isLandscape)

If you need to access inset information, use the SafeAreaView's static `getInset` method.
Accepts 2 parameters:
#### key
`top | right | bottom | left`

The inset direction to get
#### isLandscape
`true | false`

Whether the app is currently in landscape position. Default = false
Example:
```javascript
<NavigationHeader style={{paddingTop: SafeAreaView.getInset('top')}} />
```
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,18 @@ class SafeView extends Component {

const style = {
...viewStyle,
paddingTop: touchesTop ? this._getInset('top') : 0,
paddingBottom: touchesBottom ? this._getInset('bottom') : 0,
paddingLeft: touchesLeft ? this._getInset('left') : 0,
paddingRight: touchesRight ? this._getInset('right') : 0,
paddingTop: touchesTop ? SafeView.getInset('top', isLandscape) : 0,
paddingBottom: touchesBottom ? SafeView.getInset('bottom', isLandscape) : 0,
paddingLeft: touchesLeft ? SafeView.getInset('left', isLandscape) : 0,
paddingRight: touchesRight ? SafeView.getInset('right', isLandscape) : 0,
};

if (forceInset) {
Object.keys(forceInset).forEach(key => {
let inset = forceInset[key];

if (inset === 'always') {
inset = this._getInset(key);
inset = SafeView.getInset(key, isLandscape);
}

if (inset === 'never') {
Expand Down Expand Up @@ -295,8 +295,7 @@ class SafeView extends Component {
};
};

_getInset = key => {
const { isLandscape } = this.props;
static getInset = (key, isLandscape = false) => {
switch (key) {
case 'horizontal':
case 'right':
Expand Down