-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 893 Bytes
/
Copy pathindex.js
File metadata and controls
40 lines (33 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { Component } from "react";
import { Dimensions, View } from "react-native";
const Wrapper = View;
const isPortrait = () => {
const dim = Dimensions.get("screen");
return dim.height >= dim.width;
};
export class OrientationChangeProvider extends Component {
constructor() {
super();
this.state = {
orientation: isPortrait() ? "portrait" : "landscape"
};
Dimensions.addEventListener("change", () => {
this.setState({
orientation: isPortrait() ? "portrait" : "landscape"
});
});
}
shouldComponentUpdate(nextProps, nextState) {
return (
this.state.orientation !== nextState.orientation ||
this.props.children !== nextProps.children
);
}
render() {
return (
<Wrapper style={{ display: "flex", flexGrow: 1 }} key={Date.now()}>
{this.props.children}
</Wrapper>
);
}
}