Skip to content

Commit

Permalink
2015-02-04 updates
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
vjeux committed Feb 6, 2015
1 parent 6153fff commit fd8b7de
Show file tree
Hide file tree
Showing 55 changed files with 1,515 additions and 1,668 deletions.
50 changes: 36 additions & 14 deletions Libraries/vendor/react/browser/eventPlugins/ResponderEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @providesModule ResponderEventPlugin
*/

"use strict";
'use strict';

var EventConstants = require('EventConstants');
var EventPluginUtils = require('EventPluginUtils');
Expand All @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand All @@ -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);
}

Expand Down
48 changes: 48 additions & 0 deletions Libraries/vendor/react/vendor/core/ExecutionEnvironment.ios.js
Original file line number Diff line number Diff line change
@@ -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;
55 changes: 27 additions & 28 deletions Libraries/vendor/react_contrib/interactions/Touchable/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
Expand All @@ -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;
},

Expand Down Expand Up @@ -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 =
Expand All @@ -660,4 +660,3 @@ var Touchable = {
};

module.exports = Touchable;

35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**Warning: This is a one-time code drop to accompany the ReactJS conference
**Warning: This is currently a private repo to accompany the ReactJS conference
talk, and is not accessible outside the official conference attendees - please
don't share this code.**
do not share this code.**

This is also a very early alpha release. There are certainly bugs and missing
features. Some things may even be well-documented in JS, but missing from the
Expand Down Expand Up @@ -67,11 +67,14 @@ the same library.**

## Troubleshooting

Xcode will break if you have two examples open at the same time.

Jest testing does not yet work on node versions after 0.10.x.

You can verify the packager is working by loading the [bundle](http://localhost:8081/Examples/Movies/MoviesApp.includeRequire.runModule.bundle) in your browser and
+ Xcode will break if you have two examples open at the same time.
+ If `npm start` fails with log spew like:
```
2015-02-02 10:56 node[24294] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-21)
```
then you've hit the node file watching bug - `brew install watchman` should fix the issue.
+ Jest testing does not yet work on node versions after 0.10.x.
+ You can verify the packager is working by loading the [bundle](http://localhost:8081/Examples/Movies/MoviesApp.includeRequire.runModule.bundle) in your browser and
inspecting the contents.

Please report any other issues you encounter so we can fix them ASAP.
Expand All @@ -92,48 +95,48 @@ the responder system.

# FAQ

Q. How does debugging work? Can I set breakpoints in my JS?
Q. How does debugging work? Can I set breakpoints in my JS?
A. We are going to add the ability to use the Chrome developer tools soon. We
are very passionate about building the best possible developer experience.

Q. When is this coming to Android/Windows/OS X/etc?
Q. When is this coming to Android/Windows/OS X/etc?
A. We're working on Android, and we are excited to release it as soon as we can.
We are looking forward to the community helping us target other platforms as
well :)

Q. How do I create my own app?
Q. How do I create my own app?
A. Copy the entire `Examples/TicTacToe` folder, rename stuff in Xcode, and
replace the `TicTacToeApp.js` with your own. Then, in `AppDelegate.m`, update
`moduleName` to match your call to
`Bundler.registerComponent(<moduleName>, <componentName>)` at the bottom of your
JS file, and update `jsCodeLocation` to match your JS file name and location.

Q. Can I submit my own React Native app to the App Store?
Q. Can I submit my own React Native app to the App Store?
A. Not yet, but you will be able to soon. If you build something you want to
submit to the App Store, come talk to us ASAP.

Q. How do I deploy to my device?
Q. How do I deploy to my device?
A. You can change `localhost` in `AppDelegate.m` to your laptop's IP address and
grab the bundle over the same Wi-Fi network. You can also download the bundle
that the React packager generates, save it to the file `main.jsbundle`, and add it
as a static resource in your Xcode project. Then set the `jsCodeLocation` in
`AppDelegate.m` to point to that file and deploy to your device like you would
any other app.

Q. What's up with this private repo? Why aren't you just open sourcing it now?
Q. What's up with this private repo? Why aren't you just open sourcing it now?
A. We want input from the React community before we open the floodgates so we
can incorporate your feedback, and we also have a bunch more features we want to
add to make a more complete offering before we open source.

Q. Do you have to ship a JS runtime with your apps?
Q. Do you have to ship a JS runtime with your apps?
A. No, we just use the JavaScriptCore public API that is part of iOS 7 and
later.

Q. How do I add more native capabilities?
Q. How do I add more native capabilities?
A. React Native is designed to be extensible - come talk to us, we would love to
work with you.

Q. Can I reuse existing iOS code?
Q. Can I reuse existing iOS code?
A. Yes, React Native is designed to be extensible and allow integration of all
sorts of native components, such as `UINavigationController` (available as
`<NavigatorIOS>`), `MKMapView` (not available yet), or your own custom
Expand Down
Loading

0 comments on commit fd8b7de

Please sign in to comment.