2015-04-17 00:14:11 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-04-17 00:14:11 +00:00
|
|
|
*
|
2018-08-23 19:46:43 +00:00
|
|
|
* @flow strict-local
|
2017-09-25 05:57:35 +00:00
|
|
|
* @format
|
2015-04-17 00:14:11 +00:00
|
|
|
*/
|
2018-05-07 23:45:16 +00:00
|
|
|
|
2015-04-17 00:14:11 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-11-04 12:40:26 +00:00
|
|
|
const createReactNativeComponentClass = require('createReactNativeComponentClass');
|
2018-08-23 19:46:43 +00:00
|
|
|
const getNativeComponentAttributes = require('getNativeComponentAttributes');
|
2015-04-17 00:14:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-01 19:37:22 +00:00
|
|
|
* Creates values that can be used like React components which represent native
|
|
|
|
* view managers. You should create JavaScript modules that wrap these values so
|
|
|
|
* that the results are memoized. Example:
|
2015-04-17 01:17:19 +00:00
|
|
|
*
|
2018-06-01 19:37:22 +00:00
|
|
|
* const View = requireNativeComponent('RCTView');
|
2015-04-17 00:14:11 +00:00
|
|
|
*
|
|
|
|
*/
|
2018-06-01 19:37:22 +00:00
|
|
|
const requireNativeComponent = (uiViewClassName: string): string =>
|
2018-08-23 19:46:43 +00:00
|
|
|
createReactNativeComponentClass(uiViewClassName, () =>
|
|
|
|
getNativeComponentAttributes(uiViewClassName),
|
|
|
|
);
|
Reimplement color processing
Summary:
**Problem:**
As I was trying to document what color formats we supported, I realized that our current implementation based on the open source project tinycolor supported some crazy things. A few examples that were all valid:
```
tinycolor('abc')
tinycolor(' #abc ')
tinycolor('##abc')
tinycolor('rgb 255 0 0')
tinycolor('RGBA(0, 1, 2)')
tinycolor('rgb (0, 1, 2)')
tinycolor('hsv(0, 1, 2)')
tinycolor({r: 10, g: 10, b: 10})
tinycolor('hsl(1%, 2, 3)')
tinycolor('rgb(1.0, 2.0, 3.0)')
tinycolor('rgb(1%, 2%, 3%)')
```
The integrations of tinycolor were also really bad. processColor added "support" for pure numbers and an array of colors!?? ColorPropTypes did some crazy trim().toString() and repeated a bad error message twice.
**Solution:**
While iteratively cleaning the file, I eventually ended up reimplementing it entierly. Major changes are:
- The API is now dead simple: returns null if it doesn't parse or returns the int32 representation of the color
- Stricter parsing of at
Closes https://github.com/facebook/react-native/pull/5529
Reviewed By: svcscm
Differential Revision: D2872015
Pulled By: nicklockwood
fb-gh-sync-id: df78244eefce6cf8e8ed2ea51f58d6b232de16f9
2016-01-29 17:11:53 +00:00
|
|
|
|
2015-04-17 00:14:11 +00:00
|
|
|
module.exports = requireNativeComponent;
|