Code Monkey home page Code Monkey logo

react-native-svgkit's Introduction

@alloc/react-native-svgkit

SVG support for react-native-macos

TypeScript definitions included!

 

Install

npm install @alloc/react-native-svgkit
  1. Add macos/RNSVGKit.xcodeproj to your project

  2. Add these frameworks to your project:

  • libxml2.tbd
  • AppKit.framework
  • QuartzCore.framework
  • CoreGraphics.framework

 

Usage

import {SVGKView} from '@alloc/react-native-svgkit'

// Control the width without needing to know the aspect ratio.
<SVGKView style={{width: 50}} data="..." />

// Explicit size is optional.
<SVGKView source={require('./foo.svg')} />

Any <View> prop can be passed to <SVGKView>.

When neither props.style.width nor props.style.height is defined, the <SVGKView> fills its parent (while preserving its aspect ratio).

props.data

The string of SVG markup. This always overrides the source prop.

Loading of the source prop is cancelled when the data prop is set.

props.source

The reference to an SVG, either local or remote.

For local SVGs: require('./foo.svg')

For remote SVGs: { uri: 'https://foo.com/bar.svg' }

Loading is cancelled whenever the source prop changes.

The previous image is cleared immediately whenever the data or source props change.

props.tintColor

Override the fillColor and/or strokeColor of every shape in the SVG.

props.anchorPoint

After the SVG is resized to fit its view, it gets aligned based on the difference between its view size and image size.

Defaults to {x: 0.5, y: 0.5} (center alignment)

props.onLoadStart

Called when the source prop begins loading.

props.onError

Called when either (1) the source prop failed to load, or (2) the SVG markup has a syntax error.

Syntax errors in the data prop are included.

Passed an object like { nativeEvent: { error: string } }

props.onLoad

Called once the source prop has been loaded and rendered without error.

props.onLoadEnd

Called when the source prop either (1) fails to load or (2) is rendered.

react-native-svgkit's People

Contributors

aleclarson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-svgkit's Issues

"Touch" support

Allow for <Touchable> components to wrap SVGKView elements.

Currently, you need to wrap the SVGKView element with a component that supports touch events (eg: <View>).

The default behavior would be identical to wrapping with a <View> component.

If it's not too hard, we could consider adding hit detection on the SVG paths.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.