From cf43dd1412af035c0eacbbe54a993b307cdec141 Mon Sep 17 00:00:00 2001 From: analuizaff Date: Wed, 30 Dec 2020 11:20:31 -0300 Subject: [PATCH] image picker - modal --- src/App.js | 2 - src/app/components/ImageInput.js | 62 +++++++++++++++++++++--------- src/app/components/LaunchCamera.js | 57 --------------------------- 3 files changed, 43 insertions(+), 78 deletions(-) delete mode 100644 src/app/components/LaunchCamera.js diff --git a/src/App.js b/src/App.js index 9216542..15d6d2b 100644 --- a/src/App.js +++ b/src/App.js @@ -8,7 +8,6 @@ import openDatabase from "./app/database/database-connection"; import initDatabase from "./app/database/database-init"; import FlashMessage from "react-native-flash-message"; -import LaunchCamera from "./app/components/LaunchCamera"; export default function App() { global.userDataBase = openDatabase(); @@ -19,6 +18,5 @@ export default function App() { - /**/ ); } diff --git a/src/app/components/ImageInput.js b/src/app/components/ImageInput.js index 689135c..e49595d 100644 --- a/src/app/components/ImageInput.js +++ b/src/app/components/ImageInput.js @@ -7,12 +7,10 @@ import { Alert, Text, Modal, - TouchableHighlight, + TouchableOpacity, } from "react-native"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import * as ImagePicker from "expo-image-picker"; -import { Dialog } from 'react-native-simple-dialogs'; - import colors from "../config/colors"; import { useState } from "react/cjs/react.development"; @@ -41,7 +39,7 @@ function ImageInput({ imageUri, onChangeImage }) { ]); }; - const selectImage = async () => { + const launchImageLibrary = async () => { setModalVisible(false); try { const result = await ImagePicker.launchImageLibraryAsync({ @@ -54,7 +52,7 @@ function ImageInput({ imageUri, onChangeImage }) { } }; - const takePicture = async () => { + const launchCamera = async () => { setModalVisible(false); try { const result = await ImagePicker.launchCameraAsync({ @@ -86,16 +84,29 @@ function ImageInput({ imageUri, onChangeImage }) { { - Alert.alert('Modal has been closed.'); + visible={modalVisible}> + { + setModalVisible(!setModalVisible); }}> - - - Câmera - Galeria + + + + Selecione uma imagem + + Câmera + + + Galeria + + + { setModalVisible(false) }}> + + Cancelar + + + - + @@ -125,22 +136,35 @@ const styles = StyleSheet.create({ }, modalView: { margin: 20, - backgroundColor: 'white', + backgroundColor: '#d3d3d3', borderRadius: 20, - padding: 35, + padding: 30, alignItems: 'center', - shadowColor: '#000', + shadowColor: 'grey', shadowOffset: { - width: 0, + width: 10, height: 2, }, shadowOpacity: 0.25, shadowRadius: 3.84, - elevation: 5, + elevation: 25, + width: 300, }, modalText: { - marginBottom: 15, + marginTop: 15, textAlign: 'center', + fontSize: 16, + color: colors.primary, + }, + modalLabel: { + borderBottomWidth: 2, + borderBottomColor: colors.primary, + width: 300, + color: colors.primary, + fontSize: 18, + textAlign: "center", + fontWeight: "bold", + height: 35 }, }); diff --git a/src/app/components/LaunchCamera.js b/src/app/components/LaunchCamera.js deleted file mode 100644 index c9b8072..0000000 --- a/src/app/components/LaunchCamera.js +++ /dev/null @@ -1,57 +0,0 @@ -import React from "react"; -import { StyleSheet, Text, View, SafeAreaView, Image, Button, TouchableWithoutFeedback } from "react-native"; -import * as ImagePicker from "expo-image-picker"; -import { useState, useEffect } from "react"; -import * as Permissions from 'expo-permissions'; -import colors from "../config/colors"; -import { MaterialCommunityIcons } from "@expo/vector-icons"; - -function LaunchCamera() { - const [imageUri, setImageUri] = useState(null); - - const takePicture = async () => { - await Permissions.askAsync(Permissions.CAMERA); - const { cancelled, uri } = await ImagePicker.launchCameraAsync({ - allowsEditing: false, - }); - setImageUri(uri); - }; - - const handlePress = () => { - takePicture(); - }; - - return ( - - - {!imageUri && ( - - )} - {imageUri && } - - - ); -} - -const styles = StyleSheet.create({ - container: { - alignItems: "center", - backgroundColor: colors.light, - borderRadius: 15, - height: 100, - justifyContent: "center", - marginVertical: 10, - overflow: "hidden", - width: 100, - }, - image: { - height: "100%", - width: "100%", - }, -}); - -export default LaunchCamera; \ No newline at end of file