forked from ptomasroos/react-native-scrollable-tab-view
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSceneComponent.js
70 lines (58 loc) · 1.9 KB
/
SceneComponent.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const React = require("react");
const ReactNative = require("react-native");
const { View, StyleSheet } = ReactNative;
import Orientation from "./components/Orientation";
const subtractiPhonePortraitWidth = 54;
const subtractiPhoneLandscapeWidth = 148;
const subtractiPadPortraitWidth = 54;
const subtractiPadLandscapeWidth = 54;
const iPhone = ReactNative.Platform.OS === "ios";
const android = ReactNative.Platform.OS === "android";
const iPad = ReactNative.Platform.isPad ? true : false;
const isTV = ReactNative.Platform.isTV;
const SceneComponent = (Props) => {
const { shouldUpdated, ...props } = Props;
const [layoutWidth, setLayoutWidth] = React.useState(0);
const [layoutHeight, setLayoutHeight] = React.useState(0);
const deviceWidth = ReactNative.Dimensions.get("screen").width;
const [orientation, setOrientation] = React.useState(
Orientation.isPortrait() ? "portrait" : "landscape"
);
React.useEffect(() => {
ReactNative.Dimensions.addEventListener("change", () => {
setOrientation(Orientation.isPortrait() ? "portrait" : "landscape");
});
});
React.useEffect(() => {
if (iPhone && orientation === "portrait") {
setLayoutWidth(deviceWidth - subtractiPhonePortraitWidth);
}
if (iPhone && orientation === "landscape") {
setLayoutWidth(deviceWidth - subtractiPhoneLandscapeWidth);
}
if (iPad && orientation === "portrait") {
setLayoutWidth(deviceWidth - subtractiPadPortraitWidth);
}
if (iPad && orientation === "landscape") {
setLayoutWidth(deviceWidth - subtractiPadLandscapeWidth);
}
if (android) {
setLayoutWidth(deviceWidth - 55);
}
if (isTV) {
setLayoutWidth(deviceWidth - 108);
}
});
return (
<View
onLayout={() => {}}
style={{
width: layoutWidth,
height: "auto",
}}
>
{props.children}
</View>
);
};
module.exports = SceneComponent;