mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Prettier React Native Libraries
Reviewed By: sahrens Differential Revision: D7961488 fbshipit-source-id: 05f9b8b0b91ae77f9040a5321ccc18f7c3c1ce9a
This commit is contained in:
committed by
Facebook Github Bot
parent
1e2de71290
commit
d01ab66b47
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -36,7 +37,7 @@ BoundingDimensions.prototype.destructor = function() {
|
||||
BoundingDimensions.getPooledFromElement = function(element) {
|
||||
return BoundingDimensions.getPooled(
|
||||
element.offsetWidth,
|
||||
element.offsetHeight
|
||||
element.offsetHeight,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -110,14 +111,14 @@ const normalizeColor = require('normalizeColor');
|
||||
* Touchable states.
|
||||
*/
|
||||
const States = keyMirror({
|
||||
NOT_RESPONDER: null, // Not the responder
|
||||
RESPONDER_INACTIVE_PRESS_IN: null, // Responder, inactive, in the `PressRect`
|
||||
RESPONDER_INACTIVE_PRESS_OUT: null, // Responder, inactive, out of `PressRect`
|
||||
RESPONDER_ACTIVE_PRESS_IN: null, // Responder, active, in the `PressRect`
|
||||
RESPONDER_ACTIVE_PRESS_OUT: null, // Responder, active, out of `PressRect`
|
||||
RESPONDER_ACTIVE_LONG_PRESS_IN: null, // Responder, active, in the `PressRect`, after long press threshold
|
||||
NOT_RESPONDER: null, // Not the responder
|
||||
RESPONDER_INACTIVE_PRESS_IN: null, // Responder, inactive, in the `PressRect`
|
||||
RESPONDER_INACTIVE_PRESS_OUT: null, // Responder, inactive, out of `PressRect`
|
||||
RESPONDER_ACTIVE_PRESS_IN: null, // Responder, active, in the `PressRect`
|
||||
RESPONDER_ACTIVE_PRESS_OUT: null, // Responder, active, out of `PressRect`
|
||||
RESPONDER_ACTIVE_LONG_PRESS_IN: null, // Responder, active, in the `PressRect`, after long press threshold
|
||||
RESPONDER_ACTIVE_LONG_PRESS_OUT: null, // Responder, active, out of `PressRect`, after long press threshold
|
||||
ERROR: null
|
||||
ERROR: null,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -125,7 +126,7 @@ const States = keyMirror({
|
||||
*/
|
||||
const IsActive = {
|
||||
RESPONDER_ACTIVE_PRESS_OUT: true,
|
||||
RESPONDER_ACTIVE_PRESS_IN: true
|
||||
RESPONDER_ACTIVE_PRESS_IN: true,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -230,7 +231,7 @@ const Transitions = {
|
||||
ENTER_PRESS_RECT: States.NOT_RESPONDER,
|
||||
LEAVE_PRESS_RECT: States.NOT_RESPONDER,
|
||||
LONG_PRESS_DETECTED: States.NOT_RESPONDER,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// ==== Typical Constants for integrating into UI components ====
|
||||
@@ -324,11 +325,15 @@ const TouchableMixin = {
|
||||
evt.dispatchConfig = {};
|
||||
if (myTag === evt.tag) {
|
||||
if (evt.eventType === 'focus') {
|
||||
cmp.touchableHandleActivePressIn && cmp.touchableHandleActivePressIn(evt);
|
||||
cmp.touchableHandleActivePressIn &&
|
||||
cmp.touchableHandleActivePressIn(evt);
|
||||
} else if (evt.eventType === 'blur') {
|
||||
cmp.touchableHandleActivePressOut && cmp.touchableHandleActivePressOut(evt);
|
||||
cmp.touchableHandleActivePressOut &&
|
||||
cmp.touchableHandleActivePressOut(evt);
|
||||
} else if (evt.eventType === 'select') {
|
||||
cmp.touchableHandlePress && !cmp.props.disabled && cmp.touchableHandlePress(evt);
|
||||
cmp.touchableHandlePress &&
|
||||
!cmp.props.disabled &&
|
||||
cmp.touchableHandlePress(evt);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -356,7 +361,7 @@ const TouchableMixin = {
|
||||
*/
|
||||
touchableGetInitialState: function() {
|
||||
return {
|
||||
touchable: {touchState: undefined, responderID: null}
|
||||
touchable: {touchState: undefined, responderID: null},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -378,7 +383,7 @@ const TouchableMixin = {
|
||||
/**
|
||||
* Return true to cancel press on long press.
|
||||
*/
|
||||
touchableLongPressCancelsPress: function () {
|
||||
touchableLongPressCancelsPress: function() {
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -401,25 +406,27 @@ const TouchableMixin = {
|
||||
this.state.touchable.responderID = dispatchID;
|
||||
this._receiveSignal(Signals.RESPONDER_GRANT, e);
|
||||
let delayMS =
|
||||
this.touchableGetHighlightDelayMS !== undefined ?
|
||||
Math.max(this.touchableGetHighlightDelayMS(), 0) : HIGHLIGHT_DELAY_MS;
|
||||
this.touchableGetHighlightDelayMS !== undefined
|
||||
? Math.max(this.touchableGetHighlightDelayMS(), 0)
|
||||
: HIGHLIGHT_DELAY_MS;
|
||||
delayMS = isNaN(delayMS) ? HIGHLIGHT_DELAY_MS : delayMS;
|
||||
if (delayMS !== 0) {
|
||||
this.touchableDelayTimeout = setTimeout(
|
||||
this._handleDelay.bind(this, e),
|
||||
delayMS
|
||||
delayMS,
|
||||
);
|
||||
} else {
|
||||
this._handleDelay(e);
|
||||
}
|
||||
|
||||
let longDelayMS =
|
||||
this.touchableGetLongPressDelayMS !== undefined ?
|
||||
Math.max(this.touchableGetLongPressDelayMS(), 10) : LONG_PRESS_DELAY_MS;
|
||||
this.touchableGetLongPressDelayMS !== undefined
|
||||
? Math.max(this.touchableGetLongPressDelayMS(), 10)
|
||||
: LONG_PRESS_DELAY_MS;
|
||||
longDelayMS = isNaN(longDelayMS) ? LONG_PRESS_DELAY_MS : longDelayMS;
|
||||
this.longPressDelayTimeout = setTimeout(
|
||||
this._handleLongDelay.bind(this, e),
|
||||
longDelayMS + delayMS
|
||||
longDelayMS + delayMS,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -443,7 +450,9 @@ const TouchableMixin = {
|
||||
touchableHandleResponderMove: function(e) {
|
||||
// Not enough time elapsed yet, wait for highlight -
|
||||
// this is just a perf optimization.
|
||||
if (this.state.touchable.touchState === States.RESPONDER_INACTIVE_PRESS_IN) {
|
||||
if (
|
||||
this.state.touchable.touchState === States.RESPONDER_INACTIVE_PRESS_IN
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -454,21 +463,23 @@ const TouchableMixin = {
|
||||
|
||||
const positionOnActivate = this.state.touchable.positionOnActivate;
|
||||
const dimensionsOnActivate = this.state.touchable.dimensionsOnActivate;
|
||||
const pressRectOffset = this.touchableGetPressRectOffset ?
|
||||
this.touchableGetPressRectOffset() : {
|
||||
left: PRESS_EXPAND_PX,
|
||||
right: PRESS_EXPAND_PX,
|
||||
top: PRESS_EXPAND_PX,
|
||||
bottom: PRESS_EXPAND_PX
|
||||
};
|
||||
const pressRectOffset = this.touchableGetPressRectOffset
|
||||
? this.touchableGetPressRectOffset()
|
||||
: {
|
||||
left: PRESS_EXPAND_PX,
|
||||
right: PRESS_EXPAND_PX,
|
||||
top: PRESS_EXPAND_PX,
|
||||
bottom: PRESS_EXPAND_PX,
|
||||
};
|
||||
|
||||
let pressExpandLeft = pressRectOffset.left;
|
||||
let pressExpandTop = pressRectOffset.top;
|
||||
let pressExpandRight = pressRectOffset.right;
|
||||
let pressExpandBottom = pressRectOffset.bottom;
|
||||
|
||||
const hitSlop = this.touchableGetHitSlop ?
|
||||
this.touchableGetHitSlop() : null;
|
||||
const hitSlop = this.touchableGetHitSlop
|
||||
? this.touchableGetHitSlop()
|
||||
: null;
|
||||
|
||||
if (hitSlop) {
|
||||
pressExpandLeft += hitSlop.left;
|
||||
@@ -482,21 +493,26 @@ const TouchableMixin = {
|
||||
const pageY = touch && touch.pageY;
|
||||
|
||||
if (this.pressInLocation) {
|
||||
const movedDistance = this._getDistanceBetweenPoints(pageX, pageY, this.pressInLocation.pageX, this.pressInLocation.pageY);
|
||||
const movedDistance = this._getDistanceBetweenPoints(
|
||||
pageX,
|
||||
pageY,
|
||||
this.pressInLocation.pageX,
|
||||
this.pressInLocation.pageY,
|
||||
);
|
||||
if (movedDistance > LONG_PRESS_ALLOWED_MOVEMENT) {
|
||||
this._cancelLongPressDelayTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
const isTouchWithinActive =
|
||||
pageX > positionOnActivate.left - pressExpandLeft &&
|
||||
pageY > positionOnActivate.top - pressExpandTop &&
|
||||
pageX <
|
||||
positionOnActivate.left +
|
||||
pageX > positionOnActivate.left - pressExpandLeft &&
|
||||
pageY > positionOnActivate.top - pressExpandTop &&
|
||||
pageX <
|
||||
positionOnActivate.left +
|
||||
dimensionsOnActivate.width +
|
||||
pressExpandRight &&
|
||||
pageY <
|
||||
positionOnActivate.top +
|
||||
pageY <
|
||||
positionOnActivate.top +
|
||||
dimensionsOnActivate.height +
|
||||
pressExpandBottom;
|
||||
if (isTouchWithinActive) {
|
||||
@@ -574,8 +590,6 @@ const TouchableMixin = {
|
||||
* touchableGetPressRectOffset: function
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ==== Internal Logic ====
|
||||
|
||||
/**
|
||||
@@ -608,8 +622,14 @@ const TouchableMixin = {
|
||||
Position.release(this.state.touchable.positionOnActivate);
|
||||
this.state.touchable.dimensionsOnActivate &&
|
||||
BoundingDimensions.release(this.state.touchable.dimensionsOnActivate);
|
||||
this.state.touchable.positionOnActivate = Position.getPooled(globalX, globalY);
|
||||
this.state.touchable.dimensionsOnActivate = BoundingDimensions.getPooled(w, h);
|
||||
this.state.touchable.positionOnActivate = Position.getPooled(
|
||||
globalX,
|
||||
globalY,
|
||||
);
|
||||
this.state.touchable.dimensionsOnActivate = BoundingDimensions.getPooled(
|
||||
w,
|
||||
h,
|
||||
);
|
||||
},
|
||||
|
||||
_handleDelay: function(e) {
|
||||
@@ -620,11 +640,18 @@ const TouchableMixin = {
|
||||
_handleLongDelay: function(e) {
|
||||
this.longPressDelayTimeout = null;
|
||||
const curState = this.state.touchable.touchState;
|
||||
if (curState !== States.RESPONDER_ACTIVE_PRESS_IN &&
|
||||
curState !== States.RESPONDER_ACTIVE_LONG_PRESS_IN) {
|
||||
console.error('Attempted to transition from state `' + curState + '` to `' +
|
||||
States.RESPONDER_ACTIVE_LONG_PRESS_IN + '`, which is not supported. This is ' +
|
||||
'most likely due to `Touchable.longPressDelayTimeout` not being cancelled.');
|
||||
if (
|
||||
curState !== States.RESPONDER_ACTIVE_PRESS_IN &&
|
||||
curState !== States.RESPONDER_ACTIVE_LONG_PRESS_IN
|
||||
) {
|
||||
console.error(
|
||||
'Attempted to transition from state `' +
|
||||
curState +
|
||||
'` to `' +
|
||||
States.RESPONDER_ACTIVE_LONG_PRESS_IN +
|
||||
'`, which is not supported. This is ' +
|
||||
'most likely due to `Touchable.longPressDelayTimeout` not being cancelled.',
|
||||
);
|
||||
} else {
|
||||
this._receiveSignal(Signals.LONG_PRESS_DETECTED, e);
|
||||
}
|
||||
@@ -647,14 +674,24 @@ const TouchableMixin = {
|
||||
}
|
||||
if (!nextState) {
|
||||
throw new Error(
|
||||
'Unrecognized signal `' + signal + '` or state `' + curState +
|
||||
'` for Touchable responder `' + responderID + '`'
|
||||
'Unrecognized signal `' +
|
||||
signal +
|
||||
'` or state `' +
|
||||
curState +
|
||||
'` for Touchable responder `' +
|
||||
responderID +
|
||||
'`',
|
||||
);
|
||||
}
|
||||
if (nextState === States.ERROR) {
|
||||
throw new Error(
|
||||
'Touchable cannot transition from `' + curState + '` to `' + signal +
|
||||
'` for responder `' + responderID + '`'
|
||||
'Touchable cannot transition from `' +
|
||||
curState +
|
||||
'` to `' +
|
||||
signal +
|
||||
'` for responder `' +
|
||||
responderID +
|
||||
'`',
|
||||
);
|
||||
}
|
||||
if (curState !== nextState) {
|
||||
@@ -663,14 +700,16 @@ const TouchableMixin = {
|
||||
}
|
||||
},
|
||||
|
||||
_cancelLongPressDelayTimeout: function () {
|
||||
_cancelLongPressDelayTimeout: function() {
|
||||
this.longPressDelayTimeout && clearTimeout(this.longPressDelayTimeout);
|
||||
this.longPressDelayTimeout = null;
|
||||
},
|
||||
|
||||
_isHighlight: function (state) {
|
||||
return state === States.RESPONDER_ACTIVE_PRESS_IN ||
|
||||
state === States.RESPONDER_ACTIVE_LONG_PRESS_IN;
|
||||
_isHighlight: function(state) {
|
||||
return (
|
||||
state === States.RESPONDER_ACTIVE_PRESS_IN ||
|
||||
state === States.RESPONDER_ACTIVE_LONG_PRESS_IN
|
||||
);
|
||||
},
|
||||
|
||||
_savePressInLocation: function(e) {
|
||||
@@ -682,7 +721,7 @@ const TouchableMixin = {
|
||||
this.pressInLocation = {pageX, pageY, locationX, locationY};
|
||||
},
|
||||
|
||||
_getDistanceBetweenPoints: function (aX, aY, bX, bY) {
|
||||
_getDistanceBetweenPoints: function(aX, aY, bX, bY) {
|
||||
const deltaX = aX - bX;
|
||||
const deltaY = aY - bY;
|
||||
return Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
@@ -728,12 +767,11 @@ const TouchableMixin = {
|
||||
if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) {
|
||||
const hasLongPressHandler = !!this.props.onLongPress;
|
||||
const pressIsLongButStillCallOnPress =
|
||||
IsLongPressingIn[curState] && ( // We *are* long pressing..
|
||||
(// But either has no long handler
|
||||
!hasLongPressHandler || !this.touchableLongPressCancelsPress()) // or we're told to ignore it.
|
||||
);
|
||||
IsLongPressingIn[curState] && // We *are* long pressing.. // But either has no long handler
|
||||
(!hasLongPressHandler || !this.touchableLongPressCancelsPress()); // or we're told to ignore it.
|
||||
|
||||
const shouldInvokePress = !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
|
||||
const shouldInvokePress =
|
||||
!IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
|
||||
if (shouldInvokePress && this.touchableHandlePress) {
|
||||
if (!newIsHighlight && !curIsHighlight) {
|
||||
// we never highlighted because of delay, but we should highlight now
|
||||
@@ -750,11 +788,11 @@ const TouchableMixin = {
|
||||
this.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout);
|
||||
this.touchableDelayTimeout = null;
|
||||
},
|
||||
|
||||
|
||||
_playTouchSound: function() {
|
||||
UIManager.playTouchSound();
|
||||
},
|
||||
|
||||
|
||||
_startHighlight: function(e) {
|
||||
this._savePressInLocation(e);
|
||||
this.touchableHandleActivePressIn && this.touchableHandleActivePressIn(e);
|
||||
@@ -762,7 +800,10 @@ const TouchableMixin = {
|
||||
|
||||
_endHighlight: function(e) {
|
||||
if (this.touchableHandleActivePressOut) {
|
||||
if (this.touchableGetPressOutDelayMS && this.touchableGetPressOutDelayMS()) {
|
||||
if (
|
||||
this.touchableGetPressOutDelayMS &&
|
||||
this.touchableGetPressOutDelayMS()
|
||||
) {
|
||||
this.pressOutDelayTimeout = setTimeout(() => {
|
||||
this.touchableHandleActivePressOut(e);
|
||||
}, this.touchableGetPressOutDelayMS());
|
||||
@@ -771,7 +812,6 @@ const TouchableMixin = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
const Touchable = {
|
||||
@@ -785,14 +825,17 @@ const Touchable = {
|
||||
return null;
|
||||
}
|
||||
if (!__DEV__) {
|
||||
throw Error('Touchable.TOUCH_TARGET_DEBUG should not be enabled in prod!');
|
||||
throw Error(
|
||||
'Touchable.TOUCH_TARGET_DEBUG should not be enabled in prod!',
|
||||
);
|
||||
}
|
||||
const debugHitSlopStyle = {};
|
||||
hitSlop = hitSlop || {top: 0, bottom: 0, left: 0, right: 0};
|
||||
for (const key in hitSlop) {
|
||||
debugHitSlopStyle[key] = -hitSlop[key];
|
||||
}
|
||||
const hexColor = '#' + ('00000000' + normalizeColor(color).toString(16)).substr(-8);
|
||||
const hexColor =
|
||||
'#' + ('00000000' + normalizeColor(color).toString(16)).substr(-8);
|
||||
return (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
@@ -802,11 +845,11 @@ const Touchable = {
|
||||
borderWidth: 1,
|
||||
borderStyle: 'dashed',
|
||||
backgroundColor: hexColor.slice(0, -2) + '0F', // Less opaque
|
||||
...debugHitSlopStyle
|
||||
...debugHitSlopStyle,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = Touchable;
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Platform = require('Platform');
|
||||
@@ -112,7 +114,10 @@ const TouchableNativeFeedback = createReactClass({
|
||||
* Available on android API level 21+.
|
||||
*/
|
||||
SelectableBackgroundBorderless: function() {
|
||||
return {type: 'ThemeAttrAndroid', attribute: 'selectableItemBackgroundBorderless'};
|
||||
return {
|
||||
type: 'ThemeAttrAndroid',
|
||||
attribute: 'selectableItemBackgroundBorderless',
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Creates an object that represents ripple drawable with specified color (as a
|
||||
@@ -125,12 +130,16 @@ const TouchableNativeFeedback = createReactClass({
|
||||
* @param borderless If the ripple can render outside it's bounds
|
||||
*/
|
||||
Ripple: function(color: string, borderless: boolean) {
|
||||
return {type: 'RippleAndroid', color: processColor(color), borderless: borderless};
|
||||
return {
|
||||
type: 'RippleAndroid',
|
||||
color: processColor(color),
|
||||
borderless: borderless,
|
||||
};
|
||||
},
|
||||
|
||||
canUseNativeForeground: function() {
|
||||
return Platform.OS === 'android' && Platform.Version >= 23;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
mixins: [Touchable.Mixin],
|
||||
@@ -161,7 +170,10 @@ const TouchableNativeFeedback = createReactClass({
|
||||
this.props.onPressIn && this.props.onPressIn(e);
|
||||
this._dispatchPressedStateChange(true);
|
||||
if (this.pressInLocation) {
|
||||
this._dispatchHotspotUpdate(this.pressInLocation.locationX, this.pressInLocation.locationY);
|
||||
this._dispatchHotspotUpdate(
|
||||
this.pressInLocation.locationX,
|
||||
this.pressInLocation.locationY,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -201,14 +213,17 @@ const TouchableNativeFeedback = createReactClass({
|
||||
|
||||
_handleResponderMove: function(e) {
|
||||
this.touchableHandleResponderMove(e);
|
||||
this._dispatchHotspotUpdate(e.nativeEvent.locationX, e.nativeEvent.locationY);
|
||||
this._dispatchHotspotUpdate(
|
||||
e.nativeEvent.locationX,
|
||||
e.nativeEvent.locationY,
|
||||
);
|
||||
},
|
||||
|
||||
_dispatchHotspotUpdate: function(destX, destY) {
|
||||
UIManager.dispatchViewManagerCommand(
|
||||
ReactNative.findNodeHandle(this),
|
||||
UIManager.RCTView.Commands.hotspotUpdate,
|
||||
[destX || 0, destY || 0]
|
||||
[destX || 0, destY || 0],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -216,7 +231,7 @@ const TouchableNativeFeedback = createReactClass({
|
||||
UIManager.dispatchViewManagerCommand(
|
||||
ReactNative.findNodeHandle(this),
|
||||
UIManager.RCTView.Commands.setPressed,
|
||||
[pressed]
|
||||
[pressed],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -227,16 +242,26 @@ const TouchableNativeFeedback = createReactClass({
|
||||
if (!Array.isArray(children)) {
|
||||
children = [children];
|
||||
}
|
||||
children.push(Touchable.renderDebugView({color: 'brown', hitSlop: this.props.hitSlop}));
|
||||
children.push(
|
||||
Touchable.renderDebugView({
|
||||
color: 'brown',
|
||||
hitSlop: this.props.hitSlop,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (this.props.useForeground && !TouchableNativeFeedback.canUseNativeForeground()) {
|
||||
if (
|
||||
this.props.useForeground &&
|
||||
!TouchableNativeFeedback.canUseNativeForeground()
|
||||
) {
|
||||
console.warn(
|
||||
'Requested foreground ripple, but it is not available on this version of Android. ' +
|
||||
'Consider calling TouchableNativeFeedback.canUseNativeForeground() and using a different ' +
|
||||
'Touchable if the result is false.');
|
||||
'Consider calling TouchableNativeFeedback.canUseNativeForeground() and using a different ' +
|
||||
'Touchable if the result is false.',
|
||||
);
|
||||
}
|
||||
const drawableProp =
|
||||
this.props.useForeground && TouchableNativeFeedback.canUseNativeForeground()
|
||||
this.props.useForeground &&
|
||||
TouchableNativeFeedback.canUseNativeForeground()
|
||||
? 'nativeForegroundAndroid'
|
||||
: 'nativeBackgroundAndroid';
|
||||
const childProps = {
|
||||
@@ -253,7 +278,8 @@ const TouchableNativeFeedback = createReactClass({
|
||||
isTVSelectable: true,
|
||||
hasTVPreferredFocus: this.props.hasTVPreferredFocus,
|
||||
onStartShouldSetResponder: this.touchableHandleStartShouldSetResponder,
|
||||
onResponderTerminationRequest: this.touchableHandleResponderTerminationRequest,
|
||||
onResponderTerminationRequest: this
|
||||
.touchableHandleResponderTerminationRequest,
|
||||
onResponderGrant: this.touchableHandleResponderGrant,
|
||||
onResponderMove: this._handleResponderMove,
|
||||
onResponderRelease: this.touchableHandleResponderRelease,
|
||||
@@ -263,11 +289,8 @@ const TouchableNativeFeedback = createReactClass({
|
||||
// We need to clone the actual element so that the ripple background drawable
|
||||
// can be applied directly to the background of this element rather than to
|
||||
// a wrapper view as done in other Touchable*
|
||||
return React.cloneElement(
|
||||
child,
|
||||
childProps
|
||||
);
|
||||
}
|
||||
return React.cloneElement(child, childProps);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = TouchableNativeFeedback;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -22,7 +23,9 @@ class DummyTouchableNativeFeedback extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<View style={[styles.container, this.props.style]}>
|
||||
<Text style={styles.info}>TouchableNativeFeedback is not supported on this platform!</Text>
|
||||
<Text style={styles.info}>
|
||||
TouchableNativeFeedback is not supported on this platform!
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -42,7 +45,7 @@ const styles = StyleSheet.create({
|
||||
info: {
|
||||
color: '#333333',
|
||||
margin: 20,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = DummyTouchableNativeFeedback;
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @noflow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Note (avik): add @flow when Flow supports spread properties in propTypes
|
||||
@@ -167,15 +169,12 @@ const TouchableOpacity = createReactClass({
|
||||
* Animate the touchable to a new opacity.
|
||||
*/
|
||||
setOpacityTo: function(value: number, duration: number) {
|
||||
Animated.timing(
|
||||
this.state.anim,
|
||||
{
|
||||
toValue: value,
|
||||
duration: duration,
|
||||
easing: Easing.inOut(Easing.quad),
|
||||
useNativeDriver: true,
|
||||
}
|
||||
).start();
|
||||
Animated.timing(this.state.anim, {
|
||||
toValue: value,
|
||||
duration: duration,
|
||||
easing: Easing.inOut(Easing.quad),
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -217,8 +216,9 @@ const TouchableOpacity = createReactClass({
|
||||
},
|
||||
|
||||
touchableGetLongPressDelayMS: function() {
|
||||
return this.props.delayLongPress === 0 ? 0 :
|
||||
this.props.delayLongPress || 500;
|
||||
return this.props.delayLongPress === 0
|
||||
? 0
|
||||
: this.props.delayLongPress || 500;
|
||||
},
|
||||
|
||||
touchableGetPressOutDelayMS: function() {
|
||||
@@ -230,16 +230,13 @@ const TouchableOpacity = createReactClass({
|
||||
},
|
||||
|
||||
_opacityInactive: function(duration: number) {
|
||||
this.setOpacityTo(
|
||||
this._getChildStyleOpacityWithDefault(),
|
||||
duration
|
||||
);
|
||||
this.setOpacityTo(this._getChildStyleOpacityWithDefault(), duration);
|
||||
},
|
||||
|
||||
_getChildStyleOpacityWithDefault: function() {
|
||||
const childStyle = flattenStyle(this.props.style) || {};
|
||||
return childStyle.opacity == undefined ? 1 : childStyle.opacity;
|
||||
},
|
||||
const childStyle = flattenStyle(this.props.style) || {};
|
||||
return childStyle.opacity == undefined ? 1 : childStyle.opacity;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return (
|
||||
@@ -257,13 +254,18 @@ const TouchableOpacity = createReactClass({
|
||||
tvParallaxProperties={this.props.tvParallaxProperties}
|
||||
hitSlop={this.props.hitSlop}
|
||||
onStartShouldSetResponder={this.touchableHandleStartShouldSetResponder}
|
||||
onResponderTerminationRequest={this.touchableHandleResponderTerminationRequest}
|
||||
onResponderTerminationRequest={
|
||||
this.touchableHandleResponderTerminationRequest
|
||||
}
|
||||
onResponderGrant={this.touchableHandleResponderGrant}
|
||||
onResponderMove={this.touchableHandleResponderMove}
|
||||
onResponderRelease={this.touchableHandleResponderRelease}
|
||||
onResponderTerminate={this.touchableHandleResponderTerminate}>
|
||||
{this.props.children}
|
||||
{Touchable.renderDebugView({color: 'cyan', hitSlop: this.props.hitSlop})}
|
||||
{Touchable.renderDebugView({
|
||||
color: 'cyan',
|
||||
hitSlop: this.props.hitSlop,
|
||||
})}
|
||||
</Animated.View>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const EdgeInsetsPropType = require('EdgeInsetsPropType');
|
||||
@@ -46,9 +48,7 @@ const TouchableWithoutFeedback = createReactClass({
|
||||
|
||||
propTypes: {
|
||||
accessible: PropTypes.bool,
|
||||
accessibilityComponentType: PropTypes.oneOf(
|
||||
AccessibilityComponentTypes
|
||||
),
|
||||
accessibilityComponentType: PropTypes.oneOf(AccessibilityComponentTypes),
|
||||
accessibilityTraits: PropTypes.oneOfType([
|
||||
PropTypes.oneOf(AccessibilityTraits),
|
||||
PropTypes.arrayOf(PropTypes.oneOf(AccessibilityTraits)),
|
||||
@@ -63,14 +63,14 @@ const TouchableWithoutFeedback = createReactClass({
|
||||
*/
|
||||
onPress: PropTypes.func,
|
||||
/**
|
||||
* Called as soon as the touchable element is pressed and invoked even before onPress.
|
||||
* This can be useful when making network requests.
|
||||
*/
|
||||
* Called as soon as the touchable element is pressed and invoked even before onPress.
|
||||
* This can be useful when making network requests.
|
||||
*/
|
||||
onPressIn: PropTypes.func,
|
||||
/**
|
||||
* Called as soon as the touch is released even before onPress.
|
||||
*/
|
||||
onPressOut: PropTypes.func,
|
||||
* Called as soon as the touch is released even before onPress.
|
||||
*/
|
||||
onPressOut: PropTypes.func,
|
||||
/**
|
||||
* Invoked on mount and layout changes with
|
||||
*
|
||||
@@ -156,8 +156,9 @@ const TouchableWithoutFeedback = createReactClass({
|
||||
},
|
||||
|
||||
touchableGetLongPressDelayMS: function(): number {
|
||||
return this.props.delayLongPress === 0 ? 0 :
|
||||
this.props.delayLongPress || 500;
|
||||
return this.props.delayLongPress === 0
|
||||
? 0
|
||||
: this.props.delayLongPress || 500;
|
||||
},
|
||||
|
||||
touchableGetPressOutDelayMS: function(): number {
|
||||
@@ -172,15 +173,25 @@ const TouchableWithoutFeedback = createReactClass({
|
||||
warning(
|
||||
!child.type || child.type.displayName !== 'Text',
|
||||
'TouchableWithoutFeedback does not work well with Text children. Wrap children in a View instead. See ' +
|
||||
((child._owner && child._owner.getName && child._owner.getName()) || '<unknown>')
|
||||
((child._owner && child._owner.getName && child._owner.getName()) ||
|
||||
'<unknown>'),
|
||||
);
|
||||
if (Touchable.TOUCH_TARGET_DEBUG && child.type && child.type.displayName === 'View') {
|
||||
if (
|
||||
Touchable.TOUCH_TARGET_DEBUG &&
|
||||
child.type &&
|
||||
child.type.displayName === 'View'
|
||||
) {
|
||||
children = React.Children.toArray(children);
|
||||
children.push(Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop}));
|
||||
children.push(
|
||||
Touchable.renderDebugView({color: 'red', hitSlop: this.props.hitSlop}),
|
||||
);
|
||||
}
|
||||
const style = (Touchable.TOUCH_TARGET_DEBUG && child.type && child.type.displayName === 'Text') ?
|
||||
[child.props.style, {color: 'red'}] :
|
||||
child.props.style;
|
||||
const style =
|
||||
Touchable.TOUCH_TARGET_DEBUG &&
|
||||
child.type &&
|
||||
child.type.displayName === 'Text'
|
||||
? [child.props.style, {color: 'red'}]
|
||||
: child.props.style;
|
||||
return (React: any).cloneElement(child, {
|
||||
accessible: this.props.accessible !== false,
|
||||
accessibilityLabel: this.props.accessibilityLabel,
|
||||
@@ -191,7 +202,8 @@ const TouchableWithoutFeedback = createReactClass({
|
||||
onLayout: this.props.onLayout,
|
||||
hitSlop: this.props.hitSlop,
|
||||
onStartShouldSetResponder: this.touchableHandleStartShouldSetResponder,
|
||||
onResponderTerminationRequest: this.touchableHandleResponderTerminationRequest,
|
||||
onResponderTerminationRequest: this
|
||||
.touchableHandleResponderTerminationRequest,
|
||||
onResponderGrant: this.touchableHandleResponderGrant,
|
||||
onResponderMove: this.touchableHandleResponderMove,
|
||||
onResponderRelease: this.touchableHandleResponderRelease,
|
||||
@@ -199,7 +211,7 @@ const TouchableWithoutFeedback = createReactClass({
|
||||
style,
|
||||
children,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = TouchableWithoutFeedback;
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = () => true;
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @emails oncall+react_native
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const React = require('React');
|
||||
@@ -18,7 +20,7 @@ describe('TouchableHighlight', () => {
|
||||
const instance = ReactTestRenderer.create(
|
||||
<TouchableHighlight style={{}}>
|
||||
<Text>Touchable</Text>
|
||||
</TouchableHighlight>
|
||||
</TouchableHighlight>,
|
||||
);
|
||||
|
||||
expect(instance.toJSON()).toMatchSnapshot();
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
@@ -14,7 +16,7 @@ const ensureComponentIsNative = function(component: any) {
|
||||
invariant(
|
||||
component && typeof component.setNativeProps === 'function',
|
||||
'Touchable child must either be native or forward setNativeProps to a ' +
|
||||
'native component'
|
||||
'native component',
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,17 +4,22 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
const ensurePositiveDelayProps = function(props: any) {
|
||||
invariant(
|
||||
!(props.delayPressIn < 0 || props.delayPressOut < 0 ||
|
||||
props.delayLongPress < 0),
|
||||
'Touchable components cannot have negative delay properties'
|
||||
!(
|
||||
props.delayPressIn < 0 ||
|
||||
props.delayPressOut < 0 ||
|
||||
props.delayLongPress < 0
|
||||
),
|
||||
'Touchable components cannot have negative delay properties',
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user