react-native/Libraries/ART
Liu Zhanhong 6b29fe78c4 Avoid creating a new Path instance for performance
Summary:
New a Path instance will cause a slice call to exist path.

```js
// react-native/Libraries/ART/ARTSerializablePath.js
if (path instanceof SerializablePath) {
  this.path = path.path.slice(0);
}
```

Most of d3's APIs can set context when we don't want to use d3's build-in path object. And in RN envirenment, we must use RN's path instance. So we can use RN's path as a context in d3 avoiding doing conversions from svg's path string to arrays. But with existing code, when Shape receive a `d` proprety, it new a path instance and will cause calling slice in a very large array.

Typical usage is as follows

```js
import React from 'react';
import { View, ART } from 'react-native';
import { line } from 'd3-shape';
import { scaleLinear } from 'd3-scale';

const { Path, Surface, Shape } = ART;
const width = 360;
const height = 300;
const data = [5,2,7,6,9,1,8,4,3];
const x = scaleLinear().range([0, width]).domain([0, data.length]);
const y = scaleLinear().range([height, 0]).domain([0, 9]);
const myline = line()
    .x(function(d, i) {
      return x(i);
    })
    .y(function(d) { return y(d); });

// use RN's ART Path
const path = Path();
myline.context(path)(data);

class TestArt extends React.Component {
  render() {
    return (
      <View>
        <Surface width={width} height={height}>
          <Shape
            stroke="red"
            d={
              // use RN's ART Path
              path
              // use d3's path
              // myline(data)
            }
          />
        </Surface>
      </View>
    );
  }
}
```
Closes https://github.com/facebook/react-native/pull/14551

Differential Revision: D5398653

Pulled By: javache

fbshipit-source-id: 1264acfb8844b60584604a664e0474f9e212d1d1
2017-07-11 11:18:56 -07:00
..
ART.xcodeproj Apple TV Support: Add tvOS build support for ART library 2017-04-20 16:15:38 -07:00
Brushes Remove REACT_HEADERS from RN BUCK file 2016-12-05 10:43:33 -08:00
ViewManagers Remove REACT_HEADERS from RN BUCK file 2016-12-05 10:43:33 -08:00
ARTCGFloatArray.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTContainer.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTGroup.h Implement clipping rectangle for ReactNativeART 2016-04-11 19:19:17 -07:00
ARTGroup.m Implement clipping rectangle for ReactNativeART 2016-04-11 19:19:17 -07:00
ARTNode.h Remove REACT_HEADERS from RN BUCK file 2016-12-05 10:43:33 -08:00
ARTNode.m Fixed ART views 2016-06-08 00:13:30 -07:00
ARTRenderable.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTRenderable.m [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTSerializablePath.js [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00
ARTShape.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTShape.m [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTSurfaceView.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTSurfaceView.m Remove REACT_HEADERS from RN BUCK file 2016-12-05 10:43:33 -08:00
ARTText.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
ARTText.m Fixed ART Text 2015-07-10 08:31:21 -08:00
ARTTextFrame.h [react-native] Open-source ReactART for native 2015-04-29 15:21:48 -08:00
RCTConvert+ART.h Remove REACT_HEADERS from RN BUCK file 2016-12-05 10:43:33 -08:00
RCTConvert+ART.m Remove REACT_HEADERS from RN BUCK file 2016-12-05 10:43:33 -08:00
ReactNativeART.js Avoid creating a new Path instance for performance 2017-07-11 11:18:56 -07:00