This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GestureComponents.js
58 lines (54 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
import React from 'react';
import ReactNative from 'react-native';
import createNativeWrapper from './createNativeWrapper';
const MEMOIZED = new WeakMap();
function memoizeWrap(Component, config) {
if (Component == null) {
return null;
}
let memoized = MEMOIZED.get(Component);
if (!memoized) {
memoized = createNativeWrapper(Component, config);
MEMOIZED.set(Component, memoized);
}
return memoized;
}
module.exports = {
/* RN's components */
get ScrollView() {
return memoizeWrap(ReactNative.ScrollView, {
disallowInterruption: true,
shouldCancelWhenOutside: false,
});
},
get Switch() {
return memoizeWrap(ReactNative.Switch, {
shouldCancelWhenOutside: false,
shouldActivateOnStart: true,
disallowInterruption: true,
});
},
get TextInput() {
return memoizeWrap(ReactNative.TextInput);
},
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;
},
};