mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-03-30 23:23:35 +08:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c83ba162d | ||
|
|
3ffc005a7b | ||
|
|
50a70ad02f | ||
|
|
768e895701 | ||
|
|
af5fde994d | ||
|
|
c3d0763944 | ||
|
|
0aba506725 | ||
|
|
91032d8565 | ||
|
|
0696721488 | ||
|
|
fe18830ce6 | ||
|
|
1b86d02300 | ||
|
|
c56b472258 | ||
|
|
b00132f007 | ||
|
|
8b8f8f0374 | ||
|
|
8e94af34e1 | ||
|
|
7ffaf592d5 | ||
|
|
a1017fa785 | ||
|
|
5db300df35 | ||
|
|
214d862e61 |
@@ -99,6 +99,14 @@ from `style`.
|
||||
+ `alignContent`
|
||||
+ `alignItems`
|
||||
+ `alignSelf`
|
||||
+ `animationDelay`
|
||||
+ `animationDirection`
|
||||
+ `animationDuration`
|
||||
+ `animationFillMode`
|
||||
+ `animationIterationCount`
|
||||
+ `animationName`
|
||||
+ `animationPlayState`
|
||||
+ `animationTimingFunction`
|
||||
+ `backfaceVisibility`
|
||||
+ `backgroundAttachment`
|
||||
+ `backgroundClip`
|
||||
@@ -164,10 +172,17 @@ from `style`.
|
||||
+ `paddingRight`‡
|
||||
+ `paddingTop`
|
||||
+ `paddingVertical`
|
||||
+ `perspective`
|
||||
+ `perspectiveOrigin`
|
||||
+ `position`
|
||||
+ `right`‡
|
||||
+ `top`
|
||||
+ `transform`
|
||||
+ `transformOrigin`
|
||||
+ `transitionDelay`
|
||||
+ `transitionDuration`
|
||||
+ `transitionProperty`
|
||||
+ `transitionTimingFunction`
|
||||
+ `userSelect`
|
||||
+ `visibility`
|
||||
+ `width`
|
||||
|
||||
@@ -4,7 +4,7 @@ It is sometimes necessary to make changes directly to a component without using
|
||||
state/props to trigger a re-render of the entire subtree – in the browser, this
|
||||
is done by directly modifying a DOM node. `setNativeProps` is the React Native
|
||||
equivalent to setting properties directly on a DOM node. Use direct
|
||||
manipulation when frequent re-rendering creates a performance bottleneck Direct
|
||||
manipulation when frequent re-rendering creates a performance bottleneck. Direct
|
||||
manipulation will not be a tool that you reach for frequently.
|
||||
|
||||
## `setNativeProps` and `shouldComponentUpdate`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-web",
|
||||
"version": "0.0.64",
|
||||
"version": "0.0.67",
|
||||
"description": "React Native for Web",
|
||||
"main": "dist/index.js",
|
||||
"files": [
|
||||
@@ -30,6 +30,7 @@
|
||||
"deep-assign": "^2.0.0",
|
||||
"fbjs": "^0.8.8",
|
||||
"inline-style-prefixer": "^2.0.5",
|
||||
"normalize-css-color": "^1.0.2",
|
||||
"react-dom": "~15.4.1",
|
||||
"react-textarea-autosize": "^4.0.4",
|
||||
"react-timer-mixin": "^0.13.3"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Animated from 'animated';
|
||||
import Image from '../../components/Image';
|
||||
import ScrollView from '../../components/ScrollView';
|
||||
import StyleSheet from '../StyleSheet';
|
||||
import Text from '../../components/Text';
|
||||
import View from '../../components/View';
|
||||
@@ -9,6 +10,7 @@ Animated.inject.FlattenStyle(StyleSheet.flatten);
|
||||
module.exports = {
|
||||
...Animated,
|
||||
Image: Animated.createAnimatedComponent(Image),
|
||||
ScrollView: Animated.createAnimatedComponent(ScrollView),
|
||||
Text: Animated.createAnimatedComponent(Text),
|
||||
View: Animated.createAnimatedComponent(View)
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ describe('apis/StyleSheet/resolveTransform', () => {
|
||||
const resolvedStyle = {};
|
||||
const style = {
|
||||
transform: [
|
||||
{ perspective: 50 },
|
||||
{ scaleX: 20 },
|
||||
{ translateX: 20 },
|
||||
{ rotate: '20deg' }
|
||||
@@ -15,7 +16,7 @@ describe('apis/StyleSheet/resolveTransform', () => {
|
||||
resolveTransform(resolvedStyle, style);
|
||||
|
||||
expect(resolvedStyle).toEqual({
|
||||
transform: 'scaleX(20) translateX(20px) rotate(20deg)'
|
||||
transform: 'perspective(50px) scaleX(20) translateX(20px) rotate(20deg)'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,23 +1,36 @@
|
||||
const unitlessNumbers = {
|
||||
animationIterationCount: true,
|
||||
borderImageOutset: true,
|
||||
borderImageSlice: true,
|
||||
borderImageWidth: true,
|
||||
boxFlex: true,
|
||||
boxFlexGroup: true,
|
||||
boxOrdinalGroup: true,
|
||||
columnCount: true,
|
||||
flex: true,
|
||||
flexGrow: true,
|
||||
flexOrder: true,
|
||||
flexPositive: true,
|
||||
flexShrink: true,
|
||||
flexNegative: true,
|
||||
fontWeight: true,
|
||||
gridRow: true,
|
||||
gridColumn: true,
|
||||
lineClamp: true,
|
||||
opacity: true,
|
||||
order: true,
|
||||
orphans: true,
|
||||
tabSize: true,
|
||||
widows: true,
|
||||
zIndex: true,
|
||||
zoom: true,
|
||||
// SVG-related
|
||||
fillOpacity: true,
|
||||
floodOpacity: true,
|
||||
stopOpacity: true,
|
||||
strokeDasharray: true,
|
||||
strokeDashoffset: true,
|
||||
strokeMiterlimit: true,
|
||||
strokeOpacity: true,
|
||||
strokeWidth: true,
|
||||
// transform types
|
||||
|
||||
@@ -95,6 +95,7 @@ const resolveProps = (reactNativeStyle) => {
|
||||
style: prefixInlineStyles(style)
|
||||
};
|
||||
|
||||
/*
|
||||
if (process.env.__REACT_NATIVE_DEBUG_ENABLED__) {
|
||||
console.groupCollapsed('[StyleSheet] resolving uncached styles');
|
||||
console.log(
|
||||
@@ -106,6 +107,7 @@ const resolveProps = (reactNativeStyle) => {
|
||||
console.log('resolve => \n', props);
|
||||
console.groupEnd();
|
||||
}
|
||||
*/
|
||||
|
||||
return props;
|
||||
};
|
||||
@@ -131,6 +133,7 @@ const StyleRegistry = {
|
||||
initialize(classNames) {
|
||||
injectedClassNames = classNames;
|
||||
|
||||
/*
|
||||
if (process.env.__REACT_NATIVE_DEBUG_ENABLED__) {
|
||||
if (global.__REACT_NATIVE_DEBUG_ENABLED__styleRegistryTimer) {
|
||||
clearInterval(global.__REACT_NATIVE_DEBUG_ENABLED__styleRegistryTimer);
|
||||
@@ -142,6 +145,7 @@ const StyleRegistry = {
|
||||
console.groupEnd();
|
||||
}, 30000);
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
reset() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import normalizeColor from '../../modules/normalizeColor';
|
||||
import normalizeColor from 'normalize-css-color';
|
||||
import normalizeValue from './normalizeValue';
|
||||
|
||||
const defaultOffset = { height: 0, width: 0 };
|
||||
@@ -6,11 +6,9 @@ const defaultOffset = { height: 0, width: 0 };
|
||||
const applyOpacity = (color, opacity = 1) => {
|
||||
const nullableColor = normalizeColor(color);
|
||||
const colorInt = nullableColor === null ? 0x00000000 : nullableColor;
|
||||
const r = Math.round(((colorInt & 0xff000000) >>> 24));
|
||||
const g = Math.round(((colorInt & 0x00ff0000) >>> 16));
|
||||
const b = Math.round(((colorInt & 0x0000ff00) >>> 8));
|
||||
const a = (((colorInt & 0x000000ff) >>> 0) / 255).toFixed(2);
|
||||
return `rgba(${r},${g},${b},${a * opacity})`;
|
||||
const { r, g, b, a } = normalizeColor.rgba(colorInt);
|
||||
const alpha = a.toFixed(2);
|
||||
return `rgba(${r},${g},${b},${alpha * opacity})`;
|
||||
};
|
||||
|
||||
// TODO: add inset and spread support
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import normalizeValue from './normalizeValue';
|
||||
|
||||
// { scale: 2 } => 'scale(2)'
|
||||
// { translateX: 20 } => 'translateX(20px)'
|
||||
// { translateX: 20 } => 'translateX(20px)'
|
||||
const mapTransform = (transform) => {
|
||||
const type = Object.keys(transform)[0];
|
||||
const value = normalizeValue(type, transform[type]);
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('apis/UIManager', () => {
|
||||
});
|
||||
|
||||
describe('measure', () => {
|
||||
test('provides correct layout to callback', () => {
|
||||
test('provides correct layout to callback', (done) => {
|
||||
const node = createNode({ height: '5000px', left: '100px', position: 'relative', top: '100px', width: '5000px' });
|
||||
document.body.appendChild(node);
|
||||
|
||||
@@ -37,7 +37,14 @@ describe('apis/UIManager', () => {
|
||||
expect(height).toEqual(5000);
|
||||
expect(pageX).toEqual(100);
|
||||
expect(pageY).toEqual(100);
|
||||
done();
|
||||
document.body.removeChild(node);
|
||||
});
|
||||
});
|
||||
|
||||
test('provides correct layout to callback', (done) => {
|
||||
const node = createNode({ height: '5000px', left: '100px', position: 'relative', top: '100px', width: '5000px' });
|
||||
document.body.appendChild(node);
|
||||
|
||||
// test values account for scroll position
|
||||
window.scrollTo(200, 200);
|
||||
@@ -51,14 +58,14 @@ describe('apis/UIManager', () => {
|
||||
expect(height).toEqual(5000);
|
||||
expect(pageX).toEqual(-100);
|
||||
expect(pageY).toEqual(-100);
|
||||
done();
|
||||
document.body.removeChild(node);
|
||||
});
|
||||
|
||||
document.body.removeChild(node);
|
||||
});
|
||||
});
|
||||
|
||||
describe('measureLayout', () => {
|
||||
test('provides correct layout to onSuccess callback', () => {
|
||||
test('provides correct layout to onSuccess callback', (done) => {
|
||||
const node = createNode({ height: '10px', width: '10px' });
|
||||
const middle = createNode({ padding: '20px' });
|
||||
const context = createNode({ padding: '20px' });
|
||||
@@ -78,14 +85,14 @@ describe('apis/UIManager', () => {
|
||||
expect(y).toEqual(40);
|
||||
expect(width).toEqual(10);
|
||||
expect(height).toEqual(10);
|
||||
done();
|
||||
document.body.removeChild(context);
|
||||
});
|
||||
|
||||
document.body.removeChild(context);
|
||||
});
|
||||
});
|
||||
|
||||
describe('measureInWindow', () => {
|
||||
test('provides correct layout to callback', () => {
|
||||
test('provides correct layout to callback', (done) => {
|
||||
const node = createNode({ height: '10px', width: '10px' });
|
||||
const middle = createNode({ padding: '20px' });
|
||||
const context = createNode({ padding: '20px' });
|
||||
@@ -105,9 +112,9 @@ describe('apis/UIManager', () => {
|
||||
expect(y).toEqual(40);
|
||||
expect(width).toEqual(10);
|
||||
expect(height).toEqual(10);
|
||||
done();
|
||||
document.body.removeChild(context);
|
||||
});
|
||||
|
||||
document.body.removeChild(context);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -119,17 +126,16 @@ describe('apis/UIManager', () => {
|
||||
}
|
||||
};
|
||||
|
||||
test('add new className to existing className', () => {
|
||||
test('supports className alias for class', () => {
|
||||
const node = createNode();
|
||||
node.className = 'existing';
|
||||
const props = { className: 'extra' };
|
||||
UIManager.updateView(node, props, componentStub);
|
||||
expect(node.getAttribute('class')).toEqual('existing extra');
|
||||
expect(node.getAttribute('class')).toEqual('extra');
|
||||
});
|
||||
|
||||
test('adds correct DOM styles to existing style', () => {
|
||||
const node = createNode({ color: 'red' });
|
||||
const props = { style: { marginVertical: 0, opacity: 0 } };
|
||||
const props = { style: { marginTop: 0, marginBottom: 0, opacity: 0 } };
|
||||
UIManager.updateView(node, props, componentStub);
|
||||
expect(node.getAttribute('style')).toEqual('color: red; margin-top: 0px; margin-bottom: 0px; opacity: 0;');
|
||||
});
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import createReactDOMStyle from '../StyleSheet/createReactDOMStyle';
|
||||
import flattenStyle from '../StyleSheet/flattenStyle';
|
||||
import asap from 'asap';
|
||||
import CSSPropertyOperations from 'react-dom/lib/CSSPropertyOperations';
|
||||
import prefixInlineStyles from '../StyleSheet/prefixInlineStyles';
|
||||
|
||||
const _measureLayout = (node, relativeToNativeNode, callback) => {
|
||||
const relativeNode = relativeToNativeNode || node.parentNode;
|
||||
const relativeRect = relativeNode.getBoundingClientRect();
|
||||
const { height, left, top, width } = node.getBoundingClientRect();
|
||||
const x = left - relativeRect.left;
|
||||
const y = top - relativeRect.top;
|
||||
callback(x, y, width, height, left, top);
|
||||
asap(() => {
|
||||
const relativeNode = relativeToNativeNode || node.parentNode;
|
||||
const relativeRect = relativeNode.getBoundingClientRect();
|
||||
const { height, left, top, width } = node.getBoundingClientRect();
|
||||
const x = left - relativeRect.left;
|
||||
const y = top - relativeRect.top;
|
||||
callback(x, y, width, height, left, top);
|
||||
});
|
||||
};
|
||||
|
||||
const UIManager = {
|
||||
@@ -44,16 +44,12 @@ const UIManager = {
|
||||
const value = props[prop];
|
||||
switch (prop) {
|
||||
case 'style': {
|
||||
const style = prefixInlineStyles(createReactDOMStyle(flattenStyle(value)));
|
||||
CSSPropertyOperations.setValueForStyles(node, style, component._reactInternalInstance);
|
||||
CSSPropertyOperations.setValueForStyles(node, value, component._reactInternalInstance);
|
||||
break;
|
||||
}
|
||||
case 'class':
|
||||
case 'className': {
|
||||
const nativeProp = 'class';
|
||||
// prevent class names managed by React Native from being replaced
|
||||
const className = `${node.getAttribute(nativeProp)} ${value}`;
|
||||
node.setAttribute(nativeProp, className);
|
||||
node.setAttribute('class', value);
|
||||
break;
|
||||
}
|
||||
case 'text':
|
||||
|
||||
@@ -222,6 +222,10 @@ class ListViewDataSource {
|
||||
return this._cachedRowCount;
|
||||
}
|
||||
|
||||
getRowAndSectionCount(): number {
|
||||
return (this._cachedRowCount + this.sectionIdentities.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the row is dirtied and needs to be rerendered
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,8 @@ import ListViewDataSource from './ListViewDataSource';
|
||||
import ListViewPropTypes from './ListViewPropTypes';
|
||||
import ScrollView from '../ScrollView';
|
||||
import StaticRenderer from '../StaticRenderer';
|
||||
import React, { Component, isEmpty, merge } from 'react';
|
||||
import React, { Component } from 'react';
|
||||
import isEmpty from 'fbjs/lib/isEmpty';
|
||||
import requestAnimationFrame from 'fbjs/lib/requestAnimationFrame';
|
||||
|
||||
const DEFAULT_PAGE_SIZE = 1;
|
||||
@@ -245,7 +246,7 @@ class ListView extends Component {
|
||||
}
|
||||
if (updatedFrames) {
|
||||
updatedFrames.forEach((newFrame) => {
|
||||
this._childFrames[newFrame.index] = merge(newFrame);
|
||||
this._childFrames[newFrame.index] = Object.assign({}, newFrame);
|
||||
});
|
||||
}
|
||||
const isVertical = !this.props.horizontal;
|
||||
|
||||
@@ -18,7 +18,8 @@ rn-paddingBottom:0px
|
||||
rn-paddingLeft:0px
|
||||
rn-textDecoration:none
|
||||
rn-whiteSpace:pre-wrap
|
||||
rn-wordWrap:break-word">
|
||||
rn-wordWrap:break-word"
|
||||
dir="auto">
|
||||
children
|
||||
</span>
|
||||
`;
|
||||
@@ -45,6 +46,7 @@ rn-paddingLeft:0px
|
||||
rn-textDecoration:none
|
||||
rn-whiteSpace:pre-wrap
|
||||
rn-wordWrap:break-word"
|
||||
dir="auto"
|
||||
onClick={[Function]}
|
||||
onKeyDown={[Function]}
|
||||
style={Object {}}
|
||||
@@ -71,7 +73,8 @@ rn-paddingBottom:0px
|
||||
rn-paddingLeft:0px
|
||||
rn-textDecoration:none
|
||||
rn-whiteSpace:pre-wrap
|
||||
rn-wordWrap:break-word" />
|
||||
rn-wordWrap:break-word"
|
||||
dir="auto" />
|
||||
`;
|
||||
|
||||
exports[`components/Text prop "selectable" 2`] = `
|
||||
@@ -96,5 +99,6 @@ rn-textDecoration:none
|
||||
rn-userSelect:none
|
||||
rn-whiteSpace:pre-wrap
|
||||
rn-wordWrap:break-word"
|
||||
dir="auto"
|
||||
style={Object {}} />
|
||||
`;
|
||||
|
||||
@@ -56,6 +56,8 @@ class Text extends Component {
|
||||
numberOfLines === 1 && styles.singleLineStyle,
|
||||
onPress && styles.pressable
|
||||
];
|
||||
// allow browsers to automatically infer the language writing direction
|
||||
otherProps.dir = 'auto';
|
||||
|
||||
return createDOMElement('span', otherProps);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
/* @edit start */
|
||||
const BoundingDimensions = require('./BoundingDimensions');
|
||||
const normalizeColor = require('../../modules/normalizeColor');
|
||||
const Position = require('./Position');
|
||||
const React = require('react');
|
||||
const TouchEventUtils = require('fbjs/lib/TouchEventUtils');
|
||||
|
||||
@@ -27,7 +27,6 @@ var ViewStylePropTypes = require('../View/ViewStylePropTypes');
|
||||
|
||||
var ensureComponentIsNative = require('./ensureComponentIsNative');
|
||||
var ensurePositiveDelayProps = require('./ensurePositiveDelayProps');
|
||||
var keyOf = require('fbjs/lib/keyOf');
|
||||
|
||||
type Event = Object;
|
||||
|
||||
@@ -268,8 +267,9 @@ var TouchableHighlight = React.createClass({
|
||||
}
|
||||
});
|
||||
|
||||
var CHILD_REF = keyOf({childRef: null});
|
||||
var UNDERLAY_REF = keyOf({underlayRef: null});
|
||||
var CHILD_REF = 'childRef';
|
||||
var UNDERLAY_REF = 'underlayRef';
|
||||
|
||||
var INACTIVE_CHILD_PROPS = {
|
||||
style: StyleSheet.create({x: {opacity: 1.0}}).x,
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ var TouchableOpacity = React.createClass({
|
||||
this.setNativeProps({
|
||||
style: {
|
||||
opacity: value,
|
||||
transitionDuration: duration
|
||||
transitionDuration: `${duration / 1000}s`
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -27,15 +27,18 @@ module.exports = process.env.NODE_ENV !== 'production' ? {
|
||||
backgroundAttachment: string,
|
||||
backgroundClip: string,
|
||||
backgroundImage: string,
|
||||
backgroundPosition: string,
|
||||
backgroundOrigin: oneOf([ 'border-box', 'content-box', 'padding-box' ]),
|
||||
backgroundPosition: string,
|
||||
backgroundRepeat: string,
|
||||
backgroundSize: string,
|
||||
boxShadow: string,
|
||||
cursor: string,
|
||||
display: string,
|
||||
outline: string,
|
||||
overflowX: autoOrHiddenOrVisible,
|
||||
overflowY: autoOrHiddenOrVisible,
|
||||
perspective: PropTypes.oneOfType([ number, string ]),
|
||||
perspectiveOrigin: string,
|
||||
transitionDelay: string,
|
||||
transitionDuration: string,
|
||||
transitionProperty: string,
|
||||
|
||||
@@ -7,8 +7,21 @@
|
||||
*/
|
||||
|
||||
import findNodeHandle from '../findNodeHandle';
|
||||
import StyleRegistry from '../../apis/StyleSheet/registry';
|
||||
import UIManager from '../../apis/UIManager';
|
||||
|
||||
const REGEX_CLASSNAME_SPLIT = /\s+/;
|
||||
const REGEX_STYLE_PROP = /rn-(.*):.*/;
|
||||
|
||||
const classNameFilter = (className) => { return className !== ''; };
|
||||
const classNameToList = (className = '') => className.split(REGEX_CLASSNAME_SPLIT).filter(classNameFilter);
|
||||
const getStyleProp = (className) => {
|
||||
const match = className.match(REGEX_STYLE_PROP);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
};
|
||||
|
||||
const NativeMethodsMixin = {
|
||||
/**
|
||||
* Removes focus from an input or view. This is the opposite of `focus()`.
|
||||
@@ -45,7 +58,7 @@ const NativeMethodsMixin = {
|
||||
* - height
|
||||
*
|
||||
* Note that these measurements are not available until after the rendering
|
||||
* has been completed in native.
|
||||
* has been completed.
|
||||
*/
|
||||
measureInWindow(callback) {
|
||||
UIManager.measureInWindow(findNodeHandle(this), callback);
|
||||
@@ -60,9 +73,49 @@ const NativeMethodsMixin = {
|
||||
|
||||
/**
|
||||
* This function sends props straight to the underlying DOM node.
|
||||
* This works as if all styles were set as inline styles. Since a DOM node
|
||||
* may aleady be styled with class names and inline styles, we need to get
|
||||
* the initial styles from the DOM node and merge them with incoming props.
|
||||
*/
|
||||
setNativeProps(nativeProps: Object) {
|
||||
UIManager.updateView(findNodeHandle(this), nativeProps, this);
|
||||
// DOM state
|
||||
const node = findNodeHandle(this);
|
||||
const domClassList = [ ...node.classList ];
|
||||
|
||||
// Resolved state
|
||||
const resolvedProps = StyleRegistry.resolve(nativeProps.style);
|
||||
const resolvedClassList = classNameToList(resolvedProps.className);
|
||||
|
||||
// Merged state
|
||||
const classList = [];
|
||||
const style = { ...resolvedProps.style };
|
||||
|
||||
// The node has class names that we need to override.
|
||||
// Only pass on a class name when the style is unchanged.
|
||||
domClassList.forEach((c) => {
|
||||
const prop = getStyleProp(c);
|
||||
if (resolvedProps.className.indexOf(prop) === -1) {
|
||||
classList.push(c);
|
||||
}
|
||||
});
|
||||
|
||||
// The node has styles that we need to override.
|
||||
// Remove any inline style that may collide with a new class name.
|
||||
resolvedClassList.forEach((c) => {
|
||||
const prop = getStyleProp(c);
|
||||
classList.push(c);
|
||||
style[prop] = null;
|
||||
});
|
||||
|
||||
const className = `\n${classList.sort().join('\n')}`;
|
||||
|
||||
const props = {
|
||||
...nativeProps,
|
||||
className,
|
||||
style
|
||||
};
|
||||
|
||||
UIManager.updateView(node, props, this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,353 +0,0 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule normalizeColor
|
||||
* @flow
|
||||
*/
|
||||
/* eslint no-bitwise: 0 */
|
||||
'use strict';
|
||||
|
||||
function normalizeColor(color: string | number): ?number {
|
||||
var match;
|
||||
|
||||
if (typeof color === 'number') {
|
||||
if (color >>> 0 === color && color >= 0 && color <= 0xffffffff) {
|
||||
return color;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ordered based on occurrences on Facebook codebase
|
||||
if ((match = matchers.hex6.exec(color))) {
|
||||
return parseInt(match[1] + 'ff', 16) >>> 0;
|
||||
}
|
||||
|
||||
if (names.hasOwnProperty(color)) {
|
||||
return names[color];
|
||||
}
|
||||
|
||||
if ((match = matchers.rgb.exec(color))) {
|
||||
return (
|
||||
parse255(match[1]) << 24 | // r
|
||||
parse255(match[2]) << 16 | // g
|
||||
parse255(match[3]) << 8 | // b
|
||||
0x000000ff // a
|
||||
) >>> 0;
|
||||
}
|
||||
|
||||
if ((match = matchers.rgba.exec(color))) {
|
||||
return (
|
||||
parse255(match[1]) << 24 | // r
|
||||
parse255(match[2]) << 16 | // g
|
||||
parse255(match[3]) << 8 | // b
|
||||
parse1(match[4]) // a
|
||||
) >>> 0;
|
||||
}
|
||||
|
||||
if ((match = matchers.hex3.exec(color))) {
|
||||
return parseInt(
|
||||
match[1] + match[1] + // r
|
||||
match[2] + match[2] + // g
|
||||
match[3] + match[3] + // b
|
||||
'ff', // a
|
||||
16
|
||||
) >>> 0;
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-color-4/#hex-notation
|
||||
if ((match = matchers.hex8.exec(color))) {
|
||||
return parseInt(match[1], 16) >>> 0;
|
||||
}
|
||||
|
||||
if ((match = matchers.hex4.exec(color))) {
|
||||
return parseInt(
|
||||
match[1] + match[1] + // r
|
||||
match[2] + match[2] + // g
|
||||
match[3] + match[3] + // b
|
||||
match[4] + match[4], // a
|
||||
16
|
||||
) >>> 0;
|
||||
}
|
||||
|
||||
if ((match = matchers.hsl.exec(color))) {
|
||||
return (
|
||||
hslToRgb(
|
||||
parse360(match[1]), // h
|
||||
parsePercentage(match[2]), // s
|
||||
parsePercentage(match[3]) // l
|
||||
) |
|
||||
0x000000ff // a
|
||||
) >>> 0;
|
||||
}
|
||||
|
||||
if ((match = matchers.hsla.exec(color))) {
|
||||
return (
|
||||
hslToRgb(
|
||||
parse360(match[1]), // h
|
||||
parsePercentage(match[2]), // s
|
||||
parsePercentage(match[3]) // l
|
||||
) |
|
||||
parse1(match[4]) // a
|
||||
) >>> 0;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function hue2rgb(p: number, q: number, t: number): number {
|
||||
if (t < 0) {
|
||||
t += 1;
|
||||
}
|
||||
if (t > 1) {
|
||||
t -= 1;
|
||||
}
|
||||
if (t < 1 / 6) {
|
||||
return p + (q - p) * 6 * t;
|
||||
}
|
||||
if (t < 1 / 2) {
|
||||
return q;
|
||||
}
|
||||
if (t < 2 / 3) {
|
||||
return p + (q - p) * (2 / 3 - t) * 6;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
function hslToRgb(h: number, s: number, l: number): number {
|
||||
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||
var p = 2 * l - q;
|
||||
var r = hue2rgb(p, q, h + 1 / 3);
|
||||
var g = hue2rgb(p, q, h);
|
||||
var b = hue2rgb(p, q, h - 1 / 3);
|
||||
|
||||
return (
|
||||
Math.round(r * 255) << 24 |
|
||||
Math.round(g * 255) << 16 |
|
||||
Math.round(b * 255) << 8
|
||||
);
|
||||
}
|
||||
|
||||
// var INTEGER = '[-+]?\\d+';
|
||||
var NUMBER = '[-+]?\\d*\\.?\\d+';
|
||||
var PERCENTAGE = NUMBER + '%';
|
||||
|
||||
function call(...args) {
|
||||
return '\\(\\s*(' + args.join(')\\s*,\\s*(') + ')\\s*\\)';
|
||||
}
|
||||
|
||||
var matchers = {
|
||||
rgb: new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER)),
|
||||
rgba: new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER)),
|
||||
hsl: new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE)),
|
||||
hsla: new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)),
|
||||
hex3: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
||||
hex4: /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
||||
hex6: /^#([0-9a-fA-F]{6})$/,
|
||||
hex8: /^#([0-9a-fA-F]{8})$/,
|
||||
};
|
||||
|
||||
function parse255(str: string): number {
|
||||
var int = parseInt(str, 10);
|
||||
if (int < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (int > 255) {
|
||||
return 255;
|
||||
}
|
||||
return int;
|
||||
}
|
||||
|
||||
function parse360(str: string): number {
|
||||
var int = parseFloat(str);
|
||||
return (((int % 360) + 360) % 360) / 360;
|
||||
}
|
||||
|
||||
function parse1(str: string): number {
|
||||
var num = parseFloat(str);
|
||||
if (num < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (num > 1) {
|
||||
return 255;
|
||||
}
|
||||
return Math.round(num * 255);
|
||||
}
|
||||
|
||||
function parsePercentage(str: string): number {
|
||||
// parseFloat conveniently ignores the final %
|
||||
var int = parseFloat(str, 10);
|
||||
if (int < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (int > 100) {
|
||||
return 1;
|
||||
}
|
||||
return int / 100;
|
||||
}
|
||||
|
||||
var names = {
|
||||
/* @edit start */
|
||||
currentcolor: 'currentcolor',
|
||||
inherit: 'inherit',
|
||||
/* @edit end */
|
||||
transparent: 0x00000000,
|
||||
|
||||
// http://www.w3.org/TR/css3-color/#svg-color
|
||||
aliceblue: 0xf0f8ffff,
|
||||
antiquewhite: 0xfaebd7ff,
|
||||
aqua: 0x00ffffff,
|
||||
aquamarine: 0x7fffd4ff,
|
||||
azure: 0xf0ffffff,
|
||||
beige: 0xf5f5dcff,
|
||||
bisque: 0xffe4c4ff,
|
||||
black: 0x000000ff,
|
||||
blanchedalmond: 0xffebcdff,
|
||||
blue: 0x0000ffff,
|
||||
blueviolet: 0x8a2be2ff,
|
||||
brown: 0xa52a2aff,
|
||||
burlywood: 0xdeb887ff,
|
||||
burntsienna: 0xea7e5dff,
|
||||
cadetblue: 0x5f9ea0ff,
|
||||
chartreuse: 0x7fff00ff,
|
||||
chocolate: 0xd2691eff,
|
||||
coral: 0xff7f50ff,
|
||||
cornflowerblue: 0x6495edff,
|
||||
cornsilk: 0xfff8dcff,
|
||||
crimson: 0xdc143cff,
|
||||
cyan: 0x00ffffff,
|
||||
darkblue: 0x00008bff,
|
||||
darkcyan: 0x008b8bff,
|
||||
darkgoldenrod: 0xb8860bff,
|
||||
darkgray: 0xa9a9a9ff,
|
||||
darkgreen: 0x006400ff,
|
||||
darkgrey: 0xa9a9a9ff,
|
||||
darkkhaki: 0xbdb76bff,
|
||||
darkmagenta: 0x8b008bff,
|
||||
darkolivegreen: 0x556b2fff,
|
||||
darkorange: 0xff8c00ff,
|
||||
darkorchid: 0x9932ccff,
|
||||
darkred: 0x8b0000ff,
|
||||
darksalmon: 0xe9967aff,
|
||||
darkseagreen: 0x8fbc8fff,
|
||||
darkslateblue: 0x483d8bff,
|
||||
darkslategray: 0x2f4f4fff,
|
||||
darkslategrey: 0x2f4f4fff,
|
||||
darkturquoise: 0x00ced1ff,
|
||||
darkviolet: 0x9400d3ff,
|
||||
deeppink: 0xff1493ff,
|
||||
deepskyblue: 0x00bfffff,
|
||||
dimgray: 0x696969ff,
|
||||
dimgrey: 0x696969ff,
|
||||
dodgerblue: 0x1e90ffff,
|
||||
firebrick: 0xb22222ff,
|
||||
floralwhite: 0xfffaf0ff,
|
||||
forestgreen: 0x228b22ff,
|
||||
fuchsia: 0xff00ffff,
|
||||
gainsboro: 0xdcdcdcff,
|
||||
ghostwhite: 0xf8f8ffff,
|
||||
gold: 0xffd700ff,
|
||||
goldenrod: 0xdaa520ff,
|
||||
gray: 0x808080ff,
|
||||
green: 0x008000ff,
|
||||
greenyellow: 0xadff2fff,
|
||||
grey: 0x808080ff,
|
||||
honeydew: 0xf0fff0ff,
|
||||
hotpink: 0xff69b4ff,
|
||||
indianred: 0xcd5c5cff,
|
||||
indigo: 0x4b0082ff,
|
||||
ivory: 0xfffff0ff,
|
||||
khaki: 0xf0e68cff,
|
||||
lavender: 0xe6e6faff,
|
||||
lavenderblush: 0xfff0f5ff,
|
||||
lawngreen: 0x7cfc00ff,
|
||||
lemonchiffon: 0xfffacdff,
|
||||
lightblue: 0xadd8e6ff,
|
||||
lightcoral: 0xf08080ff,
|
||||
lightcyan: 0xe0ffffff,
|
||||
lightgoldenrodyellow: 0xfafad2ff,
|
||||
lightgray: 0xd3d3d3ff,
|
||||
lightgreen: 0x90ee90ff,
|
||||
lightgrey: 0xd3d3d3ff,
|
||||
lightpink: 0xffb6c1ff,
|
||||
lightsalmon: 0xffa07aff,
|
||||
lightseagreen: 0x20b2aaff,
|
||||
lightskyblue: 0x87cefaff,
|
||||
lightslategray: 0x778899ff,
|
||||
lightslategrey: 0x778899ff,
|
||||
lightsteelblue: 0xb0c4deff,
|
||||
lightyellow: 0xffffe0ff,
|
||||
lime: 0x00ff00ff,
|
||||
limegreen: 0x32cd32ff,
|
||||
linen: 0xfaf0e6ff,
|
||||
magenta: 0xff00ffff,
|
||||
maroon: 0x800000ff,
|
||||
mediumaquamarine: 0x66cdaaff,
|
||||
mediumblue: 0x0000cdff,
|
||||
mediumorchid: 0xba55d3ff,
|
||||
mediumpurple: 0x9370dbff,
|
||||
mediumseagreen: 0x3cb371ff,
|
||||
mediumslateblue: 0x7b68eeff,
|
||||
mediumspringgreen: 0x00fa9aff,
|
||||
mediumturquoise: 0x48d1ccff,
|
||||
mediumvioletred: 0xc71585ff,
|
||||
midnightblue: 0x191970ff,
|
||||
mintcream: 0xf5fffaff,
|
||||
mistyrose: 0xffe4e1ff,
|
||||
moccasin: 0xffe4b5ff,
|
||||
navajowhite: 0xffdeadff,
|
||||
navy: 0x000080ff,
|
||||
oldlace: 0xfdf5e6ff,
|
||||
olive: 0x808000ff,
|
||||
olivedrab: 0x6b8e23ff,
|
||||
orange: 0xffa500ff,
|
||||
orangered: 0xff4500ff,
|
||||
orchid: 0xda70d6ff,
|
||||
palegoldenrod: 0xeee8aaff,
|
||||
palegreen: 0x98fb98ff,
|
||||
paleturquoise: 0xafeeeeff,
|
||||
palevioletred: 0xdb7093ff,
|
||||
papayawhip: 0xffefd5ff,
|
||||
peachpuff: 0xffdab9ff,
|
||||
peru: 0xcd853fff,
|
||||
pink: 0xffc0cbff,
|
||||
plum: 0xdda0ddff,
|
||||
powderblue: 0xb0e0e6ff,
|
||||
purple: 0x800080ff,
|
||||
rebeccapurple: 0x663399ff,
|
||||
red: 0xff0000ff,
|
||||
rosybrown: 0xbc8f8fff,
|
||||
royalblue: 0x4169e1ff,
|
||||
saddlebrown: 0x8b4513ff,
|
||||
salmon: 0xfa8072ff,
|
||||
sandybrown: 0xf4a460ff,
|
||||
seagreen: 0x2e8b57ff,
|
||||
seashell: 0xfff5eeff,
|
||||
sienna: 0xa0522dff,
|
||||
silver: 0xc0c0c0ff,
|
||||
skyblue: 0x87ceebff,
|
||||
slateblue: 0x6a5acdff,
|
||||
slategray: 0x708090ff,
|
||||
slategrey: 0x708090ff,
|
||||
snow: 0xfffafaff,
|
||||
springgreen: 0x00ff7fff,
|
||||
steelblue: 0x4682b4ff,
|
||||
tan: 0xd2b48cff,
|
||||
teal: 0x008080ff,
|
||||
thistle: 0xd8bfd8ff,
|
||||
tomato: 0xff6347ff,
|
||||
turquoise: 0x40e0d0ff,
|
||||
violet: 0xee82eeff,
|
||||
wheat: 0xf5deb3ff,
|
||||
white: 0xffffffff,
|
||||
whitesmoke: 0xf5f5f5ff,
|
||||
yellow: 0xffff00ff,
|
||||
yellowgreen: 0x9acd32ff,
|
||||
};
|
||||
|
||||
module.exports = normalizeColor;
|
||||
@@ -13,7 +13,7 @@
|
||||
import { PropTypes } from 'react'
|
||||
|
||||
var colorPropType = function(isRequired, props, propName, componentName, location, propFullName) {
|
||||
var normalizeColor = require('../modules/normalizeColor');
|
||||
var normalizeColor = require('normalize-css-color');
|
||||
var ReactPropTypeLocationNames = require('react-dom/lib/ReactPropTypeLocationNames');
|
||||
var color = props[propName];
|
||||
if (color === undefined || color === null) {
|
||||
@@ -34,6 +34,10 @@ var colorPropType = function(isRequired, props, propName, componentName, locatio
|
||||
return;
|
||||
}
|
||||
|
||||
if (color === 'currentcolor' || color === 'inherit') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (normalizeColor(color) === null) {
|
||||
var locationName = ReactPropTypeLocationNames[location];
|
||||
return new Error(
|
||||
|
||||
@@ -28,7 +28,8 @@ const TransformPropTypes = process.env.NODE_ENV !== 'production' ? {
|
||||
shape({ translateZ: numberOrString }),
|
||||
shape({ translate3d: string })
|
||||
])
|
||||
)
|
||||
),
|
||||
transformOrigin: string
|
||||
} : {};
|
||||
|
||||
module.exports = TransformPropTypes;
|
||||
|
||||
17
yarn.lock
17
yarn.lock
@@ -2299,18 +2299,7 @@ fb-watchman@^1.8.0, fb-watchman@^1.9.0:
|
||||
dependencies:
|
||||
bser "^1.0.2"
|
||||
|
||||
fbjs@^0.8.1, fbjs@^0.8.4:
|
||||
version "0.8.6"
|
||||
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.6.tgz#7eb67d6986b2d5007a9b6e92e0e7cb6f75cad290"
|
||||
dependencies:
|
||||
core-js "^1.0.0"
|
||||
isomorphic-fetch "^2.1.1"
|
||||
loose-envify "^1.0.0"
|
||||
object-assign "^4.1.0"
|
||||
promise "^7.1.1"
|
||||
ua-parser-js "^0.7.9"
|
||||
|
||||
fbjs@^0.8.8:
|
||||
fbjs@^0.8.1, fbjs@^0.8.4, fbjs@^0.8.8:
|
||||
version "0.8.8"
|
||||
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.8.tgz#02f1b6e0ea0d46c24e0b51a2d24df069563a5ad6"
|
||||
dependencies:
|
||||
@@ -4033,6 +4022,10 @@ normalize-css-color@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/normalize-css-color/-/normalize-css-color-1.0.1.tgz#792f59cae25036950a9127cfcfddc073048f4f9d"
|
||||
|
||||
normalize-css-color@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/normalize-css-color/-/normalize-css-color-1.0.2.tgz#02991e97cccec6623fe573afbbf0de6a1f3e9f8d"
|
||||
|
||||
normalize-package-data@^2.3.2, normalize-package-data@^2.3.4:
|
||||
version "2.3.5"
|
||||
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.3.5.tgz#8d924f142960e1777e7ffe170543631cc7cb02df"
|
||||
|
||||
Reference in New Issue
Block a user