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

fix: web compatibility #406

Merged
merged 34 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
94670f3
fix: web compatibility
Jan 9, 2019
96c8515
fix: implement TapGestureHandler
Jan 9, 2019
3867bfa
fix: treat enabled property as true if not set explicitely
Jan 9, 2019
a9cd8fb
fix: move Directions and State to separate modules
Jan 10, 2019
97236fd
fix: add dummy setNativeProps
Jan 10, 2019
ee685df
fix: use responder events
Jan 14, 2019
cd9bc75
fix: map Responder event properties
Jan 15, 2019
c62c1ee
fix: reduce memory footprint
Jan 15, 2019
b8bcc54
fix: support maxDurationMs in TapGestureHandler
Jan 15, 2019
f508722
fix: improve TapGestureHandler
Jan 26, 2019
107f5d7
fix: add web platform to example app
Jan 29, 2019
0dd754a
fix: change babel preset to react-native
Jan 30, 2019
59d1586
fix: remove GestureHandler.web.js and instead reuse GestureHandler.js
Jan 30, 2019
a586cea
fix: remove View wrapper from TapGestureHandler
Jan 31, 2019
b4343e0
fix: remove inheritance
Jan 31, 2019
f6bd3a9
fix: rename file suffixes
Jan 31, 2019
9fd9071
fix: rename file suffixes
Feb 1, 2019
c74b441
Merge branch 'master' into fix/web-compatibility
jaulz Feb 1, 2019
4b485d4
fix: remove suffix
Feb 2, 2019
5cbb2c9
fix: remove suffix
Feb 2, 2019
251f13d
fix: remove suffix
Feb 2, 2019
ba0cdfc
fix(example): update android compile sdk version to 28
Jekiwijaya Feb 2, 2019
19bb6b2
Merge pull request #1 from Jekiwijaya/fix/android/sdk-version
jaulz Feb 2, 2019
831c3aa
fix: add new files to package.json
Feb 5, 2019
81019e2
fix: restore original binding
Feb 5, 2019
172f8df
fix: add files to package.json
jaulz Feb 5, 2019
9d6dc77
fix: read directions from native module
Feb 7, 2019
362b23b
fix: add unsupported warnings
Feb 7, 2019
868ed93
fix: remove Alert.alert
Feb 7, 2019
23af89f
fix: remove drawer style
Feb 7, 2019
9304881
fix: improve structure for rendering
Feb 7, 2019
945c296
fix: force rerendering if public methods of Drawer are used
Feb 7, 2019
376b5b4
fix: use global alert
Feb 12, 2019
4f568bc
fix: add createHandler file
Feb 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Directions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NativeModules } from 'react-native';

const { RNGestureHandlerModule } = NativeModules;

export default RNGestureHandlerModule.Direction;
6 changes: 6 additions & 0 deletions Directions.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
RIGHT: 1,
LEFT: 2,
UP: 4,
DOWN: 8,
};
13 changes: 9 additions & 4 deletions DrawerLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
StatusBar,
I18nManager,
} from 'react-native';
import { AnimatedEvent } from 'react-native/Libraries/Animated/src/AnimatedEvent';

import { PanGestureHandler, TapGestureHandler, State } from './GestureHandler';

Expand Down Expand Up @@ -88,7 +87,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
Right: 'right',
};
_openValue: ?Animated.Interpolation;
_onGestureEvent: ?AnimatedEvent;
_onGestureEvent: ?Animated.Event;
_accessibilityIsModalView = React.createRef();
_pointerEventsView = React.createRef();
_panGestureHandler = React.createRef();
Expand Down Expand Up @@ -353,10 +352,16 @@ export default class DrawerLayout extends Component<PropType, StateType> {
this.props.drawerWidth,
options.velocity ? options.velocity : 0
);

// We need to force the update, otherwise the overlay is not rerendered and it would not be clickable
this.forceUpdate();
};

closeDrawer = (options: DrawerMovementOptionType = {}) => {
this._animateDrawer(undefined, 0, options.velocity ? options.velocity : 0);

// We need to force the update, otherwise the overlay is not rerendered and it would be still clickable
this.forceUpdate();
};

_renderOverlay = () => {
Expand All @@ -371,6 +376,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
opacity: overlayOpacity,
backgroundColor: this.props.overlayColor,
};

