Skip to content

Camera Plus

A NativeScript camera with all the bells and whistles which can be embedded inside a view.

Installation

bash
npm install @nstudio/nativescript-camera-plus

Note for Android: Add the following to your app.gradle:

gradle
android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Usage

Angular

typescript
import { Component, NgZone } from '@angular/core';
import { CameraPlus, CameraLoadedEvent, PhotoCapturedEvent } from '@nstudio/nativescript-camera-plus';
import { registerElement } from '@nativescript/angular';

registerElement('CameraPlus', () => CameraPlus);

@Component({
  selector: 'app-camera',
  template: `
    <CameraPlus
      debug="true"
      confirmRetakeText="RETAKE!"
      confirmSaveText="CONFIRM!"
      enableVideo="true"
      showCaptureIcon="true"
      showFlashIcon="true"
      showGalleryIcon="true"
      showToggleIcon="true"
      (loaded)="cameraLoadedEvent($event)"
    ></CameraPlus>
  `
})
export class CameraComponent {
  public cam: CameraPlus;

  cameraLoadedEvent(event: CameraLoadedEvent): void {
    this.cam = event.object;
    this.cam.autoFocus = true;
  }
}

Properties

NameTypeDefaultDescription
debugbooleanfalseIf true, logs will be output in the console
confirmPhotosbooleantruePresent a confirmation dialog before saving
confirmRetakeTextstring'Retake'Text for retake button
confirmSaveTextstring'Save'Text for save button
saveToGallerybooleantrueSave captured photos to device gallery
galleryPickerModestring'multiple''single' or 'multiple' image selection
showFlashIconbooleantrueShow flash toggle button
showToggleIconbooleantrueShow camera toggle button
showCaptureIconbooleantrueShow capture button
showGalleryIconbooleantrueShow gallery button
enableVideobooleanfalseEnable video recording

Methods

MethodDescription
isCameraAvailable()Returns true if the device has a camera
toggleFlash()Toggles the flash mode
toggleCamera()Toggles between front/back camera
chooseFromLibrary(opts?)Opens the device gallery
takePicture(opts?)Takes a picture
getFlashMode()Returns the current flash mode
record(opts?)Starts recording video
stop()Stops video recording

Events

NameDescription
errorEventEmitted when an error occurs
photoCapturedEventEmitted when a photo is taken
toggleCameraEventEmitted when camera is toggled
imagesSelectedEventEmitted when images are selected from gallery
videoRecordingStartedEventEmitted when video starts recording
videoRecordingFinishedEventEmitted when video stops recording
videoRecordingReadyEventEmitted when video is ready to use

License

Apache License Version 2.0