diff --git a/package.json b/package.json index 7d6e7467..c2d25679 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,8 @@ "expo-camera": "~8.0.0", "expo-constants": "~8.0.0", "expo-font": "~8.0.0", + "expo-media-library": "~8.0.0", + "expo-permissions": "~8.0.0", "expo-web-browser": "~8.0.0", "express-session": "^1.17.0", "mem": "^6.0.1", diff --git a/src/screens/Main/RecordStack/RecordScreen/RecordScreen.tsx b/src/screens/Main/RecordStack/RecordScreen/RecordScreen.tsx index 5da1a5ca..85351db5 100644 --- a/src/screens/Main/RecordStack/RecordScreen/RecordScreen.tsx +++ b/src/screens/Main/RecordStack/RecordScreen/RecordScreen.tsx @@ -1,7 +1,9 @@ import React, { useState, useEffect } from 'react' -import { Text, View, TouchableOpacity, Image, StatusBar, Alert } from 'react-native' +import { Text, View, TouchableOpacity, Image, StatusBar} from 'react-native' import { Camera } from 'expo-camera' import styles from './styles' +import * as Permissions from 'expo-permissions' +import * as MediaLibrary from 'expo-media-library' import { NavigationScreenProp, NavigationState, NavigationParams } from 'react-navigation' interface Props { @@ -16,12 +18,41 @@ export default function RecordScreen(props: Props) { const [camera, setCamera] = useState() const [isRecording, setIsRecording] = useState(false) const [cameraDirection, setCameraDirection] = useState(Camera.Constants.Type.front) + const [video, setVideo] = useState(null) + + async function saveVideo(){ + const asset = await MediaLibrary.createAssetAsync(video.uri) + if (asset) { + setVideo(null) + } + } + + async function stopRecord(){ + setIsRecording(false) + camera.stopRecording() + } + + async function startRecord(){ + if (camera) { + setIsRecording(true) + const data = await camera.recordAsync() + setVideo(data) + } + } + + async function toogleRecord(){ + if (isRecording) { + stopRecord() + } else { + startRecord() + } + } useEffect(() => { (async () => { - const { status } = await Camera.requestPermissionsAsync() - setHasPermission(status === 'granted') - + const { status: cameraPermission } = await Camera.requestPermissionsAsync() + const { status: cameraRollPermission } = await Permissions.askAsync(Permissions.CAMERA_ROLL) + setHasPermission(cameraPermission === 'granted' && cameraRollPermission === 'granted') })() }, []) @@ -41,10 +72,18 @@ export default function RecordScreen(props: Props) { >