forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GestureHandlerRootView.android.js
39 lines (34 loc) · 1.12 KB
/
GestureHandlerRootView.android.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
import React from 'react';
import { View, ViewPropTypes, requireNativeComponent } from 'react-native';
const iface = {
name: 'GestureHandlerRootView',
propTypes: {
...ViewPropTypes,
},
};
const GestureHandlerRootViewNative = requireNativeComponent(
'GestureHandlerRootView',
iface
);
const GestureHandlerRootViewContext = React.createContext(false);
export default function GestureHandlerRootView({ children, ...rest }) {
return (
<GestureHandlerRootViewContext.Consumer>
{available => {
if (available) {
// If we already have a parent wrapped in the gesture handler root view,
// We don't need to wrap it again in root view
// We still wrap it in a normal view so our styling stays the same
return <View {...rest}>{children}</View>;
}
return (
<GestureHandlerRootViewContext.Provider value={true}>
<GestureHandlerRootViewNative {...rest}>
{children}
</GestureHandlerRootViewNative>
</GestureHandlerRootViewContext.Provider>
);
}}
</GestureHandlerRootViewContext.Consumer>
);
}