Skip to content

fix: web compatibility #406

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

Merged
merged 34 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AnimatedEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AnimatedEvent from 'react-native/Libraries/Animated/src/AnimatedEvent';

export default AnimatedEvent;
3 changes: 3 additions & 0 deletions AnimatedEvent.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AnimatedEvent from 'react-native-web/dist/vendor/react-native/Animated/AnimatedEvent';
Copy link

Choose a reason for hiding this comment

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

If AnimatedEvent needs to be used directly, you may want to ask that it is added to the Animated export from React Native rather than relying on the fragility of reaching into internals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will check on their repository and raise a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will keep track here: facebook/react-native#22984


export default AnimatedEvent;
6 changes: 6 additions & 0 deletions Directions.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,
};
4 changes: 2 additions & 2 deletions DrawerLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
StatusBar,
I18nManager,
} from 'react-native';
import { AnimatedEvent } from 'react-native/Libraries/Animated/src/AnimatedEvent';
import { AnimatedEvent } from './AnimatedEvent';

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

Expand Down Expand Up @@ -507,7 +507,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
}

const styles = StyleSheet.create({
drawer: { flex: 0 },
drawer: {},
drawerContainer: {
...StyleSheet.absoluteFillObject,
zIndex: 1001,
Expand Down
6 changes: 2 additions & 4 deletions GestureHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import deepEqual from 'fbjs/lib/areEqual';
import PropTypes from 'prop-types';

import gestureHandlerRootHOC from './gestureHandlerRootHOC';
import Directions from './Directions';
import State from './State';

const RNGestureHandlerModule = NativeModules.RNGestureHandlerModule;

Expand Down Expand Up @@ -51,10 +53,6 @@ UIManager.RCTView.directEventTypes = {
},
};

const State = RNGestureHandlerModule.State;

const Directions = RNGestureHandlerModule.Direction;

let handlerTag = 1;
const handlerIDToTag = {};

Expand Down
132 changes: 132 additions & 0 deletions GestureHandler.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React from 'react';
import {
ScrollView,
Slider,
Switch,
TextInput,
ToolbarAndroid,
ViewPagerAndroid,
DrawerLayoutAndroid,
FlatList,
TouchableWithoutFeedback,
} from 'react-native';
import gestureHandlerRootHOC from './gestureHandlerRootHOC';
import Directions from './Directions';
import State from './State';

// Factory for stub Handler components
function createStubHandler(name) {
return class NativeViewGestureHandler extends React.Component {
static displayName = name;

container = React.createRef();

setNativeProps() {
// Since this is a stub we do not need to pass on native props.
// However, we need to implement it here to avoid null calls.
// If for any reason we need to pass on native props we can fallback to this:
// this.container.current.setNativeProps(...args)
}

render() {
const { children, ...rest } = this.props;

// We don't want to create another layer, so instead we clone it only but keep the reference
const child = React.Children.only(children);
return React.cloneElement(child, {
ref: this.container,
...rest,
});
}
};
}

// Create all Handler components with their respective handler functions
// (at the moment only TapGestureHandler is properly supported)
const NativeViewGestureHandler = createStubHandler('NativeViewGestureHandler');

class TapGestureHandler extends React.Component {
setNativeProps() {}

render() {
const { children, enabled, onHandlerStateChange, style } = this.props;

return (
<TouchableWithoutFeedback
Copy link
Contributor

Choose a reason for hiding this comment

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

And can't we use onPressIn and onPressIn for achieving more native-like states' flow?

style={style}
onPress={({ x }) => {
enabled !== false &&
onHandlerStateChange &&
onHandlerStateChange({
nativeEvent: {
oldState: State.ACTIVE,
state: State.UNDETERMINED,
x,
},
});
}}>
{children}
</TouchableWithoutFeedback>
);
}
}

const FlingGestureHandler = createStubHandler('FlingGestureHandler');

const ForceTouchGestureHandler = createStubHandler('ForceTouchGestureHandler');

const LongPressGestureHandler = createStubHandler('LongPressGestureHandler');

const PanGestureHandler = createStubHandler('PanGestureHandler');

const PinchGestureHandler = createStubHandler('PinchGestureHandler');

const RotationGestureHandler = createStubHandler('RotationGestureHandler');

// Factory for stub Button component
// (at the moment this is a plain TouchableWithoutFeedback)
function createStubButton(name) {
return class Button extends React.Component {
static displayName = name;

render() {
return (
<TouchableWithoutFeedback accessibilityRole="button" {...this.props} />
);
}
};
}

const RawButton = createStubButton('RawButton');
const BaseButton = createStubButton('BaseButton');
const RectButton = createStubButton('RectButton');
const BorderlessButton = createStubButton('BorderlessButton');

// Export same components as in GestureHandler.js
export {
ScrollView,
Slider,
Switch,
TextInput,
ToolbarAndroid,
ViewPagerAndroid,
DrawerLayoutAndroid,
NativeViewGestureHandler,
TapGestureHandler,
FlingGestureHandler,
ForceTouchGestureHandler,
LongPressGestureHandler,
PanGestureHandler,
PinchGestureHandler,
RotationGestureHandler,
State,
/* Buttons */
RawButton,
BaseButton,
RectButton,
BorderlessButton,
/* Other */
FlatList,
gestureHandlerRootHOC,
Directions,
};
8 changes: 8 additions & 0 deletions State.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
CANCELLED: 3,
ACTIVE: 4,
END: 5,
};
2 changes: 1 addition & 1 deletion Swipeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { Component } from 'react';
import { Animated, StyleSheet, View } from 'react-native';
import { AnimatedEvent } from 'react-native/Libraries/Animated/src/AnimatedEvent';
import { AnimatedEvent } from './AnimatedEvent';

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

Expand Down
4 changes: 4 additions & 0 deletions Swipeable.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// At the moment no swipe is supported
export default function Swipeable({ children }) {
return children;
}