mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Convert react-native-github/Libraries to let/const
Reviewed By: sahrens Differential Revision: D7956042 fbshipit-source-id: 221851aa311f3cdd6326497352b366048db0a1bb
This commit is contained in:
committed by
Facebook Github Bot
parent
266016c521
commit
8f5ebe5952
@@ -9,16 +9,16 @@
|
||||
|
||||
// TODO: Move this into an ART mode called "serialized" or something
|
||||
|
||||
var Class = require('art/core/class.js');
|
||||
var Path = require('art/core/path.js');
|
||||
const Class = require('art/core/class.js');
|
||||
const Path = require('art/core/path.js');
|
||||
|
||||
var MOVE_TO = 0;
|
||||
var CLOSE = 1;
|
||||
var LINE_TO = 2;
|
||||
var CURVE_TO = 3;
|
||||
var ARC = 4;
|
||||
const MOVE_TO = 0;
|
||||
const CLOSE = 1;
|
||||
const LINE_TO = 2;
|
||||
const CURVE_TO = 3;
|
||||
const ARC = 4;
|
||||
|
||||
var SerializablePath = Class(Path, {
|
||||
const SerializablePath = Class(Path, {
|
||||
|
||||
initialize: function(path) {
|
||||
this.reset();
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var Color = require('art/core/color');
|
||||
var Path = require('ARTSerializablePath');
|
||||
var Transform = require('art/core/transform');
|
||||
const Color = require('art/core/color');
|
||||
const Path = require('ARTSerializablePath');
|
||||
const Transform = require('art/core/transform');
|
||||
|
||||
var React = require('React');
|
||||
var PropTypes = require('prop-types');
|
||||
var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
||||
const React = require('React');
|
||||
const PropTypes = require('prop-types');
|
||||
const ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
||||
|
||||
var createReactNativeComponentClass = require('createReactNativeComponentClass');
|
||||
var merge = require('merge');
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
const createReactNativeComponentClass = require('createReactNativeComponentClass');
|
||||
const merge = require('merge');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
|
||||
// Diff Helpers
|
||||
|
||||
@@ -28,7 +28,7 @@ function arrayDiffer(a, b) {
|
||||
if (a.length !== b.length) {
|
||||
return true;
|
||||
}
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return true;
|
||||
}
|
||||
@@ -62,22 +62,22 @@ function fontAndLinesDiffer(a, b) {
|
||||
|
||||
// Native Attributes
|
||||
|
||||
var SurfaceViewAttributes = merge(ReactNativeViewAttributes.UIView, {
|
||||
const SurfaceViewAttributes = merge(ReactNativeViewAttributes.UIView, {
|
||||
// This should contain pixel information such as width, height and
|
||||
// resolution to know what kind of buffer needs to be allocated.
|
||||
// Currently we rely on UIViews and style to figure that out.
|
||||
});
|
||||
|
||||
var NodeAttributes = {
|
||||
const NodeAttributes = {
|
||||
transform: { diff: arrayDiffer },
|
||||
opacity: true,
|
||||
};
|
||||
|
||||
var GroupAttributes = merge(NodeAttributes, {
|
||||
const GroupAttributes = merge(NodeAttributes, {
|
||||
clipping: { diff: arrayDiffer }
|
||||
});
|
||||
|
||||
var RenderableAttributes = merge(NodeAttributes, {
|
||||
const RenderableAttributes = merge(NodeAttributes, {
|
||||
fill: { diff: arrayDiffer },
|
||||
stroke: { diff: arrayDiffer },
|
||||
strokeWidth: true,
|
||||
@@ -86,11 +86,11 @@ var RenderableAttributes = merge(NodeAttributes, {
|
||||
strokeDash: { diff: arrayDiffer },
|
||||
});
|
||||
|
||||
var ShapeAttributes = merge(RenderableAttributes, {
|
||||
const ShapeAttributes = merge(RenderableAttributes, {
|
||||
d: { diff: arrayDiffer },
|
||||
});
|
||||
|
||||
var TextAttributes = merge(RenderableAttributes, {
|
||||
const TextAttributes = merge(RenderableAttributes, {
|
||||
alignment: true,
|
||||
frame: { diff: fontAndLinesDiffer },
|
||||
path: { diff: arrayDiffer }
|
||||
@@ -98,25 +98,25 @@ var TextAttributes = merge(RenderableAttributes, {
|
||||
|
||||
// Native Components
|
||||
|
||||
var NativeSurfaceView = createReactNativeComponentClass('ARTSurfaceView',
|
||||
const NativeSurfaceView = createReactNativeComponentClass('ARTSurfaceView',
|
||||
() => ({
|
||||
validAttributes: SurfaceViewAttributes,
|
||||
uiViewClassName: 'ARTSurfaceView',
|
||||
}));
|
||||
|
||||
var NativeGroup = createReactNativeComponentClass('ARTGroup',
|
||||
const NativeGroup = createReactNativeComponentClass('ARTGroup',
|
||||
() => ({
|
||||
validAttributes: GroupAttributes,
|
||||
uiViewClassName: 'ARTGroup',
|
||||
}));
|
||||
|
||||
var NativeShape = createReactNativeComponentClass('ARTShape',
|
||||
const NativeShape = createReactNativeComponentClass('ARTShape',
|
||||
() => ({
|
||||
validAttributes: ShapeAttributes,
|
||||
uiViewClassName: 'ARTShape',
|
||||
}));
|
||||
|
||||
var NativeText = createReactNativeComponentClass('ARTText',
|
||||
const NativeText = createReactNativeComponentClass('ARTText',
|
||||
() => ({
|
||||
validAttributes: TextAttributes,
|
||||
uiViewClassName: 'ARTText',
|
||||
@@ -149,9 +149,9 @@ class Surface extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
var props = this.props;
|
||||
var w = extractNumber(props.width, 0);
|
||||
var h = extractNumber(props.height, 0);
|
||||
const props = this.props;
|
||||
const w = extractNumber(props.width, 0);
|
||||
const h = extractNumber(props.height, 0);
|
||||
return (
|
||||
<NativeSurfaceView style={[props.style, { width: w, height: h }]}>
|
||||
{this.props.children}
|
||||
@@ -172,12 +172,12 @@ function extractNumber(value, defaultValue) {
|
||||
return +value;
|
||||
}
|
||||
|
||||
var pooledTransform = new Transform();
|
||||
const pooledTransform = new Transform();
|
||||
|
||||
function extractTransform(props) {
|
||||
var scaleX = props.scaleX != null ? props.scaleX :
|
||||
const scaleX = props.scaleX != null ? props.scaleX :
|
||||
props.scale != null ? props.scale : 1;
|
||||
var scaleY = props.scaleY != null ? props.scaleY :
|
||||
const scaleY = props.scaleY != null ? props.scaleY :
|
||||
props.scale != null ? props.scale : 1;
|
||||
|
||||
pooledTransform
|
||||
@@ -219,7 +219,7 @@ class Group extends React.Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
var props = this.props;
|
||||
const props = this.props;
|
||||
invariant(
|
||||
this.context.isInSurface,
|
||||
'ART: <Group /> must be a child of a <Surface />'
|
||||
@@ -236,14 +236,14 @@ class Group extends React.Component {
|
||||
|
||||
class ClippingRectangle extends React.Component {
|
||||
render() {
|
||||
var props = this.props;
|
||||
var x = extractNumber(props.x, 0);
|
||||
var y = extractNumber(props.y, 0);
|
||||
var w = extractNumber(props.width, 0);
|
||||
var h = extractNumber(props.height, 0);
|
||||
var clipping = [x, y, w, h];
|
||||
const props = this.props;
|
||||
const x = extractNumber(props.x, 0);
|
||||
const y = extractNumber(props.y, 0);
|
||||
const w = extractNumber(props.width, 0);
|
||||
const h = extractNumber(props.height, 0);
|
||||
const clipping = [x, y, w, h];
|
||||
// The current clipping API requires x and y to be ignored in the transform
|
||||
var propsExcludingXAndY = merge(props);
|
||||
const propsExcludingXAndY = merge(props);
|
||||
delete propsExcludingXAndY.x;
|
||||
delete propsExcludingXAndY.y;
|
||||
return (
|
||||
@@ -259,13 +259,13 @@ class ClippingRectangle extends React.Component {
|
||||
|
||||
// Renderables
|
||||
|
||||
var SOLID_COLOR = 0;
|
||||
var LINEAR_GRADIENT = 1;
|
||||
var RADIAL_GRADIENT = 2;
|
||||
var PATTERN = 3;
|
||||
const SOLID_COLOR = 0;
|
||||
const LINEAR_GRADIENT = 1;
|
||||
const RADIAL_GRADIENT = 2;
|
||||
const PATTERN = 3;
|
||||
|
||||
function insertColorIntoArray(color, targetArray, atIndex) {
|
||||
var c = new Color(color);
|
||||
const c = new Color(color);
|
||||
targetArray[atIndex + 0] = c.red / 255;
|
||||
targetArray[atIndex + 1] = c.green / 255;
|
||||
targetArray[atIndex + 2] = c.blue / 255;
|
||||
@@ -273,14 +273,14 @@ function insertColorIntoArray(color, targetArray, atIndex) {
|
||||
}
|
||||
|
||||
function insertColorsIntoArray(stops, targetArray, atIndex) {
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
if ('length' in stops) {
|
||||
while (i < stops.length) {
|
||||
insertColorIntoArray(stops[i], targetArray, atIndex + i * 4);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
for (var offset in stops) {
|
||||
for (const offset in stops) {
|
||||
insertColorIntoArray(stops[offset], targetArray, atIndex + i * 4);
|
||||
i++;
|
||||
}
|
||||
@@ -289,8 +289,8 @@ function insertColorsIntoArray(stops, targetArray, atIndex) {
|
||||
}
|
||||
|
||||
function insertOffsetsIntoArray(stops, targetArray, atIndex, multi, reverse) {
|
||||
var offsetNumber;
|
||||
var i = 0;
|
||||
let offsetNumber;
|
||||
let i = 0;
|
||||
if ('length' in stops) {
|
||||
while (i < stops.length) {
|
||||
offsetNumber = i / (stops.length - 1) * multi;
|
||||
@@ -298,7 +298,7 @@ function insertOffsetsIntoArray(stops, targetArray, atIndex, multi, reverse) {
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
for (var offsetString in stops) {
|
||||
for (const offsetString in stops) {
|
||||
offsetNumber = (+offsetString) * multi;
|
||||
targetArray[atIndex + i] = reverse ? 1 - offsetNumber : offsetNumber;
|
||||
i++;
|
||||
@@ -308,21 +308,21 @@ function insertOffsetsIntoArray(stops, targetArray, atIndex, multi, reverse) {
|
||||
}
|
||||
|
||||
function insertColorStopsIntoArray(stops, targetArray, atIndex) {
|
||||
var lastIndex = insertColorsIntoArray(stops, targetArray, atIndex);
|
||||
const lastIndex = insertColorsIntoArray(stops, targetArray, atIndex);
|
||||
insertOffsetsIntoArray(stops, targetArray, lastIndex, 1, false);
|
||||
}
|
||||
|
||||
function insertDoubleColorStopsIntoArray(stops, targetArray, atIndex) {
|
||||
var lastIndex = insertColorsIntoArray(stops, targetArray, atIndex);
|
||||
let lastIndex = insertColorsIntoArray(stops, targetArray, atIndex);
|
||||
lastIndex = insertColorsIntoArray(stops, targetArray, lastIndex);
|
||||
lastIndex = insertOffsetsIntoArray(stops, targetArray, lastIndex, 0.5, false);
|
||||
insertOffsetsIntoArray(stops, targetArray, lastIndex, 0.5, true);
|
||||
}
|
||||
|
||||
function applyBoundingBoxToBrushData(brushData, props) {
|
||||
var type = brushData[0];
|
||||
var width = +props.width;
|
||||
var height = +props.height;
|
||||
const type = brushData[0];
|
||||
const width = +props.width;
|
||||
const height = +props.height;
|
||||
if (type === LINEAR_GRADIENT) {
|
||||
brushData[1] *= width;
|
||||
brushData[2] *= height;
|
||||
@@ -356,7 +356,7 @@ function extractBrush(colorOrBrush, props) {
|
||||
}
|
||||
return colorOrBrush._brush;
|
||||
}
|
||||
var c = new Color(colorOrBrush);
|
||||
const c = new Color(colorOrBrush);
|
||||
return [SOLID_COLOR, c.red / 255, c.green / 255, c.blue / 255, c.alpha];
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ function extractColor(color) {
|
||||
if (color == null) {
|
||||
return null;
|
||||
}
|
||||
var c = new Color(color);
|
||||
const c = new Color(color);
|
||||
return [c.red / 255, c.green / 255, c.blue / 255, c.alpha];
|
||||
}
|
||||
|
||||
@@ -391,9 +391,9 @@ function extractStrokeJoin(strokeJoin) {
|
||||
|
||||
class Shape extends React.Component {
|
||||
render() {
|
||||
var props = this.props;
|
||||
var path = props.d || childrenAsString(props.children);
|
||||
var d = (path instanceof Path ? path : new Path(path)).toJSON();
|
||||
const props = this.props;
|
||||
const path = props.d || childrenAsString(props.children);
|
||||
const d = (path instanceof Path ? path : new Path(path)).toJSON();
|
||||
return (
|
||||
<NativeShape
|
||||
fill={extractBrush(props.fill, props)}
|
||||
@@ -413,10 +413,10 @@ class Shape extends React.Component {
|
||||
|
||||
// Text
|
||||
|
||||
var cachedFontObjectsFromString = {};
|
||||
const cachedFontObjectsFromString = {};
|
||||
|
||||
var fontFamilyPrefix = /^[\s"']*/;
|
||||
var fontFamilySuffix = /[\s"']*$/;
|
||||
const fontFamilyPrefix = /^[\s"']*/;
|
||||
const fontFamilySuffix = /[\s"']*$/;
|
||||
|
||||
function extractSingleFontFamily(fontFamilyString) {
|
||||
// ART on the web allows for multiple font-families to be specified.
|
||||
@@ -431,15 +431,15 @@ function parseFontString(font) {
|
||||
if (cachedFontObjectsFromString.hasOwnProperty(font)) {
|
||||
return cachedFontObjectsFromString[font];
|
||||
}
|
||||
var regexp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm\%]*(?:\s*\/.*?)?\s+)?\s*\"?([^\"]*)/i;
|
||||
var match = regexp.exec(font);
|
||||
const regexp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm\%]*(?:\s*\/.*?)?\s+)?\s*\"?([^\"]*)/i;
|
||||
const match = regexp.exec(font);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
var fontFamily = extractSingleFontFamily(match[3]);
|
||||
var fontSize = +match[2] || 12;
|
||||
var isBold = /bold/.exec(match[1]);
|
||||
var isItalic = /italic/.exec(match[1]);
|
||||
const fontFamily = extractSingleFontFamily(match[3]);
|
||||
const fontSize = +match[2] || 12;
|
||||
const isBold = /bold/.exec(match[1]);
|
||||
const isItalic = /italic/.exec(match[1]);
|
||||
cachedFontObjectsFromString[font] = {
|
||||
fontFamily: fontFamily,
|
||||
fontSize: fontSize,
|
||||
@@ -456,9 +456,9 @@ function extractFont(font) {
|
||||
if (typeof font === 'string') {
|
||||
return parseFontString(font);
|
||||
}
|
||||
var fontFamily = extractSingleFontFamily(font.fontFamily);
|
||||
var fontSize = +font.fontSize || 12;
|
||||
var fontWeight = font.fontWeight != null ? font.fontWeight.toString() : '400';
|
||||
const fontFamily = extractSingleFontFamily(font.fontFamily);
|
||||
const fontSize = +font.fontSize || 12;
|
||||
const fontWeight = font.fontWeight != null ? font.fontWeight.toString() : '400';
|
||||
return {
|
||||
// Normalize
|
||||
fontFamily: fontFamily,
|
||||
@@ -468,7 +468,7 @@ function extractFont(font) {
|
||||
};
|
||||
}
|
||||
|
||||
var newLine = /\n/g;
|
||||
const newLine = /\n/g;
|
||||
function extractFontAndLines(font, text) {
|
||||
return { font: extractFont(font), lines: text.split(newLine) };
|
||||
}
|
||||
@@ -486,10 +486,10 @@ function extractAlignment(alignment) {
|
||||
|
||||
class Text extends React.Component {
|
||||
render() {
|
||||
var props = this.props;
|
||||
var path = props.path;
|
||||
var textPath = path ? (path instanceof Path ? path : new Path(path)).toJSON() : null;
|
||||
var textFrame = extractFontAndLines(
|
||||
const props = this.props;
|
||||
const path = props.path;
|
||||
const textPath = path ? (path instanceof Path ? path : new Path(path)).toJSON() : null;
|
||||
const textFrame = extractFontAndLines(
|
||||
props.font,
|
||||
childrenAsString(props.children)
|
||||
);
|
||||
@@ -515,14 +515,14 @@ class Text extends React.Component {
|
||||
// Declarative fill type objects - API design not finalized
|
||||
|
||||
function LinearGradient(stops, x1, y1, x2, y2) {
|
||||
var type = LINEAR_GRADIENT;
|
||||
const type = LINEAR_GRADIENT;
|
||||
|
||||
if (arguments.length < 5) {
|
||||
var angle = ((x1 == null) ? 270 : x1) * Math.PI / 180;
|
||||
const angle = ((x1 == null) ? 270 : x1) * Math.PI / 180;
|
||||
|
||||
var x = Math.cos(angle);
|
||||
var y = -Math.sin(angle);
|
||||
var l = (Math.abs(x) + Math.abs(y)) / 2;
|
||||
let x = Math.cos(angle);
|
||||
let y = -Math.sin(angle);
|
||||
const l = (Math.abs(x) + Math.abs(y)) / 2;
|
||||
|
||||
x *= l; y *= l;
|
||||
|
||||
@@ -535,7 +535,7 @@ function LinearGradient(stops, x1, y1, x2, y2) {
|
||||
this._bb = false;
|
||||
}
|
||||
|
||||
var brushData = [type, +x1, +y1, +x2, +y2];
|
||||
const brushData = [type, +x1, +y1, +x2, +y2];
|
||||
insertColorStopsIntoArray(stops, brushData, 5);
|
||||
this._brush = brushData;
|
||||
}
|
||||
@@ -562,7 +562,7 @@ function RadialGradient(stops, fx, fy, rx, ry, cx, cy) {
|
||||
// To simulate this we render the gradient twice as large and add double
|
||||
// color stops. Ideally this API would become more restrictive so that this
|
||||
// extra work isn't needed.
|
||||
var brushData = [RADIAL_GRADIENT, +fx, +fy, +rx * 2, +ry * 2, +cx, +cy];
|
||||
const brushData = [RADIAL_GRADIENT, +fx, +fy, +rx * 2, +ry * 2, +cx, +cy];
|
||||
insertDoubleColorStopsIntoArray(stops, brushData, 7);
|
||||
this._brush = brushData;
|
||||
}
|
||||
@@ -571,7 +571,7 @@ function Pattern(url, width, height, left, top) {
|
||||
this._brush = [PATTERN, url, +left || 0, +top || 0, +width, +height];
|
||||
}
|
||||
|
||||
var ReactART = {
|
||||
const ReactART = {
|
||||
LinearGradient: LinearGradient,
|
||||
RadialGradient: RadialGradient,
|
||||
Pattern: Pattern,
|
||||
|
||||
Reference in New Issue
Block a user