mirror of
https://github.com/status-im/react-native.git
synced 2025-02-05 06:04:15 +00:00
commit
edb9322fe4
@ -2,11 +2,12 @@
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule GameBoard
|
||||
* @flow
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
// NB: Taken straight from: https://github.com/IvanVergiliev/2048-react/blob/master/src/board.js
|
||||
// with no modificiation except to format it for CommonJS and fix lint errors
|
||||
// with no modificiation except to format it for CommonJS and fix lint/flow errors
|
||||
|
||||
var rotateLeft = function (matrix) {
|
||||
var rows = matrix.length;
|
||||
@ -21,9 +22,10 @@ var rotateLeft = function (matrix) {
|
||||
return res;
|
||||
};
|
||||
|
||||
var Tile = function (value, row, column) {
|
||||
var Tile = function (value?: number, row?: number, column?: number) {
|
||||
this.value = value || 0;
|
||||
this.row = row || -1;
|
||||
|
||||
this.column = column || -1;
|
||||
this.oldRow = -1;
|
||||
this.oldColumn = -1;
|
||||
@ -102,8 +104,8 @@ Board.prototype.moveLeft = function () {
|
||||
targetTile.value += tile2.value;
|
||||
}
|
||||
resultRow[target] = targetTile;
|
||||
this.won |= (targetTile.value === 2048);
|
||||
hasChanged |= (targetTile.value !== this.cells[row][target].value);
|
||||
this.won = this.won || (targetTile.value === 2048);
|
||||
hasChanged = hasChanged || (targetTile.value !== this.cells[row][target].value);
|
||||
}
|
||||
this.cells[row] = resultRow;
|
||||
}
|
||||
@ -172,14 +174,14 @@ Board.prototype.hasLost = function () {
|
||||
var canMove = false;
|
||||
for (var row = 0; row < Board.size; ++row) {
|
||||
for (var column = 0; column < Board.size; ++column) {
|
||||
canMove |= (this.cells[row][column].value === 0);
|
||||
canMove = canMove || (this.cells[row][column].value === 0);
|
||||
for (var dir = 0; dir < 4; ++dir) {
|
||||
var newRow = row + Board.deltaX[dir];
|
||||
var newColumn = column + Board.deltaY[dir];
|
||||
if (newRow < 0 || newRow >= Board.size || newColumn < 0 || newColumn >= Board.size) {
|
||||
continue;
|
||||
}
|
||||
canMove |= (this.cells[row][column].value === this.cells[newRow][newColumn].value);
|
||||
canMove = canMove || (this.cells[row][column].value === this.cells[newRow][newColumn].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ var LOADING = {};
|
||||
var SearchScreen = React.createClass({
|
||||
mixins: [TimerMixin],
|
||||
|
||||
timeoutID: (null: any),
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
isLoading: false,
|
||||
|
@ -11,7 +11,6 @@ var {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
ix,
|
||||
} = React;
|
||||
|
||||
var ImageCapInsetsExample = React.createClass({
|
||||
@ -23,7 +22,7 @@ var ImageCapInsetsExample = React.createClass({
|
||||
capInsets: none
|
||||
</Text>
|
||||
<Image
|
||||
source={ix('story-background')}
|
||||
source={require('image!story-background')}
|
||||
style={styles.storyBackground}
|
||||
capInsets={{left: 0, right: 0, bottom: 0, top: 0}}
|
||||
/>
|
||||
@ -33,7 +32,7 @@ var ImageCapInsetsExample = React.createClass({
|
||||
capInsets: 15
|
||||
</Text>
|
||||
<Image
|
||||
source={ix('story-background')}
|
||||
source={require('image!story-background')}
|
||||
style={styles.storyBackground}
|
||||
capInsets={{left: 15, right: 15, bottom: 15, top: 15}}
|
||||
/>
|
||||
|
@ -9,7 +9,6 @@ var {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
ix,
|
||||
} = React;
|
||||
|
||||
var ImageCapInsetsExample = require('./ImageCapInsetsExample');
|
||||
@ -34,15 +33,15 @@ exports.examples = [
|
||||
},
|
||||
{
|
||||
title: 'Plain Static Image',
|
||||
description: 'Static assets must be referenced with the `ix` wrapper and ' +
|
||||
'located in the app bundle.',
|
||||
description: 'Static assets should be required by prefixing with `image!` ' +
|
||||
'and are located in the app bundle.',
|
||||
render: function() {
|
||||
return (
|
||||
<View style={styles.horizontal}>
|
||||
<Image source={ix('uie_thumb_normal')} style={styles.icon} />
|
||||
<Image source={ix('uie_thumb_selected')} style={styles.icon} />
|
||||
<Image source={ix('uie_comment_normal')} style={styles.icon} />
|
||||
<Image source={ix('uie_comment_highlighted')} style={styles.icon} />
|
||||
<Image source={require('image!uie_thumb_normal')} style={styles.icon} />
|
||||
<Image source={require('image!uie_thumb_selected')} style={styles.icon} />
|
||||
<Image source={require('image!uie_comment_normal')} style={styles.icon} />
|
||||
<Image source={require('image!uie_comment_highlighted')} style={styles.icon} />
|
||||
</View>
|
||||
);
|
||||
},
|
||||
@ -184,19 +183,19 @@ exports.examples = [
|
||||
return (
|
||||
<View style={styles.horizontal}>
|
||||
<Image
|
||||
source={ix('uie_thumb_normal')}
|
||||
source={require('image!uie_thumb_normal')}
|
||||
style={[styles.icon, {tintColor: 'blue' }]}
|
||||
/>
|
||||
<Image
|
||||
source={ix('uie_thumb_normal')}
|
||||
source={require('image!uie_thumb_normal')}
|
||||
style={[styles.icon, styles.leftMargin, {tintColor: 'green' }]}
|
||||
/>
|
||||
<Image
|
||||
source={ix('uie_thumb_normal')}
|
||||
source={require('image!uie_thumb_normal')}
|
||||
style={[styles.icon, styles.leftMargin, {tintColor: 'red' }]}
|
||||
/>
|
||||
<Image
|
||||
source={ix('uie_thumb_normal')}
|
||||
source={require('image!uie_thumb_normal')}
|
||||
style={[styles.icon, styles.leftMargin, {tintColor: 'black' }]}
|
||||
/>
|
||||
</View>
|
||||
|
@ -10,7 +10,6 @@ var StyleSheet = require('StyleSheet');
|
||||
var Text = require('Text');
|
||||
var View = require('View');
|
||||
|
||||
var ix = require('ix');
|
||||
|
||||
var TabBarExample = React.createClass({
|
||||
|
||||
@ -42,7 +41,7 @@ var TabBarExample = React.createClass({
|
||||
selectedTab={this.state.selectedTab}>
|
||||
<TabBarItemIOS
|
||||
name="blueTab"
|
||||
icon={ix('favorites')}
|
||||
icon={require('image!favorites')}
|
||||
accessibilityLabel="Blue Tab"
|
||||
selected={this.state.selectedTab === 'blueTab'}
|
||||
onPress={() => {
|
||||
@ -55,7 +54,7 @@ var TabBarExample = React.createClass({
|
||||
<TabBarItemIOS
|
||||
accessibilityLabel="Red Tab"
|
||||
name="redTab"
|
||||
icon={ix('history')}
|
||||
icon={require('image!history')}
|
||||
badgeValue={this.state.notifCount ? String(this.state.notifCount) : null}
|
||||
selected={this.state.selectedTab === 'redTab'}
|
||||
onPress={() => {
|
||||
@ -68,7 +67,7 @@ var TabBarExample = React.createClass({
|
||||
</TabBarItemIOS>
|
||||
<TabBarItemIOS
|
||||
name="greenTab"
|
||||
icon={ix('more')}
|
||||
icon={require('image!more')}
|
||||
accessibilityLabel="Green Tab"
|
||||
selected={this.state.selectedTab === 'greenTab'}
|
||||
onPress={() => {
|
||||
|
@ -41,7 +41,7 @@ var DEFAULT_PROPS = {
|
||||
* <TouchableHighlight onPress={this._onPressButton}>
|
||||
* <Image
|
||||
* style={styles.button}
|
||||
* source={ix('myButton')}
|
||||
* source={require('image!myButton')}
|
||||
* />
|
||||
* </View>
|
||||
* );
|
||||
|
@ -30,7 +30,7 @@ var onlyChild = require('onlyChild');
|
||||
* <TouchableOpacity onPress={this._onPressButton}>
|
||||
* <Image
|
||||
* style={styles.button}
|
||||
* source={ix('myButton')}
|
||||
* source={require('image!myButton')}
|
||||
* />
|
||||
* </View>
|
||||
* );
|
||||
|
@ -8,13 +8,11 @@
|
||||
var LayoutPropTypes = require('LayoutPropTypes');
|
||||
var ReactPropTypes = require('ReactPropTypes');
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
/**
|
||||
* Warning: Some of these properties may not be supported in all releases.
|
||||
*/
|
||||
var ViewStylePropTypes = merge(
|
||||
LayoutPropTypes, {
|
||||
var ViewStylePropTypes = {
|
||||
...LayoutPropTypes,
|
||||
backgroundColor: ReactPropTypes.string,
|
||||
borderColor: ReactPropTypes.string,
|
||||
borderTopColor: ReactPropTypes.string,
|
||||
@ -36,6 +34,6 @@ var ViewStylePropTypes = merge(
|
||||
scaleY: ReactPropTypes.number,
|
||||
translateX: ReactPropTypes.number,
|
||||
translateY: ReactPropTypes.number,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ViewStylePropTypes;
|
||||
|
@ -36,7 +36,7 @@ var warning = require('warning');
|
||||
* <View>
|
||||
* <Image
|
||||
* style={styles.icon}
|
||||
* source={ix('myIcon')}
|
||||
* source={require('image!myIcon')}
|
||||
* />
|
||||
* <Image
|
||||
* style={styles.logo}
|
||||
|
@ -9,23 +9,19 @@ var ImageResizeMode = require('ImageResizeMode');
|
||||
var LayoutPropTypes = require('LayoutPropTypes');
|
||||
var ReactPropTypes = require('ReactPropTypes');
|
||||
|
||||
var merge = require('merge');
|
||||
var ImageStylePropTypes = {
|
||||
...LayoutPropTypes,
|
||||
resizeMode: ReactPropTypes.oneOf(Object.keys(ImageResizeMode)),
|
||||
backgroundColor: ReactPropTypes.string,
|
||||
borderColor: ReactPropTypes.string,
|
||||
borderWidth: ReactPropTypes.number,
|
||||
borderRadius: ReactPropTypes.number,
|
||||
|
||||
var ImageStylePropTypes = merge(
|
||||
LayoutPropTypes,
|
||||
{
|
||||
resizeMode: ReactPropTypes.oneOf(Object.keys(ImageResizeMode)),
|
||||
backgroundColor: ReactPropTypes.string,
|
||||
borderColor: ReactPropTypes.string,
|
||||
borderWidth: ReactPropTypes.number,
|
||||
borderRadius: ReactPropTypes.number,
|
||||
|
||||
// iOS-Specific style to "tint" an image.
|
||||
// It changes the color of all the non-transparent pixels to the tintColor
|
||||
tintColor: ReactPropTypes.string,
|
||||
opacity: ReactPropTypes.number,
|
||||
}
|
||||
);
|
||||
// iOS-Specific style to "tint" an image.
|
||||
// It changes the color of all the non-transparent pixels to the tintColor
|
||||
tintColor: ReactPropTypes.string,
|
||||
opacity: ReactPropTypes.number,
|
||||
};
|
||||
|
||||
// Image doesn't support padding correctly (#4841912)
|
||||
var unsupportedProps = Object.keys({
|
||||
|
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule ix
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This function is used to mark string literals that are image paths. The
|
||||
* return value is a blob of data that core image components understand how to
|
||||
* render.
|
||||
*
|
||||
* The arguments to ix() must be string literals so that they can be parsed
|
||||
* statically.
|
||||
*
|
||||
* @param string Image path to render
|
||||
* @return object Data blob to be used by core UI components
|
||||
*/
|
||||
function ix(path) {
|
||||
return {
|
||||
uri: path,
|
||||
isStatic: true,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = ix;
|
@ -8,25 +8,22 @@
|
||||
var ReactPropTypes = require('ReactPropTypes');
|
||||
var ViewStylePropTypes = require('ViewStylePropTypes');
|
||||
|
||||
var merge = require('merge');
|
||||
|
||||
var TextStylePropTypes = merge(
|
||||
ViewStylePropTypes, {
|
||||
fontFamily: ReactPropTypes.string,
|
||||
fontSize: ReactPropTypes.number,
|
||||
fontWeight: ReactPropTypes.oneOf(['normal' /*default*/, 'bold']),
|
||||
fontStyle: ReactPropTypes.oneOf(['normal', 'italic']),
|
||||
lineHeight: ReactPropTypes.number,
|
||||
color: ReactPropTypes.string,
|
||||
containerBackgroundColor: ReactPropTypes.string,
|
||||
textAlign: ReactPropTypes.oneOf(
|
||||
['auto' /*default*/, 'left', 'right', 'center']
|
||||
),
|
||||
writingDirection: ReactPropTypes.oneOf(
|
||||
['auto' /*default*/, 'ltr', 'rtl']
|
||||
),
|
||||
}
|
||||
);
|
||||
var TextStylePropTypes = {
|
||||
...ViewStylePropTypes,
|
||||
fontFamily: ReactPropTypes.string,
|
||||
fontSize: ReactPropTypes.number,
|
||||
fontWeight: ReactPropTypes.oneOf(['normal' /*default*/, 'bold']),
|
||||
fontStyle: ReactPropTypes.oneOf(['normal', 'italic']),
|
||||
lineHeight: ReactPropTypes.number,
|
||||
color: ReactPropTypes.string,
|
||||
containerBackgroundColor: ReactPropTypes.string,
|
||||
textAlign: ReactPropTypes.oneOf(
|
||||
['auto' /*default*/, 'left', 'right', 'center']
|
||||
),
|
||||
writingDirection: ReactPropTypes.oneOf(
|
||||
['auto' /*default*/, 'ltr', 'rtl']
|
||||
),
|
||||
};
|
||||
|
||||
// Text doesn't support padding correctly (#4841912)
|
||||
var unsupportedProps = Object.keys({
|
||||
|
2
Libraries/react-native/react-native.js
vendored
2
Libraries/react-native/react-native.js
vendored
@ -45,7 +45,7 @@ var ReactNative = {
|
||||
TimerMixin: require('TimerMixin'),
|
||||
VibrationIOS: require('VibrationIOS'),
|
||||
|
||||
ix: require('ix'),
|
||||
invariant: require('invariant'),
|
||||
};
|
||||
|
||||
module.exports = ReactNative;
|
||||
|
@ -38,7 +38,12 @@ if (options.projectRoots) {
|
||||
options.projectRoots = options.projectRoots.split(',');
|
||||
}
|
||||
} else {
|
||||
options.projectRoots = [path.resolve(__dirname, '..')];
|
||||
if (__dirname.match(/node_modules\/react-native\/packager$/)) {
|
||||
// packager is running from node_modules of another project
|
||||
options.projectRoots = [path.resolve(__dirname, '../../..')];
|
||||
} else {
|
||||
options.projectRoots = [path.resolve(__dirname, '..')];
|
||||
}
|
||||
}
|
||||
|
||||
if (options.root) {
|
||||
|
@ -51,7 +51,7 @@ describe('processRequest', function() {
|
||||
Packager = require('../../Packager');
|
||||
FileWatcher = require('../../FileWatcher');
|
||||
|
||||
Packager.prototype.package = function() {
|
||||
Packager.prototype.package = jest.genMockFunction().mockImpl(function() {
|
||||
return q({
|
||||
getSource: function() {
|
||||
return 'this is the source';
|
||||
@ -60,7 +60,7 @@ describe('processRequest', function() {
|
||||
return 'this is the source map';
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
FileWatcher.prototype.on = function(eventType, callback) {
|
||||
@ -106,6 +106,21 @@ describe('processRequest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
pit('works with .ios.js extension', function() {
|
||||
return makeRequest(
|
||||
requestHandler,
|
||||
'index.ios.includeRequire.bundle'
|
||||
).then(function(response) {
|
||||
expect(response).toEqual('this is the source');
|
||||
expect(Packager.prototype.package).toBeCalledWith(
|
||||
'index.ios.js',
|
||||
true,
|
||||
'index.ios.includeRequire.map',
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
pit('watches all files in projectRoot', function() {
|
||||
return makeRequest(
|
||||
requestHandler,
|
||||
|
26
packager/react-packager/src/Server/index.js
vendored
26
packager/react-packager/src/Server/index.js
vendored
@ -6,7 +6,6 @@ var declareOpts = require('../lib/declareOpts');
|
||||
var FileWatcher = require('../FileWatcher');
|
||||
var Packager = require('../Packager');
|
||||
var Activity = require('../Activity');
|
||||
var setImmediate = require('timers').setImmediate;
|
||||
var q = require('q');
|
||||
var _ = require('underscore');
|
||||
|
||||
@ -236,23 +235,24 @@ Server.prototype.processRequest = function(req, res, next) {
|
||||
function getOptionsFromUrl(reqUrl) {
|
||||
// `true` to parse the query param as an object.
|
||||
var urlObj = url.parse(reqUrl, true);
|
||||
var pathname = urlObj.pathname;
|
||||
|
||||
var match = urlObj.pathname.match(/^\/?([^\.]+)\..*(bundle|map)$/);
|
||||
if (!(match && match[1])) {
|
||||
throw new Error('Invalid url format, expected "/path/to/file.bundle"');
|
||||
}
|
||||
var main = match[1] + '.js';
|
||||
// Backwards compatibility. Options used to be as added as '.' to the
|
||||
// entry module name. We can safely remove these options.
|
||||
var entryFile = pathname.replace(/^\//, '').split('.').filter(function(part) {
|
||||
if (part === 'includeRequire' || part === 'runModule' ||
|
||||
part === 'bundle' || part === 'map') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}).join('.') + '.js';
|
||||
|
||||
return {
|
||||
sourceMapUrl: urlObj.pathname.replace(/\.bundle$/, '.map'),
|
||||
main: main,
|
||||
sourceMapUrl: pathname.replace(/\.bundle$/, '.map'),
|
||||
main: entryFile,
|
||||
dev: getBoolOptionFromQuery(urlObj.query, 'dev', true),
|
||||
minify: getBoolOptionFromQuery(urlObj.query, 'minify'),
|
||||
runModule: getBoolOptionFromQuery(urlObj.query, 'runModule') ||
|
||||
// Backwards compatibility.
|
||||
urlObj.pathname.split('.').some(function(part) {
|
||||
return part === 'runModule';
|
||||
}),
|
||||
runModule: getBoolOptionFromQuery(urlObj.query, 'runModule', true),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ var components = [
|
||||
'../Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js',
|
||||
'../Libraries/Components/DatePicker/DatePickerIOS.ios.js',
|
||||
'../Libraries/Image/Image.ios.js',
|
||||
'../Libraries/Components/ListView/ListView.js',
|
||||
'../Libraries/CustomComponents/ListView/ListView.js',
|
||||
'../Libraries/Components/MapView/MapView.js',
|
||||
'../Libraries/Components/Navigation/NavigatorIOS.ios.js',
|
||||
'../Libraries/Picker/PickerIOS.ios.js',
|
||||
|
Loading…
x
Reference in New Issue
Block a user