Skip to content

Instantly share code, notes, and snippets.

@manuelbieh
Created October 9, 2021 22:31
Show Gist options
  • Select an option

  • Save manuelbieh/8ad686a24d64973a3c0bf6e5cada70a7 to your computer and use it in GitHub Desktop.

Select an option

Save manuelbieh/8ad686a24d64973a3c0bf6e5cada70a7 to your computer and use it in GitHub Desktop.

Revisions

  1. manuelbieh created this gist Oct 9, 2021.
    62 changes: 62 additions & 0 deletions App.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    import React, { useCallback, useRef } from 'react';
    import {
    Button,
    SafeAreaView,
    ScrollView,
    StatusBar,
    View,
    } from 'react-native';
    import CameraRoll from '@react-native-community/cameraroll';

    import { Camera, useCameraDevices } from 'react-native-vision-camera';

    const App = () => {
    const cameraRef = useRef<Camera>(null);

    const devices = useCameraDevices();
    const device = devices.back;

    console.log(JSON.stringify(devices));

    const startRecording = useCallback(() => {
    cameraRef?.current?.startRecording({
    onRecordingFinished: async (video) => {
    console.log(video.path);
    try {
    await CameraRoll.save(video.path);
    } catch (e) {
    console.log(e);
    }
    },
    onRecordingError: (error) => console.error(error),
    });
    }, []);

    const stopRecording = useCallback(async () => {
    await cameraRef?.current?.stopRecording();
    }, []);

    return (
    <SafeAreaView>
    <StatusBar />
    <ScrollView contentInsetAdjustmentBehavior="automatic">
    <View>
    {device !== null && device !== undefined && (
    <Camera
    ref={cameraRef}
    style={{ width: '100%', height: 400 }}
    device={device}
    fps={240}
    isActive={true}
    video
    />
    )}
    <Button title="Start" onPress={startRecording} />
    <Button title="Stop" onPress={stopRecording} />
    </View>
    </ScrollView>
    </SafeAreaView>
    );
    };

    export default App;
    3,208 changes: 3,208 additions & 0 deletions devices.json
    3,208 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.