From ef32644bd53a4bc5c9c4f665f3ba39a418328fc5 Mon Sep 17 00:00:00 2001 From: GabrielTrettel Date: Tue, 9 Mar 2021 15:54:31 -0300 Subject: [PATCH] Fixing frozen map in MapForm that occours in IOS. --- src/app/screens/MapFormScreen.js | 223 +++++++++++++++---------------- 1 file changed, 111 insertions(+), 112 deletions(-) diff --git a/src/app/screens/MapFormScreen.js b/src/app/screens/MapFormScreen.js index 3a37dbf..48b4c33 100644 --- a/src/app/screens/MapFormScreen.js +++ b/src/app/screens/MapFormScreen.js @@ -13,127 +13,126 @@ import { CurrentLocationContext } from "../context/CurrentLocationContext"; // NOTE: Implementação posterior: É interessante adcionar um searchBox para que o usuário busque um endereço (google places autocomplete é uma api paga) const MapFormScreen = (props) => { - const context = useContext(EventLocationContext); //local do evento - const contextLocation = useContext(CurrentLocationContext); //local do usuário + const context = useContext(EventLocationContext); //local do evento + const contextLocation = useContext(CurrentLocationContext); //local do usuário - const [marker, setMarker] = useState(context.eventCoordinates); + const [marker, setMarker] = useState(context.eventCoordinates); - const getAddress = async (coordenadas) => { - Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc"); + const getAddress = async (coordenadas) => { + Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc"); - const address = await Location.reverseGeocodeAsync(coordenadas); - if (address[0] != undefined) { - context.saveNewLocation( - address[0].street + - ", " + - address[0].name + - "\n" + - address[0].district, - coordenadas - ); - } else { - //Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio - context.saveNewLocation("Erro ao carregar endereço", coordenadas); - } - }; + const address = await Location.reverseGeocodeAsync(coordenadas); + if (address[0] != undefined) { + context.saveNewLocation( + address[0].street + ", " + address[0].name + "\n" + address[0].district, + coordenadas + ); + } else { + //Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio + context.saveNewLocation("Erro ao carregar endereço", coordenadas); + } + }; - const setLocation = () => { - getAddress(marker); - props.navigation.goBack(null); - }; + const setLocation = () => { + getAddress(marker); + props.navigation.goBack(null); + }; - const map_scale = 0.003; - const lat_long_delta = { - latitudeDelta: map_scale, - longitudeDelta: map_scale * (screen_width / screen_height), - }; + const map_scale = 0.003; + const lat_long_delta = { + latitudeDelta: map_scale, + longitudeDelta: map_scale * (screen_width / screen_height), + }; - return ( - - { - console.log(r); - setMarker({ latitude: r.latitude, longitude: r.longitude }); - }} - > - - - - - setLocation()}> - - Confirmar - - - - - ); + const default_location = { + latitude: -12.901799, + longitude: -51.692116, + latitudeDelta: 70, + longitudeDelta: 70 * (screen_width / screen_height), + }; + + return ( + + { + console.log(r); + setMarker({ latitude: r.latitude, longitude: r.longitude }); + }} + /> + + + + + + setLocation()}> + + Confirmar + + + + + ); }; const styles = StyleSheet.create({ - container: { - backgroundColor: colors.black, - flex: 1, - }, - mapStyle: { - position: "absolute", - top: 0, - left: 0, - right: 0, - bottom: 0, - }, - button: { - backgroundColor: "#1976D2", - borderRadius: 20, - justifyContent: "center", - alignItems: "center", - width: "100%", - height: 42, - marginVertical: 10, - textAlign: "center", - }, - markerFixed: { - left: "50%", - marginLeft: -24, - marginTop: -48, - position: "absolute", - top: "50%", - height: 48, - width: 48, - }, - text: { - color: colors.white, - fontSize: 16, - textTransform: "uppercase", - fontWeight: "bold", - }, - marker: { - height: 48, - width: 48, - }, + submit_btn: { + position: "absolute", + bottom: 0, + width: "100%", + padding: 20, + }, + container: { + backgroundColor: colors.black, + flex: 1, + }, + mapStyle: { + position: "absolute", + top: 0, + left: 0, + right: 0, + bottom: 0, + }, + button: { + backgroundColor: "#1976D2", + borderRadius: 20, + justifyContent: "center", + alignItems: "center", + width: "100%", + height: 42, + marginVertical: 10, + textAlign: "center", + }, + markerFixed: { + left: "50%", + marginLeft: -24, + marginTop: -48, + position: "absolute", + top: "50%", + height: 48, + width: 48, + }, + text: { + color: colors.white, + fontSize: 16, + textTransform: "uppercase", + fontWeight: "bold", + }, + marker: { + height: 48, + width: 48, + }, }); export default MapFormScreen;