mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-27 22:54:46 +08:00
2015-02-04 updates
- Unbreak ReactKit | Nick Lockwood - Refactor | Nick Lockwood - [ReactNative] fix touch cancel behavior | Spencer Ahrens - [ReactNative iOS] Fix responder issue with textInput | Eric Vicenti - [ReactNative] README updates - file watching troubleshooting, one-time code drop -> currently private repo | Spencer Ahrens - [ReactKit] Re-add README linebreaks | Ben Alpert
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* @providesModule ResponderEventPlugin
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var EventConstants = require('EventConstants');
|
||||
var EventPluginUtils = require('EventPluginUtils');
|
||||
@@ -27,6 +27,7 @@ var ResponderSyntheticEvent = require('ResponderSyntheticEvent');
|
||||
var ResponderTouchHistoryStore = require('ResponderTouchHistoryStore');
|
||||
|
||||
var accumulate = require('accumulate');
|
||||
var invariant = require('invariant');
|
||||
var keyOf = require('keyOf');
|
||||
|
||||
var isStartish = EventPluginUtils.isStartish;
|
||||
@@ -43,6 +44,12 @@ var executeDispatchesInOrderStopAtTrue =
|
||||
*/
|
||||
var responderID = null;
|
||||
|
||||
/**
|
||||
* Count of current touches. A textInput should become responder iff the
|
||||
* the selection changes while there is a touch on the screen.
|
||||
*/
|
||||
var trackedTouchCount = 0;
|
||||
|
||||
/**
|
||||
* Last reported number of active touches.
|
||||
*/
|
||||
@@ -426,7 +433,8 @@ function setResponderAndExtractTransfer(
|
||||
function canTriggerTransfer(topLevelType, topLevelTargetID) {
|
||||
return topLevelTargetID && (
|
||||
topLevelType === EventConstants.topLevelTypes.topScroll ||
|
||||
topLevelType === EventConstants.topLevelTypes.topSelectionChange ||
|
||||
(trackedTouchCount > 0 &&
|
||||
topLevelType === EventConstants.topLevelTypes.topSelectionChange) ||
|
||||
isStartish(topLevelType) ||
|
||||
isMoveish(topLevelType)
|
||||
);
|
||||
@@ -489,6 +497,15 @@ var ResponderEventPlugin = {
|
||||
topLevelTargetID,
|
||||
nativeEvent) {
|
||||
|
||||
if (isStartish(topLevelType)) {
|
||||
trackedTouchCount += 1;
|
||||
} else if (isEndish(topLevelType)) {
|
||||
trackedTouchCount -= 1;
|
||||
invariant(
|
||||
trackedTouchCount >= 0,
|
||||
'Ended a touch event which was not counted in trackedTouchCount.'
|
||||
);
|
||||
}
|
||||
|
||||
ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
|
||||
|
||||
@@ -507,12 +524,10 @@ var ResponderEventPlugin = {
|
||||
// (`onResponderRelease/onResponderTerminate`).
|
||||
var isResponderTouchStart = responderID && isStartish(topLevelType);
|
||||
var isResponderTouchMove = responderID && isMoveish(topLevelType);
|
||||
var isResponderTouchTerminate = responderID && topLevelType === EventConstants.topLevelTypes.topTouchCancel;
|
||||
var isResponderTouchEnd = responderID && isEndish(topLevelType);
|
||||
var incrementalTouch =
|
||||
isResponderTouchStart ? eventTypes.responderStart :
|
||||
isResponderTouchMove ? eventTypes.responderMove :
|
||||
isResponderTouchTerminate ? eventTypes.responderTerminate :
|
||||
isResponderTouchEnd ? eventTypes.responderEnd :
|
||||
null;
|
||||
|
||||
@@ -524,17 +539,24 @@ var ResponderEventPlugin = {
|
||||
extracted = accumulate(extracted, gesture);
|
||||
}
|
||||
|
||||
var isResponderTerminate =
|
||||
responderID &&
|
||||
topLevelType === EventConstants.topLevelTypes.topTouchCancel;
|
||||
var isResponderRelease =
|
||||
responderID && isEndish(topLevelType) && noResponderTouches(nativeEvent);
|
||||
if (isResponderRelease) {
|
||||
var release = ResponderSyntheticEvent.getPooled(
|
||||
eventTypes.responderRelease,
|
||||
responderID,
|
||||
nativeEvent
|
||||
);
|
||||
release.touchHistory = ResponderTouchHistoryStore.touchHistory;
|
||||
EventPropagators.accumulateDirectDispatches(release);
|
||||
extracted = accumulate(extracted, release);
|
||||
responderID &&
|
||||
!isResponderTerminate &&
|
||||
isEndish(topLevelType) &&
|
||||
noResponderTouches(nativeEvent);
|
||||
var finalTouch =
|
||||
isResponderTerminate ? eventTypes.responderTerminate :
|
||||
isResponderRelease ? eventTypes.responderRelease :
|
||||
null;
|
||||
if (finalTouch) {
|
||||
var finalEvent =
|
||||
ResponderSyntheticEvent.getPooled(finalTouch, responderID, nativeEvent);
|
||||
finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
|
||||
EventPropagators.accumulateDirectDispatches(finalEvent);
|
||||
extracted = accumulate(extracted, finalEvent);
|
||||
changeResponder(null);
|
||||
}
|
||||
|
||||
|
||||
48
Libraries/vendor/react/vendor/core/ExecutionEnvironment.ios.js
vendored
Normal file
48
Libraries/vendor/react/vendor/core/ExecutionEnvironment.ios.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule ExecutionEnvironment
|
||||
*
|
||||
* Stubs SignedSource<<7afee88a05412d0c4eef54817419648e>>
|
||||
*/
|
||||
|
||||
/*jslint evil: true */
|
||||
|
||||
"use strict";
|
||||
|
||||
var canUseDOM = false;
|
||||
|
||||
/**
|
||||
* Simple, lightweight module assisting with the detection and context of
|
||||
* Worker. Helps avoid circular dependencies and allows code to reason about
|
||||
* whether or not they are in a Worker, even if they never include the main
|
||||
* `ReactWorker` dependency.
|
||||
*/
|
||||
var ExecutionEnvironment = {
|
||||
|
||||
canUseDOM: canUseDOM,
|
||||
|
||||
canUseWorkers: typeof Worker !== 'undefined',
|
||||
|
||||
canUseEventListeners:
|
||||
canUseDOM && !!(window.addEventListener || window.attachEvent),
|
||||
|
||||
canUseViewport: canUseDOM && !!window.screen,
|
||||
|
||||
isInWorker: !canUseDOM // For now, this is true - might change in the future.
|
||||
|
||||
};
|
||||
|
||||
module.exports = ExecutionEnvironment;
|
||||
@@ -2,13 +2,12 @@
|
||||
* @providesModule Touchable
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var BoundingDimensions = require('BoundingDimensions');
|
||||
var Position = require('Position');
|
||||
var TouchEventUtils = require('TouchEventUtils');
|
||||
|
||||
var invariant = require('invariant');
|
||||
var keyMirror = require('keyMirror');
|
||||
var queryLayoutByID = require('queryLayoutByID');
|
||||
|
||||
@@ -277,20 +276,20 @@ var LONG_PRESS_ALLOWED_MOVEMENT = 10;
|
||||
* +
|
||||
* | RESPONDER_GRANT (HitRect)
|
||||
* v
|
||||
* +---------------------------+ DELAY +-------------------------+ T - DELAY +------------------------------+
|
||||
* |RESPONDER_INACTIVE_PRESS_IN|+-------->|RESPONDER_ACTIVE_PRESS_IN| +------------> |RESPONDER_ACTIVE_LONG_PRESS_IN|
|
||||
* +---------------------------+ DELAY +-------------------------+ T - DELAY +------------------------------+
|
||||
* |RESPONDER_INACTIVE_PRESS_IN|+-------->|RESPONDER_ACTIVE_PRESS_IN| +------------> |RESPONDER_ACTIVE_LONG_PRESS_IN|
|
||||
* +---------------------------+ +-------------------------+ +------------------------------+
|
||||
* + ^ + ^ + ^
|
||||
* |LEAVE_ |ENTER_ |LEAVE_ |ENTER_ |LEAVE_ |ENTER_
|
||||
* |PRESS_RECT |PRESS_RECT |PRESS_RECT |PRESS_RECT |PRESS_RECT |PRESS_RECT
|
||||
* | | | | | |
|
||||
* v + v + v +
|
||||
* +----------------------------+ DELAY +--------------------------+ +-------------------------------+
|
||||
* |RESPONDER_INACTIVE_PRESS_OUT|+------->|RESPONDER_ACTIVE_PRESS_OUT| |RESPONDER_ACTIVE_LONG_PRESS_OUT|
|
||||
* +----------------------------+ +--------------------------+ +-------------------------------+
|
||||
* +----------------------------+ DELAY +--------------------------+ +-------------------------------+
|
||||
* |RESPONDER_INACTIVE_PRESS_OUT|+------->|RESPONDER_ACTIVE_PRESS_OUT| |RESPONDER_ACTIVE_LONG_PRESS_OUT|
|
||||
* +----------------------------+ +--------------------------+ +-------------------------------+
|
||||
*
|
||||
* T - DELAY => LONG_PRESS_THRESHOLD - DELAY
|
||||
*
|
||||
* T - DELAY => LONG_PRESS_THRESHOLD - DELAY
|
||||
*
|
||||
* Not drawn are the side effects of each transition. The most important side
|
||||
* effect is the `touchableHandlePress` abstract method invocation that occurs
|
||||
* when a responder is released while in either of the "Press" states.
|
||||
@@ -344,7 +343,7 @@ var TouchableMixin = {
|
||||
*
|
||||
*/
|
||||
touchableHandleResponderGrant: function(e, dispatchID) {
|
||||
// Since e is used in a callback invoked on another event loop
|
||||
// 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.
|
||||
e.persist();
|
||||
@@ -420,9 +419,9 @@ var TouchableMixin = {
|
||||
var movedDistance = this._getDistanceBetweenPoints(pageX, pageY, this.pressInLocation.pageX, this.pressInLocation.pageY);
|
||||
if (movedDistance > LONG_PRESS_ALLOWED_MOVEMENT) {
|
||||
this._cancelLongPressDelayTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var isTouchWithinActive =
|
||||
pageX > positionOnActivate.left - pressExpandLeft &&
|
||||
pageY > positionOnActivate.top - pressExpandTop &&
|
||||
@@ -556,18 +555,19 @@ var TouchableMixin = {
|
||||
*/
|
||||
_receiveSignal: function(signal, e) {
|
||||
var curState = this.state.touchable.touchState;
|
||||
invariant(
|
||||
Transitions[curState] && Transitions[curState][signal],
|
||||
'You have supplied either an unrecognized signal or current state %s',
|
||||
curState
|
||||
);
|
||||
if (!(Transitions[curState] && Transitions[curState][signal])) {
|
||||
throw new Error(
|
||||
'Unrecognized signal `' + signal + '` or state `' + curState +
|
||||
'` for Touchable responder `' + this.state.touchable.responderID + '`'
|
||||
);
|
||||
}
|
||||
var nextState = Transitions[curState][signal];
|
||||
invariant(
|
||||
nextState !== States.ERROR,
|
||||
'Some assumptions about the state machine were violated. This is the ' +
|
||||
'fault of Touchable.js. This case has been modeled and caught as an ' +
|
||||
'error transition.'
|
||||
);
|
||||
if (nextState === States.ERROR) {
|
||||
throw new Error(
|
||||
'Touchable cannot transition from `' + curState + '` to `' + signal +
|
||||
'` for responder `' + this.state.touchable.responderID + '`'
|
||||
);
|
||||
}
|
||||
if (curState !== nextState) {
|
||||
this._performSideEffectsForTransition(curState, nextState, signal, e);
|
||||
this.state.touchable.touchState = nextState;
|
||||
@@ -580,7 +580,7 @@ var TouchableMixin = {
|
||||
},
|
||||
|
||||
_isHighlight: function (state) {
|
||||
return state === States.RESPONDER_ACTIVE_PRESS_IN ||
|
||||
return state === States.RESPONDER_ACTIVE_PRESS_IN ||
|
||||
state === States.RESPONDER_ACTIVE_LONG_PRESS_IN;
|
||||
},
|
||||
|
||||
@@ -626,15 +626,15 @@ var TouchableMixin = {
|
||||
|
||||
if (IsPressingIn[curState] && signal === Signals.LONG_PRESS_DETECTED) {
|
||||
this.touchableHandleLongPress && this.touchableHandleLongPress();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (newIsHighlight && !curIsHighlight) {
|
||||
this._savePressInLocation(e);
|
||||
this.touchableHandleActivePressIn && this.touchableHandleActivePressIn();
|
||||
} else if (!newIsHighlight && curIsHighlight) {
|
||||
this.touchableHandleActivePressOut && this.touchableHandleActivePressOut();
|
||||
}
|
||||
|
||||
|
||||
if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) {
|
||||
var hasLongPressHandler = !!this.touchableHandleLongPress;
|
||||
var pressIsLongButStillCallOnPress =
|
||||
@@ -660,4 +660,3 @@ var Touchable = {
|
||||
};
|
||||
|
||||
module.exports = Touchable;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user