-
Notifications
You must be signed in to change notification settings - Fork 13
/
utils.js
63 lines (50 loc) · 1.59 KB
/
utils.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
import React from 'react';
import {
Dimensions,
Platform,
} from 'react-native';
const getNavigationDelegate = (component) => (component.wrappedComponent && component.wrappedComponent.navigationDelegate) ||
component.navigationDelegate ||
(component.type && component.type.navigationDelegate);
const getOrientation = () => {
const { width, height } = Dimensions.get('window');
return height > width ? 'PORTRAIT' : 'LANDSCAPE';
};
const replaceInstanceEventedProps =
(reactElement, eventedProps, events = [], route, navigationContext) => {
eventedProps.forEach((eventedProp) => {
if (React.isValidElement(reactElement) && reactElement.props[eventedProp]) {
const event = reactElement.props[eventedProp]();
if (typeof event === 'string') {
if (events.indexOf(event) < 0) {
events.push(event);
}
reactElement = React.cloneElement(reactElement, {
[eventedProp]: (e) => navigationContext.emit(event, { route, e }),
});
}
}
});
return { reactElement, events };
};
const isIphoneX = () => {
const { width, height } = Dimensions.get('window');
return (
Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(height === 812 || width === 812)
);
}
const getNavigationOption = (route, option) => {
return route && route.component &&
getNavigationDelegate(route.component) &&
getNavigationDelegate(route.component)[option];
}
export {
getNavigationDelegate,
getNavigationOption,
getOrientation,
replaceInstanceEventedProps,
isIphoneX,
};