Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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: react/react-native#22984


export default AnimatedEvent;
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: {},
Comment thread
jaulz marked this conversation as resolved.
Outdated
drawerContainer: {
...StyleSheet.absoluteFillObject,
zIndex: 1001,
Expand Down
150 changes: 150 additions & 0 deletions GestureHandler.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import React from 'react';
import {
ScrollView,
Slider,
Switch,
TextInput,
ToolbarAndroid,
ViewPagerAndroid,
DrawerLayoutAndroid,
WebView,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This module is being removed from React Native and isn't included in react-native-web either

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which one in detail? Currently, I see that all of these components are exported though some of them as UnimplementedView which is fine I guess.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info!

FlatList,
TouchableWithoutFeedback,
findNodeHandle,
} from 'react-native';
import gestureHandlerRootHOC from './gestureHandlerRootHOC';

const State = {
UNDETERMINED: 'UNDETERMINED',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we move it out somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What should we move out in detail? State constants?

@osdnk osdnk Jan 9, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. If you need them here, I wish to have them in separated file in order not to duplicate code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes more than sense 😊 Was not sure before since these constants were used in GestureHandler.js as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, well, we intentionally wanted to take them from native site every time. How I think there's no need to do it. You could think about removing extracting from from Java and Objective-C if it's not big deal for you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, the constants are used in the native part as well. Hence it actually makes sense to read them in the JavaScript part from the native side. Should I undo the changes in GestureHandler.js for the time being?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, it's fine now

FAILED: 'FAILED',
BEGAN: 'BEGAN',
CANCELLED: 'CANCELLED',
ACTIVE: 'ACTIVE',
END: 'END',
};

const Directions = {};

// Factory for Handler components
function createHandler(name, attachNativeHandler) {
return class Handler extends React.Component {
static displayName = name;

container = React.createRef();
Comment thread
jaulz marked this conversation as resolved.
Outdated
detachNativeHandler = null;

componentDidMount() {
// Get current DOM node
const node = findNodeHandle(this.container.current);

// Attach handler to DOM node
const { enabled } = this.props;
if (node && attachNativeHandler && enabled !== false) {
this.detachNativeHandler = attachNativeHandler(node, this.props);
}
}

componentDidUpdate() {
// Get current DOM node
const node = findNodeHandle(this.container.current);

if (node && attachNativeHandler) {
// Detach existing handlers
if (this.detachNativeHandler) {
this.detachNativeHandler(node);
}

// Attach handler to DOM node again
const { enabled } = this.props;
if (enabled !== false) {
attachNativeHandler(node, this.props);
}
}
}

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, {
Comment thread
jaulz marked this conversation as resolved.
Outdated
ref: this.container,
...rest,
});
}
};
}

// Create all Handler components with their respective handler functions
// (at the moment only TapGestureHandler is properly supported)
const NativeViewGestureHandler = createHandler('NativeViewGestureHandler');
const TapGestureHandler = createHandler('TapGestureHandler', (node, props) => {
const { onHandlerStateChange = () => {} } = props;
const clickHandler = ({ x }) =>
onHandlerStateChange({
nativeEvent: {
oldState: State.ACTIVE,
state: State.UNDETERMINED,
x,
},
});
node.addEventListener('click', clickHandler);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using these DOM events directly means you're not hooked into the responder event system

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you have any link for me to see how we could improve this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not familiar with the behaviour/implementation of the native TapGestureHandler. But if it turns out to be preferable to use the responder events, you could pass the event handlers to createHandler and forward them to the component.


// Detach event listeners
return () => {
node.removeEventListener('click', clickHandler);
};
});
const FlingGestureHandler = createHandler('FlingGestureHandler');
const ForceTouchGestureHandler = createHandler('ForceTouchGestureHandler');
const LongPressGestureHandler = createHandler('LongPressGestureHandler');
const PanGestureHandler = createHandler('PanGestureHandler');
const PinchGestureHandler = createHandler('PinchGestureHandler');
const RotationGestureHandler = createHandler('RotationGestureHandler');

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

render() {
return <TouchableWithoutFeedback {...this.props} />;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If these are meant to be used as buttons in the UI, you should add accessibilityRole="button"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint!

}
};
}

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

// Export same components as in GestureHandler.js
export {
ScrollView,
Slider,
Switch,
TextInput,
ToolbarAndroid,
ViewPagerAndroid,
DrawerLayoutAndroid,
WebView,
NativeViewGestureHandler,
TapGestureHandler,
FlingGestureHandler,
ForceTouchGestureHandler,
LongPressGestureHandler,
PanGestureHandler,
PinchGestureHandler,
RotationGestureHandler,
State,
/* Buttons */
RawButton,
BaseButton,
RectButton,
BorderlessButton,
/* Other */
FlatList,
gestureHandlerRootHOC,
Directions,
};
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;
Comment thread
kmagiera marked this conversation as resolved.
}