Simple react implementation of iPhone / iPad photo camera
npm install 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 element for display the camera stream,
- HTML element for taking a screenshot (photo) from the element.
You can install the library using NPM:
```
npm install react-camera-ios
or Yarn:
``
yarn add react-camera-ios
`jsx
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(
`
The library provides some constants, you can use them as values of camera properties:
`javascript
const DEVICE = {
MOBILE: 'mobile',
TAB: 'tab',
};
const FACING_MODE = {
ENVIRONMENT: 'environment',
USER: 'user',
};
const PLACEMENT = {
CONTAIN: 'contain',
COVER: 'cover',
};
`
facingMode| In 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|string|FACING_MODE.ENVIRONMENT
isTurnedOn| Camera power indicator | bool | true
placement|Camera 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|string|PLACEMENT.COVER
quality|The quality of photo (a number between 0 and 1). It will be passed to canvas.toDataURL()|number|0.92`