Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy import RN components #617

Merged
merged 1 commit into from
May 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 55 additions & 42 deletions GestureHandler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from 'react';
import {
Animated,
ScrollView,
Switch,
TextInput,
ToolbarAndroid,
DrawerLayoutAndroid,
StyleSheet,
FlatList,
Platform,
processColor,
default as ReactNative,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will include everything in React Native which means things like react-art which aren't used by anyone will get bundled.

} from 'react-native';
import PropTypes from 'prop-types';

Expand Down Expand Up @@ -425,22 +420,6 @@ function createNativeWrapper(Component, config = {}) {
return ComponentWrapper;
}

const WrappedScrollView = createNativeWrapper(ScrollView, {
disallowInterruption: true,
});
const WrappedSwitch = createNativeWrapper(Switch, {
shouldCancelWhenOutside: false,
shouldActivateOnStart: true,
disallowInterruption: true,
});
const WrappedTextInput = createNativeWrapper(TextInput);

const WrappedToolbarAndroid = createNativeWrapper(ToolbarAndroid);
const WrappedDrawerLayoutAndroid = createNativeWrapper(DrawerLayoutAndroid, {
disallowInterruption: true,
});
WrappedDrawerLayoutAndroid.positions = DrawerLayoutAndroid.positions;

State.print = state => {
const keys = Object.keys(State);
for (let i = 0; i < keys.length; i++) {
Expand Down Expand Up @@ -607,24 +586,59 @@ class BorderlessButton extends React.Component {
}
}

/* Other */

const FlatListWithGHScroll = React.forwardRef((props, ref) => (
<FlatList
ref={ref}
{...props}
renderScrollComponent={scrollProps => (
<WrappedScrollView {...scrollProps} />
)}
/>
));

export {
WrappedScrollView as ScrollView,
WrappedSwitch as Switch,
WrappedTextInput as TextInput,
WrappedToolbarAndroid as ToolbarAndroid,
WrappedDrawerLayoutAndroid as DrawerLayoutAndroid,
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;
},
NativeViewGestureHandler,
TapGestureHandler,
FlingGestureHandler,
Expand All @@ -640,9 +654,8 @@ export {
RectButton,
BorderlessButton,
/* Other */
FlatListWithGHScroll as FlatList,
gestureHandlerRootHOC,
GestureHandlerButton as PureNativeButton,
PureNativeButton: GestureHandlerButton,
Directions,
createNativeWrapper,
};