forked from hyochan/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GestureComponents.js
59 lines (55 loc) · 1.48 KB
/
GestureComponents.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
import React from 'react';
import ReactNative from 'react-native';
import createNativeWrapper from './createNativeWrapper';
const MEMOIZED = {};
function memoizeWrap(Component, config) {
const memoized = MEMOIZED[Component.displayName];
if (memoized) {
return memoized;
}
return (MEMOIZED[Component.displayName] = createNativeWrapper(
Component,
config
));
}
module.exports = {
/* RN's components */
get ScrollView() {
return memoizeWrap(ReactNative.ScrollView, {
disallowInterruption: true,
});
},
get Switch() {
return memoizeWrap(ReactNative.Switch, {
shouldCancelWhenOutside: false,
shouldActivateOnStart: true,
disallowInterruption: true,
});
},
get TextInput() {
return memoizeWrap(ReactNative.TextInput);
},
get ToolbarAndroid() {
return memoizeWrap(ReactNative.ToolbarAndroid);
},
get DrawerLayoutAndroid() {
const DrawerLayoutAndroid = memoizeWrap(ReactNative.DrawerLayoutAndroid, {
disallowInterruption: true,
});
DrawerLayoutAndroid.positions = ReactNative.DrawerLayoutAndroid.positions;
return DrawerLayoutAndroid;
},
get FlatList() {
if (!MEMOIZED.FlatList) {
const ScrollView = this.ScrollView;
MEMOIZED.FlatList = React.forwardRef((props, ref) => (
<ReactNative.FlatList
ref={ref}
{...props}
renderScrollComponent={scrollProps => <ScrollView {...scrollProps} />}
/>
));
}
return MEMOIZED.FlatList;
},
};