return (
<TapGestureHandler onHandlerStateChange={this._onTapHandlerStateChange}>
<Animated.View
Expand Down Expand Up @@ -455,7 +461,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
ref={this._accessibilityIsModalView}
accessibilityViewIsModal={this._drawerShown}
style={[styles.drawerContainer, drawerStyles, drawerContainerStyle]}>
<View style={[styles.drawer, dynamicDrawerStyles]}>
<View style={dynamicDrawerStyles}>
{this.props.renderNavigationView(this._openValue)}
</View>
</Animated.View>
Expand Down Expand Up @@ -509,7 +515,6 @@ export default class DrawerLayout extends Component<PropType, StateType> {
}

const styles = StyleSheet.create({
drawer: { flex: 0 },
drawerContainer: {
...StyleSheet.absoluteFillObject,
zIndex: 1001,
Expand Down
4 changes: 2 additions & 2 deletions Example/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Text, View, FlatList, StyleSheet, YellowBox } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import { createAppContainer, createStackNavigator } from 'react-navigation';
import { RectButton, ScrollView } from 'react-native-gesture-handler';

import SwipeableTable from './swipeable';
Expand Down Expand Up @@ -156,4 +156,4 @@ const styles = StyleSheet.create({
},
});

export default ExampleApp;
export default createAppContainer(ExampleApp);
2 changes: 1 addition & 1 deletion Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
compileSdkVersion = 28
jaulz marked this conversation as resolved.
Show resolved Hide resolved
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
Expand Down
2 changes: 1 addition & 1 deletion Example/bottomSheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PanGestureHandler,
NativeViewGestureHandler,
State,
TapGestureHandler
TapGestureHandler,
} from 'react-native-gesture-handler';

import { LoremIpsum } from '../common';
Expand Down
9 changes: 4 additions & 5 deletions Example/combo/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from 'react';
import {
Alert,
StyleSheet,
ScrollView as RNScroll,
Switch,
Expand Down Expand Up @@ -107,7 +106,7 @@ class ControlledSwitch extends React.Component {

class Combo extends Component {
_onClick = () => {
Alert.alert("I'm so touched");
alert("I'm so touched");
this._scrollView.scrollTo({ y: 200, animated: true });
};
render() {
Expand Down Expand Up @@ -140,7 +139,7 @@ class Combo extends Component {
<Swipeable>
<RectButton
style={styles.rectButton}
onPress={() => Alert.alert('First row clicked')}>
onPress={() => alert('First row clicked')}>
<Text style={styles.buttonText}>
Swipe this row & observe highlight delay
</Text>
Expand All @@ -155,7 +154,7 @@ class Combo extends Component {
<View style={styles.buttonDelimiter} />
<RectButton
style={styles.rectButton}
onPress={() => Alert.alert('Second row clicked')}>
onPress={() => alert('Second row clicked')}>
<Text style={styles.buttonText}>
Second info icon will block scrolling
</Text>
Expand All @@ -167,7 +166,7 @@ class Combo extends Component {
<View style={styles.buttonDelimiter} />
<RectButton
style={styles.rectButton}
onPress={() => Alert.alert('Third row clicked')}>
onPress={() => alert('Third row clicked')}>
<Text style={styles.buttonText}>
This one will cancel when you drag outside
</Text>
Expand Down
10 changes: 4 additions & 6 deletions Example/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ export class LoremIpsum extends React.Component {
style: styles.lipsum,
};
loremIpsum() {
return LOREM_IPSUM.split(' ').slice(0, this.props.words).join(' ');
return LOREM_IPSUM.split(' ')
.slice(0, this.props.words)
.join(' ');
}
render() {
return (
<Text style={this.props.style}>
{this.loremIpsum()}
</Text>
);
return <Text style={this.props.style}>{this.loremIpsum()}</Text>;
}
}

Expand Down
6 changes: 6 additions & 0 deletions Example/index.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { AppRegistry } from 'react-native';

import ExampleApp from './App';

AppRegistry.registerComponent('App', () => ExampleApp);
AppRegistry.runApplication('App', { rootTag: document.getElementById('root') });
34 changes: 4 additions & 30 deletions Example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
const blacklist = require('metro-config/src/defaults/blacklist');
const path = require('path');
const pkg = require('./package.json');

const glob = require('glob-to-regexp');

function getBlacklist() {
const nodeModuleDirs = [
glob(`${path.resolve(__dirname, '..')}/node_modules/*`),
glob(`${path.resolve(__dirname)}/node_modules/metro/node_modules/fbjs/*`),
glob(`${path.resolve(__dirname)}/node_modules/*/node_modules/fbjs/*`),
glob(
`${path.resolve(
__dirname
)}/node_modules/create-react-context/node_modules/fbjs/*`
),
glob(
`${path.resolve(
__dirname
)}/node_modules/create-react-class/node_modules/fbjs/*`
),
glob(
`${path.resolve(
__dirname
)}/node_modules/react-navigation/node_modules/hoist-non-react-statics/*`
),
glob(
`${path.resolve(
__dirname
)}/node_modules/react-navigation-tabs/node_modules/hoist-non-react-statics/*`
),
glob(
`${path.resolve(
__dirname
)}/node_modules/react-native-safe-area-view/node_modules/hoist-non-react-statics/*`
)}/node_modules/*/node_modules/hoist-non-react-statics/*`
),
];
return blacklist(nodeModuleDirs);
Expand All @@ -39,14 +20,7 @@ function getBlacklist() {
module.exports = {
resolver: {
blacklistRE: getBlacklist(),
providesModuleNodeModules: [
'react-native',
'react',
'invariant',
'fbjs',
'prop-types',
'hoist-non-react-statics',
],
providesModuleNodeModules: Object.keys(pkg.dependencies),
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

},
watchFolders: [path.resolve(__dirname, '..')],
};
8 changes: 4 additions & 4 deletions Example/multitap/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Alert, StyleSheet, View } from 'react-native';
import { StyleSheet, View } from 'react-native';

import {
LongPressGestureHandler,
Expand All @@ -14,17 +14,17 @@ export class PressBox extends Component {
doubleTapRef = React.createRef();
_onHandlerStateChange = event => {
if (event.nativeEvent.state === State.ACTIVE) {
Alert.alert("I'm being pressed for so long");
alert("I'm being pressed for so long");
}
};
_onSingleTap = event => {
if (event.nativeEvent.state === State.ACTIVE) {
Alert.alert("I'm touched");
alert("I'm touched");
}
};
_onDoubleTap = event => {
if (event.nativeEvent.state === State.ACTIVE) {
Alert.alert('D0able tap, good job!');
alert('D0able tap, good job!');
}
};
render() {
Expand Down
22 changes: 19 additions & 3 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start --config ../../../../metro.config.js",
"ios": "react-native run-ios",
"android": "react-native run-android",
"web": "webpack-dev-server --open",
"test": "jest"
},
"dependencies": {
Expand All @@ -12,19 +15,32 @@
"invariant": "^2.2.4",
"prop-types": "^15.6.2",
"react": "16.5.1",
"react-native": "0.58.0-rc.2",
"react-art": "^16.7.0",
"react-dom": "^16.7.0",
"react-native": "^0.58.0-rc.2",
"react-native-vector-icons": "5.0.0",
"react-navigation": "2.17.0"
"react-native-web": "^0.10.0-alpha.3",
"react-navigation": "^3.1"
},
"jest": {
"preset": "react-native"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.1",
"@babel/runtime": "^7.3.1",
"babel-jest": "23.6.0",
"babel-loader": "^8.0.5",
"babel-plugin-module-resolver": "^3.1.1",
"babel-preset-react-native": "^4.0.1",
"glob-to-regexp": "^0.4.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.45.2",
"react-test-renderer": "^16.5.2"
"react-test-renderer": "^16.5.2",
"url-loader": "^1.1.2",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
}
}
4 changes: 2 additions & 2 deletions Example/panResponder/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Alert, StyleSheet, View, PanResponder } from 'react-native';
import { StyleSheet, View, PanResponder } from 'react-native';

import { ScrollView } from 'react-native-gesture-handler';

Expand Down Expand Up @@ -94,7 +94,7 @@ class PanResponderExample extends Component {

export default class Example extends Component {
_onClick = () => {
Alert.alert("I'm so touched");
alert("I'm so touched");
};
render() {
return (
Expand Down
16 changes: 8 additions & 8 deletions Example/rows/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Alert, Animated, StyleSheet, Text, View } from 'react-native';
import { Animated, StyleSheet, Text, View } from 'react-native';

import {
PanGestureHandler,
Expand Down Expand Up @@ -114,7 +114,7 @@ export const InfoButton = props => (
<BorderlessButton
{...props}
style={styles.infoButton}
onPress={() => Alert.alert(`${props.name} info button clicked`)}>
onPress={() => alert(`${props.name} info button clicked`)}>
<View style={styles.infoButtonBorders}>
<Text style={styles.infoButtonText}>i</Text>
</View>
Expand All @@ -132,7 +132,7 @@ export default class Example extends Component {
<Swipeable>
<RectButton
style={styles.rectButton}
onPress={() => Alert.alert('First row clicked')}>
onPress={() => alert('First row clicked')}>
<Text style={styles.buttonText}>
Swipe this row & observe highlight delay
</Text>
Expand All @@ -147,7 +147,7 @@ export default class Example extends Component {
<View style={styles.buttonDelimiter} />
<RectButton
style={styles.rectButton}
onPress={() => Alert.alert('Second row clicked')}>
onPress={() => alert('Second row clicked')}>
<Text style={styles.buttonText}>
Second info icon will block scrolling
</Text>
Expand All @@ -160,7 +160,7 @@ export default class Example extends Component {
<RectButton
rippleColor="red"
style={styles.rectButton}
onPress={() => Alert.alert('Third row clicked')}>
onPress={() => alert('Third row clicked')}>
<Text style={styles.buttonText}>
This one will cancel when you drag outside
</Text>
Expand All @@ -175,7 +175,7 @@ export default class Example extends Component {
<RectButton
enabled={false}
style={styles.rectButton}
onPress={() => Alert.alert('Fourth row clicked')}>
onPress={() => alert('Fourth row clicked')}>
<Text style={styles.buttonText}>
This row is "disabled" but you can swipe it
</Text>
Expand All @@ -184,12 +184,12 @@ export default class Example extends Component {
</Swipeable>
<LongPressGestureHandler
onHandlerStateChange={({ nativeEvent }) =>
nativeEvent.state === State.ACTIVE && Alert.alert('Long')
nativeEvent.state === State.ACTIVE && alert('Long')
}>
<RectButton
rippleColor="red"
style={styles.rectButton}
onPress={() => Alert.alert('Fifth row clicked')}>
onPress={() => alert('Fifth row clicked')}>
<Text style={styles.buttonText}>
Clickable row with long press handler
</Text>
Expand Down