mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-03-29 00:38:18 +08:00
Misc flow and lint fixes
This commit is contained in:
@@ -6,14 +6,16 @@
|
||||
|
||||
import TouchHistoryMath from '../../vendor/TouchHistoryMath';
|
||||
|
||||
var currentCentroidXOfTouchesChangedAfter = TouchHistoryMath.currentCentroidXOfTouchesChangedAfter;
|
||||
var currentCentroidYOfTouchesChangedAfter = TouchHistoryMath.currentCentroidYOfTouchesChangedAfter;
|
||||
var previousCentroidXOfTouchesChangedAfter =
|
||||
const currentCentroidXOfTouchesChangedAfter =
|
||||
TouchHistoryMath.currentCentroidXOfTouchesChangedAfter;
|
||||
const currentCentroidYOfTouchesChangedAfter =
|
||||
TouchHistoryMath.currentCentroidYOfTouchesChangedAfter;
|
||||
const previousCentroidXOfTouchesChangedAfter =
|
||||
TouchHistoryMath.previousCentroidXOfTouchesChangedAfter;
|
||||
var previousCentroidYOfTouchesChangedAfter =
|
||||
const previousCentroidYOfTouchesChangedAfter =
|
||||
TouchHistoryMath.previousCentroidYOfTouchesChangedAfter;
|
||||
var currentCentroidX = TouchHistoryMath.currentCentroidX;
|
||||
var currentCentroidY = TouchHistoryMath.currentCentroidY;
|
||||
const currentCentroidX = TouchHistoryMath.currentCentroidX;
|
||||
const currentCentroidY = TouchHistoryMath.currentCentroidY;
|
||||
|
||||
/**
|
||||
* `PanResponder` reconciles several touches into a single gesture. It makes
|
||||
@@ -110,7 +112,7 @@ var currentCentroidY = TouchHistoryMath.currentCentroidY;
|
||||
* [PanResponder example in UIExplorer](https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/PanResponderExample.js)
|
||||
*/
|
||||
|
||||
var PanResponder = {
|
||||
const PanResponder = {
|
||||
/**
|
||||
*
|
||||
* A graphical explanation of the touch data flow:
|
||||
@@ -222,16 +224,16 @@ var PanResponder = {
|
||||
touchHistory,
|
||||
gestureState._accountsForMovesUpTo
|
||||
);
|
||||
var movedAfter = gestureState._accountsForMovesUpTo;
|
||||
var prevX = previousCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
var x = currentCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
var prevY = previousCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
var y = currentCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
var nextDX = gestureState.dx + (x - prevX);
|
||||
var nextDY = gestureState.dy + (y - prevY);
|
||||
const movedAfter = gestureState._accountsForMovesUpTo;
|
||||
const prevX = previousCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
const x = currentCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
const prevY = previousCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
const y = currentCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
|
||||
const nextDX = gestureState.dx + (x - prevX);
|
||||
const nextDY = gestureState.dy + (y - prevY);
|
||||
|
||||
// TODO: This must be filtered intelligently.
|
||||
var dt = touchHistory.mostRecentTimeStamp - gestureState._accountsForMovesUpTo;
|
||||
const dt = touchHistory.mostRecentTimeStamp - gestureState._accountsForMovesUpTo;
|
||||
gestureState.vx = (nextDX - gestureState.dx) / dt;
|
||||
gestureState.vy = (nextDY - gestureState.dy) / dt;
|
||||
|
||||
@@ -273,12 +275,12 @@ var PanResponder = {
|
||||
* are the responder.
|
||||
*/
|
||||
create: function(config) {
|
||||
var gestureState = {
|
||||
const gestureState = {
|
||||
// Useful for debugging
|
||||
stateID: Math.random()
|
||||
};
|
||||
PanResponder._initializeGestureState(gestureState);
|
||||
var panHandlers = {
|
||||
const panHandlers = {
|
||||
onStartShouldSetResponder: function(e) {
|
||||
return config.onStartShouldSetPanResponder === undefined
|
||||
? false
|
||||
@@ -309,7 +311,7 @@ var PanResponder = {
|
||||
},
|
||||
|
||||
onMoveShouldSetResponderCapture: function(e) {
|
||||
var touchHistory = e.touchHistory;
|
||||
const touchHistory = e.touchHistory;
|
||||
// Responder system incorrectly dispatches should* to current responder
|
||||
// Filter out any touch moves past the first one - we would have
|
||||
// already processed multi-touch geometry during the first event.
|
||||
@@ -344,13 +346,13 @@ var PanResponder = {
|
||||
},
|
||||
|
||||
onResponderStart: function(e) {
|
||||
var touchHistory = e.touchHistory;
|
||||
const touchHistory = e.touchHistory;
|
||||
gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
|
||||
config.onPanResponderStart && config.onPanResponderStart(e, gestureState);
|
||||
},
|
||||
|
||||
onResponderMove: function(e) {
|
||||
var touchHistory = e.touchHistory;
|
||||
const touchHistory = e.touchHistory;
|
||||
// Guard against the dispatch of two touch moves when there are two
|
||||
// simultaneously changed touches.
|
||||
if (gestureState._accountsForMovesUpTo === touchHistory.mostRecentTimeStamp) {
|
||||
@@ -363,7 +365,7 @@ var PanResponder = {
|
||||
},
|
||||
|
||||
onResponderEnd: function(e) {
|
||||
var touchHistory = e.touchHistory;
|
||||
const touchHistory = e.touchHistory;
|
||||
gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
|
||||
config.onPanResponderEnd && config.onPanResponderEnd(e, gestureState);
|
||||
},
|
||||
|
||||
@@ -34,6 +34,9 @@ const pointerEventsCss =
|
||||
`.${pointerEvents.boxOnly} > *{pointer-events:none;}`;
|
||||
|
||||
export default class StyleManager {
|
||||
cache = null;
|
||||
mainSheet = null;
|
||||
|
||||
constructor() {
|
||||
// custom pointer event values are implemented using descendent selectors,
|
||||
// so we manually create the CSS and pre-register the declarations
|
||||
|
||||
@@ -21,10 +21,8 @@ const createCacheKey = id => {
|
||||
const classListToString = list => list.join(' ').trim();
|
||||
|
||||
export default class StyleRegistry {
|
||||
constructor() {
|
||||
this.cache = { ltr: {}, rtl: {} };
|
||||
this.styleManager = new StyleManager();
|
||||
}
|
||||
cache = { ltr: {}, rtl: {} };
|
||||
styleManager = new StyleManager();
|
||||
|
||||
getStyleSheets() {
|
||||
return this.styleManager.getStyleSheets();
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2016-present, Nicolas Gallagher.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @noflow
|
||||
*/
|
||||
|
||||
import unitlessNumbers from '../../modules/unitlessNumbers';
|
||||
|
||||
const normalizeValue = (property, value) => {
|
||||
const normalizeValue = (property: string, value) => {
|
||||
if (!unitlessNumbers[property] && typeof value === 'number') {
|
||||
value = `${value}px`;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* Copyright (c) 2015-present, Nicolas Gallagher.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import PooledClass from '../../vendor/PooledClass';
|
||||
|
||||
var twoArgumentPooler = PooledClass.twoArgumentPooler;
|
||||
const twoArgumentPooler = PooledClass.twoArgumentPooler;
|
||||
|
||||
/**
|
||||
* PooledClass representing the bounding rectangle of a region.
|
||||
*
|
||||
* @param {number} width Width of bounding rectangle.
|
||||
* @param {number} height Height of bounding rectangle.
|
||||
* @constructor BoundingDimensions
|
||||
*/
|
||||
function BoundingDimensions(width, height) {
|
||||
function BoundingDimensions(width: number, height: number) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import PooledClass from '../../vendor/PooledClass';
|
||||
|
||||
var twoArgumentPooler = PooledClass.twoArgumentPooler;
|
||||
const twoArgumentPooler = PooledClass.twoArgumentPooler;
|
||||
|
||||
/**
|
||||
* Position does not expose methods for construction via an `HTMLDOMElement`,
|
||||
|
||||
@@ -108,7 +108,7 @@ import View from '../../components/View';
|
||||
/**
|
||||
* Touchable states.
|
||||
*/
|
||||
var States = {
|
||||
const States = {
|
||||
NOT_RESPONDER: 'NOT_RESPONDER', // Not the responder
|
||||
RESPONDER_INACTIVE_PRESS_IN: 'RESPONDER_INACTIVE_PRESS_IN', // Responder, inactive, in the `PressRect`
|
||||
RESPONDER_INACTIVE_PRESS_OUT: 'RESPONDER_INACTIVE_PRESS_OUT', // Responder, inactive, out of `PressRect`
|
||||
@@ -122,7 +122,7 @@ var States = {
|
||||
/**
|
||||
* Quick lookup map for states that are considered to be "active"
|
||||
*/
|
||||
var IsActive = {
|
||||
const IsActive = {
|
||||
RESPONDER_ACTIVE_PRESS_OUT: true,
|
||||
RESPONDER_ACTIVE_PRESS_IN: true
|
||||
};
|
||||
@@ -131,20 +131,20 @@ var IsActive = {
|
||||
* Quick lookup for states that are considered to be "pressing" and are
|
||||
* therefore eligible to result in a "selection" if the press stops.
|
||||
*/
|
||||
var IsPressingIn = {
|
||||
const IsPressingIn = {
|
||||
RESPONDER_INACTIVE_PRESS_IN: true,
|
||||
RESPONDER_ACTIVE_PRESS_IN: true,
|
||||
RESPONDER_ACTIVE_LONG_PRESS_IN: true
|
||||
};
|
||||
|
||||
var IsLongPressingIn = {
|
||||
const IsLongPressingIn = {
|
||||
RESPONDER_ACTIVE_LONG_PRESS_IN: true
|
||||
};
|
||||
|
||||
/**
|
||||
* Inputs to the state machine.
|
||||
*/
|
||||
var Signals = {
|
||||
const Signals = {
|
||||
DELAY: 'DELAY',
|
||||
RESPONDER_GRANT: 'RESPONDER_GRANT',
|
||||
RESPONDER_RELEASE: 'RESPONDER_RELEASE',
|
||||
@@ -157,7 +157,7 @@ var Signals = {
|
||||
/**
|
||||
* Mapping from States x Signals => States
|
||||
*/
|
||||
var Transitions = {
|
||||
const Transitions = {
|
||||
NOT_RESPONDER: {
|
||||
DELAY: States.ERROR,
|
||||
RESPONDER_GRANT: States.RESPONDER_INACTIVE_PRESS_IN,
|
||||
@@ -235,15 +235,15 @@ var Transitions = {
|
||||
// ==== Typical Constants for integrating into UI components ====
|
||||
// var HIT_EXPAND_PX = 20;
|
||||
// var HIT_VERT_OFFSET_PX = 10;
|
||||
var HIGHLIGHT_DELAY_MS = 130;
|
||||
const HIGHLIGHT_DELAY_MS = 130;
|
||||
|
||||
var PRESS_EXPAND_PX = 20;
|
||||
const PRESS_EXPAND_PX = 20;
|
||||
|
||||
var LONG_PRESS_THRESHOLD = 500;
|
||||
const LONG_PRESS_THRESHOLD = 500;
|
||||
|
||||
var LONG_PRESS_DELAY_MS = LONG_PRESS_THRESHOLD - HIGHLIGHT_DELAY_MS;
|
||||
const LONG_PRESS_DELAY_MS = LONG_PRESS_THRESHOLD - HIGHLIGHT_DELAY_MS;
|
||||
|
||||
var LONG_PRESS_ALLOWED_MOVEMENT = 10;
|
||||
const LONG_PRESS_ALLOWED_MOVEMENT = 10;
|
||||
|
||||
// Default amount "active" region protrudes beyond box
|
||||
|
||||
@@ -311,7 +311,7 @@ var LONG_PRESS_ALLOWED_MOVEMENT = 10;
|
||||
*
|
||||
* @lends Touchable.prototype
|
||||
*/
|
||||
var TouchableMixin = {
|
||||
const TouchableMixin = {
|
||||
/**
|
||||
* Clear all timeouts on unmount
|
||||
*/
|
||||
@@ -362,7 +362,7 @@ var TouchableMixin = {
|
||||
*
|
||||
*/
|
||||
touchableHandleResponderGrant: function(e) {
|
||||
var dispatchID = e.currentTarget;
|
||||
const dispatchID = e.currentTarget;
|
||||
// Since e is used in a callback invoked on another event loop
|
||||
// (as in setTimeout etc), we need to call e.persist() on the
|
||||
// event to make sure it doesn't get reused in the event object pool.
|
||||
@@ -374,7 +374,7 @@ var TouchableMixin = {
|
||||
this.state.touchable.touchState = States.NOT_RESPONDER;
|
||||
this.state.touchable.responderID = dispatchID;
|
||||
this._receiveSignal(Signals.RESPONDER_GRANT, e);
|
||||
var delayMS = this.touchableGetHighlightDelayMS !== undefined
|
||||
let delayMS = this.touchableGetHighlightDelayMS !== undefined
|
||||
? Math.max(this.touchableGetHighlightDelayMS(), 0)
|
||||
: HIGHLIGHT_DELAY_MS;
|
||||
delayMS = isNaN(delayMS) ? HIGHLIGHT_DELAY_MS : delayMS;
|
||||
@@ -384,7 +384,7 @@ var TouchableMixin = {
|
||||
this._handleDelay(e);
|
||||
}
|
||||
|
||||
var longDelayMS = this.touchableGetLongPressDelayMS !== undefined
|
||||
let longDelayMS = this.touchableGetLongPressDelayMS !== undefined
|
||||
? Math.max(this.touchableGetLongPressDelayMS(), 10)
|
||||
: LONG_PRESS_DELAY_MS;
|
||||
longDelayMS = isNaN(longDelayMS) ? LONG_PRESS_DELAY_MS : longDelayMS;
|
||||
@@ -430,9 +430,9 @@ var TouchableMixin = {
|
||||
return;
|
||||
}
|
||||
|
||||
var positionOnActivate = this.state.touchable.positionOnActivate;
|
||||
var dimensionsOnActivate = this.state.touchable.dimensionsOnActivate;
|
||||
var pressRectOffset = this.touchableGetPressRectOffset
|
||||
const positionOnActivate = this.state.touchable.positionOnActivate;
|
||||
const dimensionsOnActivate = this.state.touchable.dimensionsOnActivate;
|
||||
const pressRectOffset = this.touchableGetPressRectOffset
|
||||
? this.touchableGetPressRectOffset()
|
||||
: {
|
||||
left: PRESS_EXPAND_PX,
|
||||
@@ -441,12 +441,12 @@ var TouchableMixin = {
|
||||
bottom: PRESS_EXPAND_PX
|
||||
};
|
||||
|
||||
var pressExpandLeft = pressRectOffset.left;
|
||||
var pressExpandTop = pressRectOffset.top;
|
||||
var pressExpandRight = pressRectOffset.right;
|
||||
var pressExpandBottom = pressRectOffset.bottom;
|
||||
let pressExpandLeft = pressRectOffset.left;
|
||||
let pressExpandTop = pressRectOffset.top;
|
||||
let pressExpandRight = pressRectOffset.right;
|
||||
let pressExpandBottom = pressRectOffset.bottom;
|
||||
|
||||
var hitSlop = this.touchableGetHitSlop ? this.touchableGetHitSlop() : null;
|
||||
const hitSlop = this.touchableGetHitSlop ? this.touchableGetHitSlop() : null;
|
||||
|
||||
if (hitSlop) {
|
||||
pressExpandLeft += hitSlop.left;
|
||||
@@ -455,12 +455,12 @@ var TouchableMixin = {
|
||||
pressExpandBottom += hitSlop.bottom;
|
||||
}
|
||||
|
||||
var touch = TouchEventUtils.extractSingleTouch(e.nativeEvent);
|
||||
var pageX = touch && touch.pageX;
|
||||
var pageY = touch && touch.pageY;
|
||||
const touch = TouchEventUtils.extractSingleTouch(e.nativeEvent);
|
||||
const pageX = touch && touch.pageX;
|
||||
const pageY = touch && touch.pageY;
|
||||
|
||||
if (this.pressInLocation) {
|
||||
var movedDistance = this._getDistanceBetweenPoints(
|
||||
const movedDistance = this._getDistanceBetweenPoints(
|
||||
pageX,
|
||||
pageY,
|
||||
this.pressInLocation.pageX,
|
||||
@@ -471,14 +471,14 @@ var TouchableMixin = {
|
||||
}
|
||||
}
|
||||
|
||||
var isTouchWithinActive =
|
||||
const isTouchWithinActive =
|
||||
pageX > positionOnActivate.left - pressExpandLeft &&
|
||||
pageY > positionOnActivate.top - pressExpandTop &&
|
||||
pageX < positionOnActivate.left + dimensionsOnActivate.width + pressExpandRight &&
|
||||
pageY < positionOnActivate.top + dimensionsOnActivate.height + pressExpandBottom;
|
||||
if (isTouchWithinActive) {
|
||||
this._receiveSignal(Signals.ENTER_PRESS_RECT, e);
|
||||
var curState = this.state.touchable.touchState;
|
||||
const curState = this.state.touchable.touchState;
|
||||
if (curState === States.RESPONDER_INACTIVE_PRESS_IN) {
|
||||
// fix for t7967420
|
||||
this._cancelLongPressDelayTimeout();
|
||||
@@ -590,7 +590,7 @@ var TouchableMixin = {
|
||||
|
||||
_handleLongDelay: function(e) {
|
||||
this.longPressDelayTimeout = null;
|
||||
var curState = this.state.touchable.touchState;
|
||||
const curState = this.state.touchable.touchState;
|
||||
if (
|
||||
curState !== States.RESPONDER_ACTIVE_PRESS_IN &&
|
||||
curState !== States.RESPONDER_ACTIVE_LONG_PRESS_IN
|
||||
@@ -617,9 +617,9 @@ var TouchableMixin = {
|
||||
* @sideeffects
|
||||
*/
|
||||
_receiveSignal: function(signal, e) {
|
||||
var responderID = this.state.touchable.responderID;
|
||||
var curState = this.state.touchable.touchState;
|
||||
var nextState = Transitions[curState] && Transitions[curState][signal];
|
||||
const responderID = this.state.touchable.responderID;
|
||||
const curState = this.state.touchable.touchState;
|
||||
const nextState = Transitions[curState] && Transitions[curState][signal];
|
||||
if (!responderID && signal === Signals.RESPONDER_RELEASE) {
|
||||
return;
|
||||
}
|
||||
@@ -663,17 +663,17 @@ var TouchableMixin = {
|
||||
},
|
||||
|
||||
_savePressInLocation: function(e) {
|
||||
var touch = TouchEventUtils.extractSingleTouch(e.nativeEvent);
|
||||
var pageX = touch && touch.pageX;
|
||||
var pageY = touch && touch.pageY;
|
||||
var locationX = touch && touch.locationX;
|
||||
var locationY = touch && touch.locationY;
|
||||
const touch = TouchEventUtils.extractSingleTouch(e.nativeEvent);
|
||||
const pageX = touch && touch.pageX;
|
||||
const pageY = touch && touch.pageY;
|
||||
const locationX = touch && touch.locationX;
|
||||
const locationY = touch && touch.locationY;
|
||||
this.pressInLocation = { pageX, pageY, locationX, locationY };
|
||||
},
|
||||
|
||||
_getDistanceBetweenPoints: function(aX, aY, bX, bY) {
|
||||
var deltaX = aX - bX;
|
||||
var deltaY = aY - bY;
|
||||
const deltaX = aX - bX;
|
||||
const deltaY = aY - bY;
|
||||
return Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
},
|
||||
|
||||
@@ -689,10 +689,10 @@ var TouchableMixin = {
|
||||
* @sideeffects
|
||||
*/
|
||||
_performSideEffectsForTransition: function(curState, nextState, signal, e) {
|
||||
var curIsHighlight = this._isHighlight(curState);
|
||||
var newIsHighlight = this._isHighlight(nextState);
|
||||
const curIsHighlight = this._isHighlight(curState);
|
||||
const newIsHighlight = this._isHighlight(nextState);
|
||||
|
||||
var isFinalSignal =
|
||||
const isFinalSignal =
|
||||
signal === Signals.RESPONDER_TERMINATED || signal === Signals.RESPONDER_RELEASE;
|
||||
|
||||
if (isFinalSignal) {
|
||||
@@ -714,13 +714,13 @@ var TouchableMixin = {
|
||||
}
|
||||
|
||||
if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) {
|
||||
var hasLongPressHandler = !!this.props.onLongPress;
|
||||
var pressIsLongButStillCallOnPress =
|
||||
const hasLongPressHandler = !!this.props.onLongPress;
|
||||
const pressIsLongButStillCallOnPress =
|
||||
IsLongPressingIn[curState] && // We *are* long pressing..
|
||||
(!hasLongPressHandler || // But either has no long handler
|
||||
!this.touchableLongPressCancelsPress()); // or we're told to ignore it.
|
||||
|
||||
var 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
|
||||
|
||||
@@ -28,12 +28,12 @@ import { func, number } from 'prop-types';
|
||||
|
||||
type Event = Object;
|
||||
|
||||
var DEFAULT_PROPS = {
|
||||
const DEFAULT_PROPS = {
|
||||
activeOpacity: 0.85,
|
||||
underlayColor: 'black'
|
||||
};
|
||||
|
||||
var PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
const PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
|
||||
/**
|
||||
* A wrapper for making views respond properly to touches.
|
||||
@@ -62,7 +62,7 @@ var PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
* > If you wish to have several child components, wrap them in a View.
|
||||
*/
|
||||
|
||||
var TouchableHighlight = createReactClass({
|
||||
const TouchableHighlight = createReactClass({
|
||||
propTypes: {
|
||||
...TouchableWithoutFeedback.propTypes,
|
||||
/**
|
||||
@@ -227,7 +227,7 @@ var TouchableHighlight = createReactClass({
|
||||
},
|
||||
|
||||
_onKeyEnter(e, callback) {
|
||||
var ENTER = 13;
|
||||
const ENTER = 13;
|
||||
if ((e.type === 'keypress' ? e.charCode : e.keyCode) === ENTER) {
|
||||
callback && callback(e);
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -22,11 +22,11 @@ import Touchable from './Touchable';
|
||||
import TouchableWithoutFeedback from './TouchableWithoutFeedback';
|
||||
import View from '../View';
|
||||
|
||||
var flattenStyle = StyleSheet.flatten;
|
||||
const flattenStyle = StyleSheet.flatten;
|
||||
|
||||
type Event = Object;
|
||||
|
||||
var PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
const PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
|
||||
/**
|
||||
* A wrapper for making views respond properly to touches.
|
||||
@@ -49,7 +49,7 @@ var PRESS_RETENTION_OFFSET = { top: 20, left: 20, right: 20, bottom: 30 };
|
||||
* },
|
||||
* ```
|
||||
*/
|
||||
var TouchableOpacity = createReactClass({
|
||||
const TouchableOpacity = createReactClass({
|
||||
mixins: [TimerMixin, Touchable.Mixin, NativeMethodsMixin],
|
||||
|
||||
propTypes: {
|
||||
@@ -141,7 +141,7 @@ var TouchableOpacity = createReactClass({
|
||||
},
|
||||
|
||||
_opacityInactive: function(duration: number) {
|
||||
var childStyle = flattenStyle(this.props.style) || {};
|
||||
const childStyle = flattenStyle(this.props.style) || {};
|
||||
this.setOpacityTo(childStyle.opacity === undefined ? 1 : childStyle.opacity, duration);
|
||||
},
|
||||
|
||||
@@ -150,7 +150,7 @@ var TouchableOpacity = createReactClass({
|
||||
},
|
||||
|
||||
_onKeyEnter(e, callback) {
|
||||
var ENTER = 13;
|
||||
const ENTER = 13;
|
||||
if ((e.type === 'keypress' ? e.charCode : e.keyCode) === ENTER) {
|
||||
callback && callback(e);
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -16,7 +16,7 @@ import invariant from 'fbjs/lib/invariant';
|
||||
const ensureComponentIsNative = (component: any) => {
|
||||
invariant(
|
||||
component && typeof component.setNativeProps === 'function',
|
||||
'Touchable child must either be native or forward setNativeProps to a ' + 'native component'
|
||||
'Touchable child must either be native or forward setNativeProps to a native component'
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const createKey = id => `${prefix}-${id}`;
|
||||
|
||||
export default class ReactNativePropRegistry {
|
||||
static register(object: Object): number {
|
||||
let id = uniqueID++;
|
||||
const id = uniqueID++;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Object.freeze(object);
|
||||
}
|
||||
|
||||
@@ -15,13 +15,10 @@ import Dimensions from '../../apis/Dimensions';
|
||||
import findNodeHandle from '../findNodeHandle';
|
||||
import invariant from 'fbjs/lib/invariant';
|
||||
import Platform from '../../apis/Platform';
|
||||
import React from 'react';
|
||||
import TextInputState from '../../components/TextInput/TextInputState';
|
||||
import UIManager from '../../apis/UIManager';
|
||||
import warning from 'fbjs/lib/warning';
|
||||
|
||||
// type Component = React.Component
|
||||
|
||||
/**
|
||||
* Mixin that can be integrated in order to handle scrolling that plays well
|
||||
* with `ResponderEventPlugin`. Integrate with your platform specific scroll
|
||||
@@ -102,7 +99,7 @@ import warning from 'fbjs/lib/warning';
|
||||
|
||||
const emptyObject = {};
|
||||
|
||||
var IS_ANIMATING_TOUCH_START_THRESHOLD_MS = 16;
|
||||
const IS_ANIMATING_TOUCH_START_THRESHOLD_MS = 16;
|
||||
|
||||
type State = {
|
||||
isTouching: boolean,
|
||||
@@ -113,7 +110,7 @@ type State = {
|
||||
};
|
||||
type Event = Object;
|
||||
|
||||
var ScrollResponderMixin = {
|
||||
const ScrollResponderMixin = {
|
||||
// mixins: [Subscribable.Mixin],
|
||||
scrollResponderMixinGetInitialState: function(): State {
|
||||
return {
|
||||
@@ -228,7 +225,7 @@ var ScrollResponderMixin = {
|
||||
* @param {SyntheticEvent} e Event.
|
||||
*/
|
||||
scrollResponderHandleTouchEnd: function(e: Event) {
|
||||
var nativeEvent = e.nativeEvent;
|
||||
const nativeEvent = e.nativeEvent;
|
||||
this.state.isTouching = nativeEvent.touches.length !== 0;
|
||||
this.props.onTouchEnd && this.props.onTouchEnd(e);
|
||||
},
|
||||
@@ -241,7 +238,7 @@ var ScrollResponderMixin = {
|
||||
|
||||
// By default scroll views will unfocus a textField
|
||||
// if another touch occurs outside of it
|
||||
var currentlyFocusedTextInput = TextInputState.currentlyFocusedField();
|
||||
const currentlyFocusedTextInput = TextInputState.currentlyFocusedField();
|
||||
if (
|
||||
!this.props.keyboardShouldPersistTaps &&
|
||||
currentlyFocusedTextInput != null &&
|
||||
@@ -340,9 +337,9 @@ var ScrollResponderMixin = {
|
||||
* a touch has just started or ended.
|
||||
*/
|
||||
scrollResponderIsAnimating: function(): boolean {
|
||||
var now = Date.now();
|
||||
var timeSinceLastMomentumScrollEnd = now - this.state.lastMomentumScrollEndTime;
|
||||
var isAnimating =
|
||||
const now = Date.now();
|
||||
const timeSinceLastMomentumScrollEnd = now - this.state.lastMomentumScrollEndTime;
|
||||
const isAnimating =
|
||||
timeSinceLastMomentumScrollEnd < IS_ANIMATING_TOUCH_START_THRESHOLD_MS ||
|
||||
this.state.lastMomentumScrollEndTime < this.state.lastMomentumScrollBeginTime;
|
||||
return isAnimating;
|
||||
@@ -457,11 +454,11 @@ var ScrollResponderMixin = {
|
||||
width: number,
|
||||
height: number
|
||||
) {
|
||||
var keyboardScreenY = Dimensions.get('window').height;
|
||||
let keyboardScreenY = Dimensions.get('window').height;
|
||||
if (this.keyboardWillOpenTo) {
|
||||
keyboardScreenY = this.keyboardWillOpenTo.endCoordinates.screenY;
|
||||
}
|
||||
var scrollOffsetY = top - keyboardScreenY + height + this.additionalScrollOffset;
|
||||
let scrollOffsetY = top - keyboardScreenY + height + this.additionalScrollOffset;
|
||||
|
||||
// By default, this can scroll with negative offset, pulling the content
|
||||
// down so that the target component's bottom meets the keyboard's top.
|
||||
@@ -548,7 +545,7 @@ var ScrollResponderMixin = {
|
||||
}
|
||||
};
|
||||
|
||||
var ScrollResponder = {
|
||||
const ScrollResponder = {
|
||||
Mixin: ScrollResponderMixin
|
||||
};
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ const isNumeric = n => {
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
};
|
||||
|
||||
const multiplyStyleLengthValue = (value: String | Number, multiple) => {
|
||||
const multiplyStyleLengthValue = (value: string | number, multiple) => {
|
||||
if (typeof value === 'string') {
|
||||
const number = parseFloat(value, 10) * multiple;
|
||||
const number = parseFloat(value) * multiple;
|
||||
const unit = getUnit(value);
|
||||
return `${number}${unit}`;
|
||||
} else if (isNumeric(value)) {
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2016-present, Nicolas Gallagher.
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @providesModule processColor
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import normalizeColor from 'normalize-css-color';
|
||||
|
||||
const processColor = (color, opacity = 1) => {
|
||||
const processColor = (color: ?(string | number), opacity: number = 1) => {
|
||||
if (
|
||||
color === undefined ||
|
||||
color === null ||
|
||||
|
||||
@@ -13,7 +13,7 @@ const _requestIdleCallback = function(cb) {
|
||||
}, 1);
|
||||
};
|
||||
|
||||
const _cancelIdleCallback = function(id) {
|
||||
const _cancelIdleCallback = function(id: number) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import createStrictShapeTypeChecker from './createStrictShapeTypeChecker';
|
||||
import { number } from 'prop-types';
|
||||
|
||||
var PointPropType = createStrictShapeTypeChecker({
|
||||
const PointPropType = createStrictShapeTypeChecker({
|
||||
x: number,
|
||||
y: number
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user