This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-04-02 02:24:13 +03:00
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;
},
};