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

react-native-camera-hooks

v0.5.3

Published

React Native Hooks for the react-native-camera module.

Downloads

2,544

Readme

React Native Camera Hooks provides you with functionality to use the React Native Camera API with Functional Components.

npm GitHub CircleCI Deploy

import { View, TouchableOpacity, TouchableWithoutFeedback } from 'react-native';
import { RNCamera } from 'react-native-camera';
import { useCamera } from 'react-native-camera-hooks';

const FunctionalComponentExample = ({ initialProps }) => {
  const [
    { cameraRef, type, ratio, autoFocus, autoFocusPoint, isRecording },
    {
      toggleFacing,
      touchToFocus,
      textRecognized,
      facesDetected,
      recordVideo,
      setIsRecording,
    },
  ] = useCamera(initialProps);

  return (
    <View style={{ flex: 1 }}>
      <RNCamera
        ref={cameraRef}
        autoFocusPointOfInterest={autoFocusPoint.normalized}
        type={type}
        ratio={ratio}
        style={{ flex: 1 }}
        autoFocus={autoFocus}
        onTextRecognized={textRecognized}
        onFacesDetected={facesDetected}
      />

      <TouchableWithoutFeedback
        style={{
          flex: 1,
        }}
        onPress={touchToFocus}
      />

      <TouchableOpacity
        testID="button"
        onPress={toggleFacing}
        style={{ width: '100%', height: 45 }}>
        {type}
      </TouchableOpacity>

      {!isRecording && (
        <TouchableOpacity
          onPress={async () => {
            try {
              setIsRecording(true);
              const data = await recordVideo();
              console.warn(data);
            } catch (error) {
              console.warn(error);
            } finally {
              setIsRecording(false);
            }
          }}
          style={{ width: '100%', height: 45 }}
        />
      )}
    </View>
  );
};

Features

  • React Hooks Support: Use React Native Camera with Functional Components
  • Wrapper around the Camera API, that makes the usage easier
  • TypeScript support

Constants are defined in constants and initalState.

|Function|Description| |---|---| |useCamera(initialState)|Includes all camera hooks described below. See also the example above| |useZoom(state)|Zoom feature. Includes zoom, setZoom, zoomIn (increment by 0.01) and zoomOut (decrement by 0.1) | |useToggleFacing(state, modes)|Toggles between two values (front and back side of the camera). Includes type, toggleFacing.| |useAutoFocus(state, modes)|Toggles between two values (focus on or off). Includes autoFocus and toggleAutoFocus.| |useWhiteBalance(state)|Toggles between white balance values. Includes whiteBalance, toggleWB and setWhiteBalance.| |useFlash(state)|Toggles between flash modes. Includes flash, toggleFlash and setFlash.| |useAutoFocusTouch(state)|Touch to focus feature. Includes autoFocusPoint, touchToFocus (callback to be used in onPress for example) and setAutoFocusPoint.| |useTextRecognition(state)|Text recognition feature. Includes textBlocks, setTextblocks and textRecognized (callback).| |useFaceDetection(state)|Face detection feature. Includes faces, setFaces and facesDetected (callback).| |useBarcodeDetection(state)|Barcode detection feature. Includes barcodes, setBarcodes and barcodeRecognized (callback).| |takePicture({ cameraRef }, options)|Function to take a picture. Returns a Promise with the result. defaultPictureTakeOptions can also be imported from the same file.| |recordVideo({ cameraRef }, options)|Function to record a video. Returns a Promise with the result. defaultVideoRecordOptions can also be imported from the same file.| |stopRecording({ cameraRef })|Function to stop recording. Returns a Promise.| |pausePreview({ cameraRef })|Function to pause the camera preview. Returns a Promise with the result as a boolean.| |resumePreview({ cameraRef })|Function to resume the camera preview. Returns a Promise with the result as a boolean.|


Installation

To install react-native-camera-hooks, do either

npm install --save react-native-camera-hooks

or

yarn add react-native-camera-hooks

Note that this requires a react-native version > 0.59 which supports React Hooks. Also, react-native-camera has to be installed.


TODO

  • Improve TypeScript support