Git Product home page Git Product logo

camera-kit-react-native's Introduction

Camera Kit wrapper for React Native

This project provides a wrapper to Snap's Camera Kit solution that simplifies and speeds up the integration process for developers building React Native apps. While development on native platforms is still a recommended way, this wrapper provides a convenient way to implement basic functionalities of Camera Kit in React Native application.

Note: Advanced functionalities like Remote API support, Inclusive Camera features, etc. are not supported in this wrapper implementation yet. If your project needs the missing features then feel free to implement it yourself and submit a PR to this repo or use native development environment.

Installation

You can install the Camera Kit React Native package using npm:

npm install @snap/camera-kit-react-native

Usage

Start with importing the following modules:

import { CameraKitContext } from '@snap/camera-kit-react-native';
import { useCameraKit } from '@snap/camera-kit-react-native';

CameraKitContext component will contain global configuration for CameraKit session whereas useCameraKit hook will provide API for managing native CameraKit session, load lenses, apply lens, etc.

For Android, make sure you have following permissions defined in AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />

<!-- optionally, if you want to record audio: -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

Please refer to the example directory for detailed usage examples on how to integrate and use this wrapper in your React Native project.

Usage example:

import { PreviewView, useCamera } from "@snap/camera-kit-react-native"
import { useEffect } from "react"
import { View, FlatList, Pressable, Image } from "react-native"
import { Lenses } from "./lenses"

export function App() {
    const { setPosition } = useCamera();

    useEffect(async () => {
        setPosition("front");
    })

    return (
        <CameraKitContext apiToken="<API Token from Camera Kit Portal>" safeArea={{top: 100, bottom: 200}}>
            <PreviewView />
            <Lenses />
        </CameraKitContext>
    )
}

Lens carousel example:

import { PreviewView, useCameraKitManager } from "@snap/camera-kit-react-native"
import { useEffect } from "react"
import { View, FlatList, Pressable, Image } from "react-native"
import { useCameraManager } from "./partner-camera"

function Lenses({ groupId }: { groupId: string }) {
    const { loadLenses, applyLens } = useCameraKitManager();
    const [lenses, setLenses] = useState([]);

    useEffect(async () => {
        const getLenses = async () => {
            const lenses = await loadLenses(groupId);
            setLenses(lenses);
        }

        getLenses().catch(console.error)

        return undefined;
    }, [loadLenses])

    return (
        <View style={{position: 'absolute'}}>
            <FlatList
                horizontal={true}
                data={lenses}
                renderItem={item => (
                    <Pressable
                        onPress={() => {
                            applyLens(item.item.id);
                        }}>
                        <Image
                            source={{uri: item.item.icon}}
                        />
                    </Pressable>
                )}
                keyExtractor={item => item.id}
            />
        </View>
    )
}

Contributing

Thank you for your interest in improving our project! ๐Ÿ™

Here's how you can contribute:

  1. Fork and clone this repository.
  2. Install dependencies by running yarn install --immutable && yarn prepare.
  3. Make your changes.
  4. Test your changes with the example app using yarn example start. Ensure everything works as expected.
  5. Update the documentation if necessary by running yarn docs.
  6. Submit a pull request with a clear description of your changes.

License

Please refer to the LICENSE file for license information.

camera-kit-react-native's People

Contributors

mikalai-snap avatar jonra1993 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.