-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AndrewC
committed
Sep 18, 2023
1 parent
ea9f5fb
commit dc57daf
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useState, useEffect, forwardRef, useImperativeHandle, } from "react"; | ||
import { View, Text, StyleSheet, TouchableOpacity } from "react-native"; | ||
import {launchImageLibrary} from 'react-native-image-picker'; | ||
|
||
const openImagePicker = () => { | ||
const [selectedImage, setSelectedImage] = useState(null); | ||
|
||
const handleNewMedia = async () => { | ||
const { status } = await requestCameraPermissionsAsync(); | ||
if (status !== "granted") { | ||
alert("Sorry, we need camera permissions to make this work!"); | ||
return; | ||
} | ||
const cameraResult = await launchCameraAsync({ | ||
mediaTypes: MediaTypeOptions.All, | ||
allowsEditing: false, | ||
aspect: [3, 4], | ||
quality: 0.75, | ||
videoMaxDuration: 300, | ||
}); | ||
|
||
if (!cameraResult.canceled) { | ||
handleImageSelection(cameraResult); | ||
} | ||
}; | ||
|
||
const options = { | ||
mediaType: 'photo', | ||
includeBase64: false, | ||
maxHeight: 2000, | ||
maxWidth: 2000, | ||
}; | ||
|
||
launchImageLibrary(options, (response) => { | ||
if (response.didCancel) { | ||
console.log('User cancelled image picker'); | ||
} else if (response.error) { | ||
console.log('Image picker error: ', response.error); | ||
} else { | ||
let imageUri = response.uri || response.assets?.[0]?.uri; | ||
setSelectedImage(imageUri); | ||
} | ||
}); | ||
}; |