diff --git a/Example/examples.js b/Example/examples.js index 608f5cc1..eeccf707 100644 --- a/Example/examples.js +++ b/Example/examples.js @@ -6,6 +6,7 @@ import * as Line from './examples/Line'; import * as Polygon from './examples/Polygon'; import * as Polyline from './examples/Polyline'; import * as Path from './examples/Path'; +import * as Text from './examples/Text'; export { Svg, @@ -15,5 +16,6 @@ export { Line, Polygon, Polyline, - Path + Path, + Text }; diff --git a/Example/examples/Path.js b/Example/examples/Path.js index 04b50ef2..857c035d 100644 --- a/Example/examples/Path.js +++ b/Example/examples/Path.js @@ -83,15 +83,15 @@ class BezierCurve extends Component{ A - B - C + B + C + ; } diff --git a/Example/examples/Stroking.js b/Example/examples/Stroking.js new file mode 100644 index 00000000..812c161c --- /dev/null +++ b/Example/examples/Stroking.js @@ -0,0 +1,47 @@ +import React, { + Component +} from 'react-native'; + +import Svg, { + Line +} from 'react-native-art-svg'; + +class LineExample extends Component{ + static title = 'Line'; + render() { + return + + ; + } +} + +const icon = + +; + +const samples = [LineExample]; + +export { + icon, + samples +} diff --git a/Example/examples/Svg.js b/Example/examples/Svg.js index 3a144774..038caba0 100644 --- a/Example/examples/Svg.js +++ b/Example/examples/Svg.js @@ -35,6 +35,35 @@ class SvgExample extends Component{ } } +class SvgViewbox extends Component{ + static title = 'SVG with `viewbox` prop'; + render() { + return + + + ; + } +} + class SvgOpacity extends Component{ static title = 'SVG with `opacity` prop'; render() { diff --git a/Example/examples/Text.js b/Example/examples/Text.js new file mode 100644 index 00000000..83f19592 --- /dev/null +++ b/Example/examples/Text.js @@ -0,0 +1,96 @@ +import React, { + Component +} from 'react-native'; + +import Svg, { + Text +} from 'react-native-art-svg'; + +class TextExample extends Component{ + static title = 'Text'; + render() { + return + I love SVG! + ; + } +} + +class TextRotate extends Component{ + static title = 'Transform the text'; + render() { + return + I love SVG + I love SVG + I love SVG + ; + } +} + +// TODO: wait for official done +class TextPath extends Component{ + static title = 'Transform the text'; + render() { + return + We go up, then we go down, then up again + ; + } +} + +const icon = + +; + +const samples = [TextExample, TextRotate]; + +export { + icon, + samples +} diff --git a/Example/main.js b/Example/main.js index 636e4864..bedb93f5 100644 --- a/Example/main.js +++ b/Example/main.js @@ -107,7 +107,7 @@ const styles = StyleSheet.create({ }); -const names = ['Svg', 'Circle', 'Ellipse', 'G', 'Path', 'Polygon', 'Polyline', 'Line', 'Rect']; +const names = ['Svg', 'Circle', 'Ellipse', 'G', 'Text', 'Path', 'Polygon', 'Polyline', 'Line', 'Rect']; class ArtSvgExample extends Component { constructor() { @@ -157,7 +157,7 @@ class ArtSvgExample extends Component { Animated.timing(this.state.scale, { toValue: 0, easing: Easing.in(Easing.back(2)) - }).start(() => this.setState({ + }).start(({finished}) => finished && this.setState({ modal: false, content: null })); diff --git a/README.md b/README.md index 431a718a..504cf518 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,35 @@ ### react-native-art-svg -TODO: +TODO: 1. fill-rule:evenodd 2. gradients 3. text 4. other elements 5. animations https://github.com/maxwellito/vivus + + +elements: +1.defs + + +2.tref ! +3.tspan ! + + + +4.clipPath (wait for official todo) +5.svg:viewBox (wait for official todo) + + +6.glyph ? missing-glyph? + +7.linearGradient + +8.marker? +9.pattern +10.radialGradient +11.stop +12.symbol +13.use +14.textPath diff --git a/elements/Svg.js b/elements/Svg.js index 81c08a20..f385d67b 100644 --- a/elements/Svg.js +++ b/elements/Svg.js @@ -1,17 +1,52 @@ import React, { ART, - Component + Component, + PropTypes } from 'react-native'; +import _ from 'lodash'; let { - Surface + Surface, + ClippingRectangle } = ART; +function extractViewbox({viewbox, width, height}) { + let x = 0; + let y = 0; + if (typeof viewbox === 'string') { + let parts = viewbox.trim().split(/\s+/); + if (parts.length === 4) { + return { + x: parts[0], + y: parts[1], + width: parts[2], + height: parts[3] + } + } + } + return { + x, + y, + width, + height + }; +} + class Svg extends Component{ static displayName = 'Svg'; + static propType = { + opacity: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + viewbox: PropTypes.string + }; + render() { let opacity = +this.props.opacity; - + let { + x, + y, + width, + height + } = extractViewbox(this.props); return ; + > + + {this.props.children} + + ; } } diff --git a/elements/Text.js b/elements/Text.js index 37aa6860..018589ad 100644 --- a/elements/Text.js +++ b/elements/Text.js @@ -5,12 +5,13 @@ import React, { } from 'react-native'; let { - Text:ARTText, - Shape + Text:ARTText } = ART; import fillFilter from '../lib/fillFilter'; import strokeFilter from '../lib/strokeFilter'; + +const fontFamily = '"Helvetica Neue", "Helvetica", Arial'; class Text extends Component{ static displayName = 'Text'; static propTypes = { @@ -21,15 +22,40 @@ class Text extends Component{ }; render() { let {props} = this; - return ; - return ; } }