Socket
Socket
Sign inDemoInstall

react-camera-ios

Package Overview
Dependencies
5
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-camera-ios

Simple react implementation of iPhone / iPad photo camera


Version published
Weekly downloads
30
decreased by-42.31%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

GitHub Actions

React Camera iOS

A simple react implementation of iPhone / iPad photo camera with all native styles and ability to change camera (user / environment).

The following technologies were used to create the library:

  • WebRTC for getting the access to camera media stream,
  • HTML <video> element for display the camera stream,
  • HTML <canvas> element for taking a screenshot (photo) from the <video> element.

Installation

You can install the library using NPM:

npm install react-camera-ios

or Yarn:

yarn add react-camera-ios

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import Camera, { DEVICE, FACING_MODE, PLACEMENT } from 'react-camera-ios';

// Styles
import 'react-camera-ios/build/styles.css';

const containerStyle = { display: 'flex', height: '300px', width: '300px' };

ReactDOM.render(
  <div style={containerStyle}>
    <Camera
      device={DEVICE.MOBILE}
      facingMode={FACING_MODE.ENVIRONMENT}
      placement={PLACEMENT.COVER}
      quality="1"
      onError={error => console.log(error)}
      onTakePhoto={dataUrl => console.log(dataUrl)}
    />
  </div>,
  document.getElementById('root'),
);


Constants

The library provides some constants, you can use them as values of camera properties:

const DEVICE = {
  MOBILE: 'mobile',
  TAB: 'tab',
};

const FACING_MODE = {
  ENVIRONMENT: 'environment',
  USER: 'user',
};

const PLACEMENT = {
  CONTAIN: 'contain',
  COVER: 'cover',
};

PropTypes

NameDescriptionTypeDefault value
deviceWhich style of camera do you want to see:
DEVICE.MOBILE - iPhone camera style,
DEVICE.TAB - iPad camera style.
stringDEVICE.MOBILE
facingModeIn which side of device do you want to open camera:
FACING_MODE.ENVIRONMENT - back (main) camera,
FACING_MODE.USER - front camera.
It works like MediaTrackConstraints.facingMode
stringFACING_MODE.ENVIRONMENT
isTurnedOnCamera power indicatorbooltrue
placementCamera placement relative to the container:
PLACEMENT.CONTAIN - scales the camera as large as possible without cropping,
PLACEMENT.COVER - scales the camera as large as possible (but if the proportions of the camera differ from the container, it is cropped either vertically or horizontally so that no empty space remains).
It works like CSS background-size property
stringPLACEMENT.COVER
qualityThe quality of photo (a number between 0 and 1). It will be passed to canvas.toDataURL()number0.92
onError(error)Called when an error is occured (error object will be passed as an agrument)func
onTakePhoto(dataUrl)Called when a photo is taken (dataUrl will be passed as an argument)func

Demo

React Camera iOS

Keywords

FAQs

Last updated on 07 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc