Giter Site home page Giter Site logo

bradmartin / nativescript-svg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from peoplewaredo/nativescript-svg

12.0 12.0 13.0 5.68 MB

Nativescript plugin - support for .SVG file format

License: Other

HTML 1.80% TypeScript 63.21% CSS 1.36% JavaScript 33.43% Ruby 0.21%

nativescript-svg's Introduction

npm npm MIT license

NativeScript SVG

Install

tns plugin add @teammaestro/nativescript-svg

Usage

You use it in the same way you use Image source.

Android Library iOS CocoaPod
pents90 svg-android SVGKit by SVGKit

** there are limitations: ** - saveToFile ins't working

Quick start

var ImageSourceSVGModule = require('@teammaestro/nativescript-svg');
var svgFile = new ImageSourceSVGModule.ImageSourceSVG();

var loaded = svgFile.fromResource('foxie');

var path = '//somepath/file.svg';
loaded = svgFile.loadFromFile(path);

var url = 'http://somepath/file.svg';
svgFile
  .fromUrl(url)
  .then(loaded => {
    console.log('object loaded');
  })
  .catch(e => {
    console.log('error');
  });

API

ImageSourceSVGModule.fromResource(name: string): ImageSourceSVG
  • Loads this instance from the specified resource name.
ImageSourceSVGModule.fromFile(path: string): ImageSourceSVG
  • Creates a new ImageSourceSVG instance and loads it from the specified file.
ImageSourceSVGModule.fromData(data: any): ImageSourceSVG
  • Creates a new ImageSourceSVG instance and loads it from the specified resource name.
ImageSourceSVGModule.fromBase64(source: string): ImageSourceSVG
  • Creates a new ImageSourceSVG instance and loads it from the specified resource name.
ImageSourceSVGModule.fromBase64(source: string): ImageSourceSVG
  • Creates a new ImageSourceSVG instance and loads it from the specified resource name.
ImageSourceSVGModule.fromUrl(url: string): Promise:ImageSourceSVG
  • Downloads the image from the provided Url and creates a new ImageSourceSVG instance from it.

You can call every method in two ways, for example:

//from the svg file object
svgFile.loadFromResource(name: string): boolean  // synchronously
svgFile.fromResource(name: string): ImageSourceSVG //asynchronously

or

//from the svg module api
ImageSourceSVGModule.fromResource(name: string): ImageSourceSVG

Since ver 1.1 Implement a similar image tag to be used as for example:

<Page xmlns="http://schemas.nativescript.org/tns.xsd"
      xmlns:svg="@teammaestro/nativescript-svg" loaded="pageLoaded">
  <StackLayout>
    <!--svg image tag-->
    <svg:SVGImage src="~/image/nativescript.svg" height="100" />
    <svg:SVGImage src="https://media4.giphy.com/media/3uyIgVxP1qAjS/200.svg" height="200" />

    <!--normal image tag-->
    <Image src="~/images/logo.svg" stretch ="none" />
  </StackLayout>
</Page>

Roadmap

ver 1.6 implement an SVGImage tag that can support svg tags.

<!-- this is more complicated to implement, pending to be implemented -->
    <svg:SVGImage width="100" height="100">
        <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
    </svg:SVGImage>

ver 1.5 Change api dependency from pents90/svg-android to Pixplicity/sharp

Release note

v1.3.4 -- Angular 4 support, please check example code

v1.3.0 -- NS 3+ implementation and it will work with angular if you call registerElement before using it. Thanks to @tbozhikov

v1.1.4 -- Fix svg & demo

v1.1.3 -- Fix SVGImage for iOS - SVGKFastImageView issue#3

v1.1.0 -- Implemented a similar image tag to render svg images.

v1.0.11 -- Major fix for load library issue and demo include.

v1.0.9 -- load from URL on Android and IOS included.

v1.0.7 -- Fix svg.common override issue.

v1.0.5 -- fix for npm package lib not including the .js files.

v1.0.2 -- the base64 encondig on Android included - IOS pending.

nativescript-svg's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.