Updates from Wed Mar 4

- [ReactNative] modernize DatePicker | Spencer Ahrens
- React Native: Force !ExecutionEnvironment.canUseDOM | Tim Yung
- [react-packager] Recover and warn from corrupted cache file | Amjad Masad
- [ReactNative] Github repo's gitignore is written at export | Amjad Masad
- [ReactNative] Use strings instead of constants for keyboardDismissMode | Christopher Chedeau
This commit is contained in:
Christopher Chedeau
2015-03-04 08:05:38 -08:00
parent 86aa5f80dc
commit 7b0cd86759
10 changed files with 83 additions and 527 deletions

View File

@@ -31,6 +31,12 @@ var PropTypes = React.PropTypes;
var SCROLLVIEW = 'ScrollView';
var INNERVIEW = 'InnerScrollView';
var keyboardDismissModeConstants = {
'none': RKScrollViewConsts.KeyboardDismissMode.None, // default
'interactive': RKScrollViewConsts.KeyboardDismissMode.Interactive,
'onDrag': RKScrollViewConsts.KeyboardDismissMode.OnDrag,
};
/**
* `React` component that wraps platform `RKScrollView` while providing
* integration with touch locking "responder" system.
@@ -80,8 +86,8 @@ var INNERVIEW = 'InnerScrollView';
/**
* A floating-point number that determines how quickly the scroll view
* decelerates after the user lifts their finger. Reasonable choices include
* `RKScrollView.Constants.DecelerationRate.Normal` (the default) and
* `RKScrollView.Constants.DecelerationRate.Fast`.
* - Normal: 0.998 (the default)
* - Fast: 0.9
*/
decelerationRate: nativePropType(PropTypes.number),
/**
@@ -91,18 +97,17 @@ var INNERVIEW = 'InnerScrollView';
horizontal: PropTypes.bool,
/**
* Determines whether the keyboard gets dismissed in response to a drag.
* When `ScrollView.keyboardDismissMode.None` (the default), drags do not
* dismiss the keyboard. When `ScrollView.keyboardDismissMode.OnDrag`, the
* keyboard is dismissed when a drag begins. When
* `ScrollView.keyboardDismissMode.Interactive`, the keyboard is dismissed
* interactively with the drag and moves in synchrony with the touch;
* dragging upwards cancels the dismissal.
* - 'none' (the default), drags do not dismiss the keyboard.
* - 'onDrag', the keyboard is dismissed when a drag begins.
* - 'interactive', the keyboard is dismissed interactively with the drag
* and moves in synchrony with the touch; dragging upwards cancels the
* dismissal.
*/
keyboardDismissMode: nativePropType(PropTypes.oneOf([
RKScrollViewConsts.KeyboardDismissMode.None, // default
RKScrollViewConsts.KeyboardDismissMode.Interactive,
RKScrollViewConsts.KeyboardDismissMode.OnDrag,
])),
keyboardDismissMode: PropTypes.oneOf([
'none', // default
'interactive',
'onDrag',
]),
/**
* When false, tapping outside of the focused text input when the keyboard
* is up dismisses the keyboard. When true, the scroll view will not catch
@@ -154,7 +159,6 @@ var INNERVIEW = 'InnerScrollView';
var ScrollView = React.createClass({
statics: {
PropTypes: RKScrollViewPropTypes,
keyboardDismissMode: RKScrollViewConsts.KeyboardDismissMode,
},
propTypes: RKScrollViewPropTypes,
@@ -230,6 +234,9 @@ var ScrollView = React.createClass({
this.props, {
alwaysBounceHorizontal,
alwaysBounceVertical,
keyboardDismissMode: this.props.keyboardDismissMode ?
keyboardDismissModeConstants[this.props.keyboardDismissMode] :
undefined,
style: [styles.base, this.props.style],
onTouchStart: this.scrollResponderHandleTouchStart,
onTouchMove: this.scrollResponderHandleTouchMove,

View File

@@ -17,16 +17,8 @@
/* eslint global-strict: 0 */
/* globals GLOBAL: true, window: true */
var JSTimers = require('JSTimers');
// Just to make sure the JS gets packaged up
// Just to make sure the JS gets packaged up.
require('RCTDeviceEventEmitter');
var ErrorUtils = require('ErrorUtils');
var RKAlertManager = require('RKAlertManager');
var RKExceptionsManager = require('NativeModules').RKExceptionsManager;
var errorToString = require('errorToString');
var loadSourceMap = require('loadSourceMap');
if (typeof GLOBAL === 'undefined') {
GLOBAL = this;
@@ -36,7 +28,43 @@ if (typeof window === 'undefined') {
window = GLOBAL;
}
/**
* The document must be shimmed before anything else that might define the
* `ExecutionEnvironment` module (which checks for `document.createElement`).
*/
function setupDocumentShim() {
// The browser defines Text and Image globals by default. If you forget to
// require them, then the error message is very confusing.
function getInvalidGlobalUseError(name) {
return new Error(
'You are trying to render the global ' + name + ' variable as a ' +
'React element. You probably forgot to require ' + name + '.'
);
}
GLOBAL.Text = {
get defaultProps() {
throw getInvalidGlobalUseError('Text');
}
};
GLOBAL.Image = {
get defaultProps() {
throw getInvalidGlobalUseError('Image');
}
};
if (!GLOBAL.document) {
// This shouldn't be needed but scroller library fails without it. If
// we fixed the scroller, we wouldn't need this.
GLOBAL.document = {body: {}};
}
// Force `ExecutionEnvironment.canUseDOM` to be false.
GLOBAL.document.createElement = null;
}
function handleErrorWithRedBox(e) {
var RKExceptionsManager = require('NativeModules').RKExceptionsManager;
var errorToString = require('errorToString');
var loadSourceMap = require('loadSourceMap');
GLOBAL.console.error(
'Error: ' +
'\n stack: \n' + e.stack +
@@ -60,38 +88,10 @@ function handleErrorWithRedBox(e) {
}
function setupRedBoxErrorHandler() {
var ErrorUtils = require('ErrorUtils');
ErrorUtils.setGlobalHandler(handleErrorWithRedBox);
}
function setupDocumentShim() {
// The browser defines Text and Image globals by default. If you forget to
// require them, then the error message is very confusing.
function getInvalidGlobalUseError(name) {
return new Error(
'You are trying to render the global ' + name + ' variable as a ' +
'React element. You probably forgot to require ' + name + '.'
);
}
GLOBAL.Text = {
get defaultProps() {
throw getInvalidGlobalUseError('Text');
}
};
GLOBAL.Image = {
get defaultProps() {
throw getInvalidGlobalUseError('Image');
}
};
GLOBAL.document = {
// This shouldn't be needed but scroller library fails without it. If
// we fixed the scroller, we wouldn't need this.
body: {},
// Workaround for setImmediate
createElement: function() {return {};}
};
}
/**
* Sets up a set of window environment wrappers that ensure that the
* BatchedBridge is flushed after each tick. In both the case of the
@@ -100,6 +100,7 @@ function setupDocumentShim() {
* unexplainably dropped timing signals.
*/
function setupTimers() {
var JSTimers = require('JSTimers');
GLOBAL.setTimeout = JSTimers.setTimeout;
GLOBAL.setInterval = JSTimers.setInterval;
GLOBAL.setImmediate = JSTimers.setImmediate;
@@ -114,6 +115,7 @@ function setupTimers() {
}
function setupAlert() {
var RKAlertManager = require('RKAlertManager');
if (!GLOBAL.alert) {
GLOBAL.alert = function(text) {
var alertOpts = {
@@ -144,8 +146,8 @@ function setupGeolocation() {
GLOBAL.navigator.geolocation = require('GeoLocation');
}
setupRedBoxErrorHandler();
setupDocumentShim();
setupRedBoxErrorHandler();
setupTimers();
setupAlert();
setupPromise();