Skip to content

Instantly share code, notes, and snippets.

@miracle2k
Last active January 12, 2019 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miracle2k/3bc7f1c50080397dbf0d92cfb3101677 to your computer and use it in GitHub Desktop.
Save miracle2k/3bc7f1c50080397dbf0d92cfb3101677 to your computer and use it in GitHub Desktop.
// Generated with NODE_ENV=development yarn run babel node_modules/react-native-gesture-handler/touchables/GenericTouchable.js --presets module:metro-react-native-babel-preset --compact false
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.TOUCHABLE_STATE = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _GestureHandler = require("../GestureHandler");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _jsxFileName = "/Users/michael/Development/mine/ordersys-mobile/node_modules/react-native-gesture-handler/touchables/GenericTouchable.js";
var TOUCHABLE_STATE = {
UNDETERMINED: 0,
BEGAN: 1,
MOVED_OUTSIDE: 2
};
exports.TOUCHABLE_STATE = TOUCHABLE_STATE;
var GenericTouchable = function (_Component) {
(0, _inherits2.default)(GenericTouchable, _Component);
function GenericTouchable() {
var _getPrototypeOf2;
var _this;
(0, _classCallCheck2.default)(this, GenericTouchable);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(GenericTouchable)).call.apply(_getPrototypeOf2, [this].concat(args)));
_this.longPressDetected = false;
_this.pointerInside = true;
_this.STATE = TOUCHABLE_STATE.UNDETERMINED;
_this.handlePressIn = function () {
if (_this.props.delayPressIn) {
_this.pressInTimeout = setTimeout(function () {
_this.moveToState(TOUCHABLE_STATE.BEGAN);
_this.pressInTimeout = null;
}, _this.props.delayPressIn);
} else {
_this.moveToState(TOUCHABLE_STATE.BEGAN);
}
if (_this.props.onLongPress) {
var time = (_this.props.delayPressIn || 0) + (_this.props.delayLongPress || 0);
_this.longPressTimeout = setTimeout(_this.onLongPressDetected, time);
}
};
_this.handleMoveOutside = function () {
if (_this.props.delayPressOut) {
_this.pressOutTimeout = _this.pressOutTimeout || setTimeout(function () {
_this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
_this.pressOutTimeout = null;
}, _this.props.delayPressOut);
} else {
_this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
}
};
_this.handleGoToUndermined = function () {
clearTimeout(_this.pressOutTimeout);
if (_this.props.delayPressOut) {
_this.pressOutTimeout = setTimeout(function () {
if (_this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
_this.moveToState(TOUCHABLE_STATE.BEGAN);
}
_this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
_this.pressOutTimeout = null;
}, _this.props.delayPressOut);
} else {
if (_this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
_this.moveToState(TOUCHABLE_STATE.BEGAN);
}
_this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
}
};
_this.moveToState = function (newState) {
if (newState === _this.STATE) {
return;
}
if (newState === TOUCHABLE_STATE.BEGAN) {
_this.props.onPressIn && _this.props.onPressIn();
} else if (newState === TOUCHABLE_STATE.MOVED_OUTSIDE) {
_this.props.onPressOut && _this.props.onPressOut();
} else if (newState === TOUCHABLE_STATE.UNDETERMINED) {
_this.reset();
if (_this.STATE === TOUCHABLE_STATE.BEGAN) {
_this.props.onPressOut && _this.props.onPressOut();
}
}
_this.props.onStateChange && _this.props.onStateChange(_this.STATE, newState);
_this.STATE = newState;
};
_this.onGestureEvent = function (_ref) {
var pointerInside = _ref.nativeEvent.pointerInside;
if (_this.pointerInside !== pointerInside) {
if (pointerInside) {
_this.onMoveIn();
} else {
_this.onMoveOut();
}
}
_this.pointerInside = pointerInside;
};
_this.onHandlerStateChange = function (_ref2) {
var nativeEvent = _ref2.nativeEvent;
var state = nativeEvent.state;
if (state === _GestureHandler.State.CANCELLED || state === _GestureHandler.State.FAILED) {
_this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
} else if (state === (_reactNative.Platform.OS === 'ios' ? _GestureHandler.State.ACTIVE : _GestureHandler.State.BEGAN) && _this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
_this.handlePressIn();
} else if (state === _GestureHandler.State.END) {
var shouldCallOnPress = !_this.longPressDetected && _this.STATE !== TOUCHABLE_STATE.MOVED_OUTSIDE && _this.pressOutTimeout === null;
_this.handleGoToUndermined();
if (shouldCallOnPress) {
_this.props.onPress && _this.props.onPress();
}
}
};
_this.onLongPressDetected = function () {
_this.longPressDetected = true;
_this.props.onLongPress();
};
_this.onMoveIn = function () {
if (_this.STATE === TOUCHABLE_STATE.MOVED_OUTSIDE) {
_this.moveToState(TOUCHABLE_STATE.BEGAN);
}
};
_this.onMoveOut = function () {
clearTimeout(_this.longPressTimeout);
_this.longPressTimeout = null;
if (_this.STATE === TOUCHABLE_STATE.BEGAN) {
_this.handleMoveOutside();
}
};
return _this;
}
(0, _createClass2.default)(GenericTouchable, [{
key: "componentDidMount",
value: function componentDidMount() {
this.reset();
}
}, {
key: "reset",
value: function reset() {
this.longPressDetected = false;
this.pointerInside = true;
clearTimeout(this.pressInTimeout);
clearTimeout(this.pressOutTimeout);
clearTimeout(this.longPressTimeout);
this.pressOutTimeout = null;
this.longPressTimeout = null;
this.pressInTimeout = null;
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.reset();
}
}, {
key: "render",
value: function render() {
var coreProps = {
accessible: this.props.accessible !== false,
accessibilityLabel: this.props.accessibilityLabel,
accessibilityHint: this.props.accessibilityHint,
accessibilityComponentType: this.props.accessibilityComponentType,
accessibilityRole: this.props.accessibilityRole,
accessibilityStates: this.props.accessibilityStates,
accessibilityTraits: this.props.accessibilityTraits,
nativeID: this.props.nativeID,
testID: this.props.testID,
onLayout: this.props.onLayout,
hitSlop: this.props.hitSlop
};
return _react.default.createElement(_GestureHandler.BaseButton, (0, _extends2.default)({
onHandlerStateChange: this.props.disabled || this.onHandlerStateChange,
onGestureEvent: this.onGestureEvent,
hitSlop: this.props.hitSlop
}, this.props.extraButtonProps, {
__source: {
fileName: _jsxFileName,
lineNumber: 252
}
}), _react.default.createElement(_reactNative.Animated.View, (0, _extends2.default)({}, coreProps, {
style: this.props.style,
__source: {
fileName: _jsxFileName,
lineNumber: 257
}
}), this.props.children));
}
}]);
return GenericTouchable;
}(_react.Component);
exports.default = GenericTouchable;
GenericTouchable.publicPropTypes = {
accessible: _propTypes.default.bool,
accessibilityLabel: _propTypes.default.node,
accessibilityHint: _propTypes.default.string,
hitSlop: _propTypes.default.shape({
top: _propTypes.default.number,
left: _propTypes.default.number,
bottom: _propTypes.default.number,
right: _propTypes.default.number
}),
disabled: _propTypes.default.bool,
onPress: _propTypes.default.func,
onPressIn: _propTypes.default.func,
onPressOut: _propTypes.default.func,
onLayout: _propTypes.default.func,
onLongPress: _propTypes.default.func,
nativeID: _propTypes.default.string,
testID: _propTypes.default.string,
delayPressIn: _propTypes.default.number,
delayPressOut: _propTypes.default.number,
delayLongPress: _propTypes.default.number
};
GenericTouchable.internalPropTypes = {
extraButtonProps: _propTypes.default.object,
onStateChange: _propTypes.default.func
};
GenericTouchable.propTypes = (0, _objectSpread2.default)({}, GenericTouchable.internalPropTypes, GenericTouchable.publicPropTypes);
GenericTouchable.defaultProps = {
delayLongPress: 600,
extraButtonProps: {
rippleColor: 'transparent'
}
};
var GenericTouchable =
_wrapComponent("GenericTouchable")
(
(
_temp = _class = function (_Component) {
(0, _inherits2.default)(GenericTouchable, _Component);
function GenericTouchable() {
return _this;
}
(0, _createClass2.default)(GenericTouchable, [{
key: "componentDidMount",
value: function componentDidMount() {
this.reset();
}
}]);
return GenericTouchable;
}(_react.Component),
_class.publicPropTypes = {
accessible: _propTypes.default.bool,
accessibilityLabel: _propTypes.default.node,
accessibilityHint: _propTypes.default.string,
hitSlop: _propTypes.default.shape({
top: _propTypes.default.number,
left: _propTypes.default.number,
bottom: _propTypes.default.number,
right: _propTypes.default.number
}),
disabled: _propTypes.default.bool,
onPress: _propTypes.default.func,
onPressIn: _propTypes.default.func,
onPressOut: _propTypes.default.func,
onLayout: _propTypes.default.func,
onLongPress: _propTypes.default.func,
nativeID: _propTypes.default.string,
testID: _propTypes.default.string,
delayPressIn: _propTypes.default.number,
delayPressOut: _propTypes.default.number,
delayLongPress: _propTypes.default.number
},
_class.internalPropTypes = {
extraButtonProps: _propTypes.default.object,
onStateChange: _propTypes.default.func
},
_class.propTypes = (0, _objectSpread2.default)({}, GenericTouchable.internalPropTypes, GenericTouchable.publicPropTypes),
_class.defaultProps = {
delayLongPress: 600,
extraButtonProps: {
rippleColor: 'transparent'
}
},
_temp
)
);
var _default2 = GenericTouchable;
exports.default = _default2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment