Socket
Socket
Sign inDemoInstall

react-native-awesome-camera

Package Overview
Dependencies
531
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-awesome-camera

A React Native package that allows you to select a photo/video from the device library or camera.


Version published
Weekly downloads
23
increased by43.75%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

📷 React Native Awesome Camera

npm version npm downloads

Features List


  • High-quality camera support in Android and iOS
  • Select images and videos from phone storage with an option of multiple selection
  • Capture images and videos using the awesome camera
  • Flash, manual focus, and camera zoom features available
  • Customize theme color

Image Capture         Video Capture


Installation and Setup steps


yarn add react-native-awesome-camera

or

npm i react-native-awesome-camera

install dependencies

yarn add react-native-permissions react-native-vision-camera @react-native-camera-roll/camera-roll react-native-gesture-handler

we are using react-native-vision-camera

Android Changes


Add below permission in your AndroidManifest.xml

<manifest>
  ....
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  ....
</manifest>

iOS Changes


Add below lines in your Podfile

# with react-native >= 0.72
- # Resolve react_native_pods.rb with node to allow for hoisting
- require Pod::Executable.execute_command('node', ['-p',
-   'require.resolve(
-     "react-native/scripts/react_native_pods.rb",
-     {paths: [process.argv[1]]},
-   )', __dir__]).strip

+ def node_require(script)
+   # Resolve script with node to allow for hoisting
+   require Pod::Executable.execute_command('node', ['-p',
+     "require.resolve(
+       '#{script}',
+       {paths: [process.argv[1]]},
+     )", __dir__]).strip
+ end

+ node_require('react-native/scripts/react_native_pods.rb')
+ node_require('react-native-permissions/scripts/setup.rb')
# with react-native < 0.72
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
+ require_relative '../node_modules/react-native-permissions/scripts/setup'
# …

platform :ios, min_ios_version_supported
prepare_react_native_project!

# ⬇️ uncomment wanted permissions
setup_permissions([
  # 'AppTrackingTransparency',
  # 'BluetoothPeripheral',
  # 'Calendars',
  'Camera',
  # 'Contacts',
  # 'FaceID',
  # 'LocationAccuracy',
  # 'LocationAlways',
  # 'LocationWhenInUse',
  # 'MediaLibrary',
  'Microphone',
  # 'Motion',
  # 'Notifications',
  'PhotoLibrary',
  # 'PhotoLibraryAddOnly',
  # 'Reminders',
  # 'Siri',
  # 'SpeechRecognition',
  # 'StoreKit',
])

# …

Also change your Info.plist

<dict>
....
  <key>NSCameraUsageDescription</key>
  <string>${APP_NAME} Need camera access to take pictures or video.</string>
  <key>NSMicrophoneUsageDescription</key>
  <string>${APP_NAME} Need microphone access to record audio.</string>
  <key>NSPhotoLibraryUsageDescription</key>
  <string>${APP_NAME} Need photo library access to access photo gallery.</string>
....
</dict>

if you are facing any permission-related issues, you can refer to react-native-permissions/issues

you can refer these links for fixing React-bridging wrong paths, Added correct namespace qualifier to .mm file

Props:

NameTypeRequiredDescriptionDefault
setIsOpenFunctionYesClose awesome camera screen-
getDataFunctionYesReturn selected or captured media-
multiSelectbooleanNoOption to select multiple files (image or video)true
themeColorstringNoCustom theme color'yellow'
secondaryColorstringNoCustom secondary color'black'
takePhotoOptionsTakePhotoOptionsNoExtends react-native-vision-camera's TakePhotoOptions interface while capturing a photo-
recordVideoOptionsRecordVideoOptionsNoExtends react-native-vision-camera's RecordVideoOptions interface when recording starts-
cameraPropsCameraPropsNoExtends react-native-vision-camera's CameraProps interface-
showGallerybooleanNoFor showing images available on devicetrue
photobooleanNoFor allowing photo capturetrue
videobooleanNoFor allowing video capturetrue
closeContainerStyleViewStyleNoFor styling close icon container-
closeIconStyleImageStyleNoFor styling close icon-
closeIconImageSourcePropTypeNoFor providing custom close image resource-
renderCloseComponentReactComponentElementNoFor rendering custom close component-
videoContainerStyleViewStyleNoFor styling video icon container-
videoIconStyleImageStyleNoFor styling video icon-
videoIconImageSourcePropTypeNoFor providing custom video image resource-
renderVideoComponentReactComponentElementNoFor rendering custom video component-
flashContainerStyleViewStyleNoFor styling flash icon container-
flashIconStyleImageStyleNoFor styling flash icon-
flashIconImageSourcePropTypeNoFor providing custom flash image resource-
renderFlashComponentReactComponentElementNoFor rendering custom flash component-
changeCameraContainerStyleViewStyleNoFor styling change camera icon container-
changeCameraIconStyleImageStyleNoFor styling change camera icon-
changeCameraIconImageSourcePropTypeNoFor providing custom change camera image resource-
renderChangeCameraComponentReactComponentElementNoFor rendering custom change camera component-

Example

import React, { useState } from "react";
import { Button, SafeAreaView, StyleSheet } from "react-native";
import AwesomeCamera from "react-native-awesome-camera";

const App = () => {
  const { container } = styles;
  const [isOpen, setIsOpen] = useState(false);

  const getData = (data: any) => {
    console.log({ data });
  };

  return (
    <SafeAreaView style={container}>
      {(!isOpen && (
        <Button
          title="button"
          onPress={() => {
            setIsOpen(true);
          }}
        />
      )) || <AwesomeCamera setIsOpen={setIsOpen} getData={getData} />}
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
});

export default App;

Run Command Android

yarn install && npm run android

Run Command iOS

yarn install && cd ios && pod install && cd ..  && npm run ios

Welcome to issues!

  • request for more features 🚀
  • fork and fix open issues 🛠
  • raise issue 📣

open issues

Keywords

FAQs

Last updated on 04 Dec 2023

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