From e57e16ded8b46bade31922eb298393142b322270 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sat, 15 Sep 2018 21:21:28 +0300 Subject: [PATCH] Update readme --- README.md | 203 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 164 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 3e1a6307..4be4e172 100644 --- a/README.md +++ b/README.md @@ -116,56 +116,75 @@ Here's a simple example. To render output like this: Use the following code: ```javascript -import 'react'; import Svg,{ Circle, Ellipse, G, - LinearGradient, - RadialGradient, - Line, + Text, + TSpan, + TextPath, Path, Polygon, Polyline, + Line, Rect, - Symbol, - Text, Use, + Image, + Symbol, Defs, - Stop + LinearGradient, + RadialGradient, + Stop, + ClipPath, + Pattern, + Mask, } from 'react-native-svg'; -class SvgExample extends Component { - render() { - return ( - - - - - ); - } +/* Use this if you are using Expo +import { Svg } from 'expo'; +const { Circle, Rect } = Svg; +*/ + +import React from 'react'; +import { View, StyleSheet, Dimensions } from 'react-native'; + +// Percentages work in plain react-native but aren't supported in Expo yet, workaround with this or onLayout +const { width, height } = Dimensions.get('window'); + +export default class SvgExample extends React.Component { + render() { + return ( + + + + + + + ); + } } ``` -[Try this on Snack](https://snack.expo.io/r1hCVAaEZ) +[Try this on Snack](https://snack.expo.io/@msand/react-native-svg-example) ### Common props: @@ -794,6 +813,114 @@ Code explanation: ![RadialGradient](https://raw.githubusercontent.com/react-native-community/react-native-svg/master/screenShoots/radialgradient.png) +#### Mask + + +In SVG, you can specify that any other graphics object or ‘G’ element can be used as an alpha mask for compositing the current object into the background. + +A mask is defined with a ‘Mask’ element. A mask is used/referenced using the ‘mask’ property. + +A ‘Mask’ can contain any graphical elements or container elements such as a ‘G’. + +The element must be nested within a [<Defs>](#defs) tag. The [<Defs>](#defs) tag is short for definitions and contains definition of special elements (such as gradients). + +https://www.w3.org/TR/SVG11/images/masking/mask01.svg +```html + + + + + + + + + + + Masked text + + + + + + +``` + +Code explanation: https://www.w3.org/TR/SVG11/masking.html#MaskElement + +![Mask](https://www.w3.org/TR/SVG11/images/masking/mask01.svg) + +#### Pattern + +A pattern is used to fill or stroke an object using a pre-defined graphic object which can be replicated ("tiled") at fixed intervals in x and y to cover the areas to be painted. Patterns are defined using a ‘pattern’ element and then referenced by properties ‘fill’ and ‘stroke’ on a given graphics element to indicate that the given element shall be filled or stroked with the referenced pattern. +The element must be nested within a [<Defs>](#defs) tag. The [<Defs>](#defs) tag is short for definitions and contains definition of special elements (such as gradients). + +https://www.w3.org/TR/SVG11/images/pservers/pattern01.svg +```html + + + + + + + + + +``` + +Code explanation: https://www.w3.org/TR/SVG11/pservers.html#PatternElement + +![Pattern](https://www.w3.org/TR/SVG11/images/pservers/pattern01.svg) + #### Touch Events Touch events are supported in react-native-svg. These include: @@ -839,10 +966,8 @@ npm i ### TODO: 1. Add Native methods for elements. -2. Pattern element. -3. Mask element. -4. Marker element. -5. Load Image from URL. +2. Marker element. +3. Load Image from URL. ### Known issues: 1. Unable to apply focus point of RadialGradient on Android.