npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-na-camera

v1.2.0

Published

A NativeScript camera plugin

Downloads

4

Readme

NativeScript NA Camera plugin

NOTE! Android is currently not supported.

A NativeScript camera that utilizes AVFoundation for iOS.

Installation

$ tns plugin add nativescript-na-camera

Usage

XML

<Page navigatingTo="navigatingTo" xmlns:NACamera="nativescript-na-camera">
  <StackLayout>
    <NACamera:Camera id="cameraPreview" />
    <Button text="Capture" id="capturePhoto" tap="capturePhoto" />
    <Button text="New photo" id="newPhoto" tap="newPhoto" />
  </StackLayout>
</Page>

JS

var NACamera = require("nativescript-na-camera");

var page;

exports.navigatingTo = function(args) {
  page = args.object;
  
  NACamera.start();
};

exports.capturePhoto = function(args) {
  NACamera.capturePhoto({
    saveToLibrary: true
  }).then(function(image, savedToLibrary) {
    NACamera.stop();
    if(savedToLibrary) console.log("Photo was saved to library!");
    // Do something more...
  }, function(error) {
    console.error(error);
  });
};

exports.newPhoto = function(args) {
  NACamera.start();
};

Note! NACamera.start() must be fired to initiate the camera preview. It is recommended to stop the camera once the preview is out of view in the UI using NACamera.stop().

Methods

capturePhoto()

To capture a photo.

The resolution of captured photo is the proportion of the camera preview.

capturePhoto(props)

  • props - Set any capture properties (optional).
    • saveToLibrary - Saves the photo to the library upon capture (defaults to false).
    • mirrorCorrection - Correct mirroring when capturing with the front camera (defaults to true).
    • playSound - Plays a capture sound (defaults to true).
    • simulatorDebug - For testing on a simulator where a camera device is not available (defaults to false).
    • simulatorImage - The image source (defaults to empty string).
  • Returns a then promise:
    • resolve
      • image - The captured photo as an image source.
      • savedToLibrary - Reference to props.saveToLibrary which is either true or false.
    • reject
      • error - The error message.
NACamera.capturePhoto({
  saveToLibrary: true
}).then(function(image, savedToLibrary) {
  NACamera.stop();
  if(savedToLibrary) console.log("Photo was saved to library!");
  // Do something more...
}, function(error) {
  console.error(error);
});

saveToLibrary()

Save an image to the library.

saveToLibrary(image)

  • image - The image source that should be saved to the library.
  • Returns true.
NACamera.saveToLibrary(image);

setTorchMode()

Set the torch mode (if available).

setTorchMode(condition)

  • condition - Boolean value.
  • Returns true or false depending on availability.
NACamera.setTorchMode(true); // Torch on
NACamera.setTorchMode(false); // Torch off

setFlashMode()

Set the flash mode (if available).

setFlashMode(condition)

  • condition - Boolean value.
  • Returns true or false depending on availability.
NACamera.setFlashMode(true); // Flash on
NACamera.setFlashMode(false); // Flash off

setDevicePosition()

Set the camera device position (back or front camera, if available).

setDevicePosition(position)

  • position - String value. Must be either "back" or "front".
  • Returns true or false depending on availability.
NACamera.setDevicePosition("back"); // Back camera
NACamera.setDevicePosition("front"); // Front camera

hasDevicePosition()

Check if a camera device position is available.

hasDevicePosition(position)

  • position - String value. Must be either "back" or "front".
  • Returns true or false depending on availability.
var hasBackCamera = NACamera.hasDevicePosition("back");
var hasFrontCamera = NACamera.hasDevicePosition("front");

Other methods

  • start() - Start the camera session.
    • Returns boolean
  • stop() - Stop the camera session.
    • Returns boolean
  • devicesAvailable() - Check if any camera is available.
    • Returns boolean
  • getTorchMode() - Get the current torch mode.
    • Returns boolean
  • hasTorchMode() - Check if the camera's current device position has a torch available.
    • Returns boolean
  • getFlashMode() - Get the current flash mode.
    • Returns boolean
  • hasFlashMode() - Check if the camera's current device position has a flash available.
    • Returns boolean
  • getDevicePosition() - Check if the camera's current device position is either back or front.
    • Returns "back" or "front"

Known issues

  • No Android compatibility, yet.

To-do list

  • Video recording

Please post an issue if you have any other ideas!

History

Version 1.1.0 (November 21, 2016)

  • Pinch-to-zoom feature
  • Tap-to-focus feature
  • Added mirror correction property when capturing with the front camera (See capturePhoto() documentation).

Version 1.0.0 (November 10, 2016)

  • First release!

Credits

License

MIT - for {N} version 2.0.0+