Skip to content

Commit 1718b4b

Browse files
author
Javier Marquez
committed
Adds touchable also to the vendor files
1 parent 697c86d commit 1718b4b

5 files changed

Lines changed: 1067 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"peerDependencies": {
1717
"react": "^16.5",
18+
"react-dom": "^16.5",
1819
"animated": "^0.2.2"
1920
},
2021
"repository": {
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React, {Component} from 'react'
2+
import Touchable from './vendor/Touchable'
3+
import Animated from 'animated/lib/targets/react-dom'
4+
5+
export default class AnimatedView extends Component {
6+
constructor( props ){
7+
super( props )
8+
this.state = this.touchableGetInitialState()
9+
}
10+
11+
/**
12+
* `Touchable.Mixin` self callbacks. The mixin will invoke these if they are
13+
* defined on your component.
14+
*/
15+
touchableHandlePress(e) {
16+
this.props.onPress && this.props.onPress(e);
17+
}
18+
19+
touchableHandleActivePressIn(e) {
20+
this.props.onPressIn && this.props.onPressIn(e);
21+
}
22+
23+
touchableHandleActivePressOut(e) {
24+
this.props.onPressOut && this.props.onPressOut(e);
25+
}
26+
27+
touchableHandleLongPress(e) {
28+
this.props.onLongPress && this.props.onLongPress(e);
29+
}
30+
31+
touchableGetPressRectOffset() {
32+
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
33+
}
34+
35+
touchableGetHitSlop() {
36+
return this.props.hitSlop;
37+
}
38+
39+
touchableGetHighlightDelayMS() {
40+
return this.props.delayPressIn || 0;
41+
}
42+
43+
touchableGetLongPressDelayMS() {
44+
return this.props.delayLongPress === 0 ? 0 : this.props.delayLongPress || 500;
45+
}
46+
47+
touchableGetPressOutDelayMS() {
48+
return this.props.delayPressOut || 0;
49+
}
50+
51+
render() {
52+
const {
53+
/* eslint-disable */
54+
delayLongPress,
55+
delayPressIn,
56+
delayPressOut,
57+
onLongPress,
58+
onPress,
59+
onPressIn,
60+
onPressOut,
61+
pressRetentionOffset,
62+
/* eslint-enable */
63+
...other
64+
} = this.props;
65+
66+
return (
67+
<Animated.div {...other}
68+
accessible= { this.props.accessible !== false }
69+
onKeyDown={this.touchableHandleKeyEvent}
70+
onKeyUp={this.touchableHandleKeyEvent}
71+
onResponderGrant={this.touchableHandleResponderGrant}
72+
onResponderMove={this.touchableHandleResponderMove}
73+
onResponderRelease={this.touchableHandleResponderRelease}
74+
onResponderTerminate={this.touchableHandleResponderTerminate}
75+
onResponderTerminationRequest={this.touchableHandleResponderTerminationRequest}
76+
onStartShouldSetResponder={this.touchableHandleStartShouldSetResponder}>
77+
{ this.props.children }
78+
</Animated.div>
79+
)
80+
81+
return React.cloneElement(this.props.children, {
82+
...other,
83+
accessible: this.props.accessible !== false,
84+
children,
85+
onKeyDown: this.touchableHandleKeyEvent,
86+
onKeyUp: this.touchableHandleKeyEvent,
87+
onResponderGrant: this.touchableHandleResponderGrant,
88+
onResponderMove: this.touchableHandleResponderMove,
89+
onResponderRelease: this.touchableHandleResponderRelease,
90+
onResponderTerminate: this.touchableHandleResponderTerminate,
91+
onResponderTerminationRequest: this.touchableHandleResponderTerminationRequest,
92+
onStartShouldSetResponder: this.touchableHandleStartShouldSetResponder,
93+
style
94+
});
95+
}
96+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @providesModule TouchEventUtils
8+
*/
9+
10+
const TouchEventUtils = {
11+
/**
12+
* Utility function for common case of extracting out the primary touch from a
13+
* touch event.
14+
* - `touchEnd` events usually do not have the `touches` property.
15+
* http://stackoverflow.com/questions/3666929/
16+
* mobile-sarai-touchend-event-not-firing-when-last-touch-is-removed
17+
*
18+
* @param {Event} nativeEvent Native event that may or may not be a touch.
19+
* @return {TouchesObject?} an object with pageX and pageY or null.
20+
*/
21+
extractSingleTouch: function(nativeEvent) {
22+
const touches = nativeEvent.touches;
23+
const changedTouches = nativeEvent.changedTouches;
24+
const hasTouches = touches && touches.length > 0;
25+
const hasChangedTouches = changedTouches && changedTouches.length > 0;
26+
27+
return !hasTouches && hasChangedTouches ? changedTouches[0] :
28+
hasTouches ? touches[0] :
29+
nativeEvent;
30+
}
31+
};
32+
33+
module.exports = TouchEventUtils;

0 commit comments

Comments
 (0)