Files
react-native-svg/elements/ClipPath.js
Horcrux 2516a778ba use createReactNativeComponentClass inside from react
due to the peerDependency of react-native is >=0.29.0.
so there is no need to consider compatibility with react-native@0.27.0
and below.
2016-07-18 17:35:42 +08:00

43 lines
1.1 KiB
JavaScript

import React, {Component, PropTypes} from 'react';
import {set, remove} from '../lib/extract/extractClipping';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {ClipPathAttributes} from '../lib/attributes';
class ClipPath extends Component{
static displayName = 'ClipPath';
static propTypes = {
id: PropTypes.string.isRequired
};
constructor() {
super(...arguments);
this.id = this.props.id + ':' + this.props.svgId;
}
componentWillReceiveProps = nextProps => {
let id = nextProps.id + ':' + nextProps.svgId;
if (id !== this.id) {
remove(this.id);
}
};
componentWillUnmount = () => {
remove(this.id);
};
render() {
set(this.id, this.id);
return <RNSVGClipPath
name={this.id}
>{this.props.children}</RNSVGClipPath>;
}
}
const RNSVGClipPath = createReactNativeComponentClass({
validAttributes: ClipPathAttributes,
uiViewClassName: 'RNSVGClipPath'
});
export default ClipPath;