From eb25480919c73af5c02771c6124494f415f7a063 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Sat, 1 Apr 2023 17:44:58 +0200 Subject: Working app --- modules/Main.js | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 modules/Main.js (limited to 'modules/Main.js') diff --git a/modules/Main.js b/modules/Main.js new file mode 100644 index 0000000..18457b0 --- /dev/null +++ b/modules/Main.js @@ -0,0 +1,162 @@ +import * as React from 'react'; +import { useState, useEffect } from 'react'; +import { View, Text, StyleSheet, TouchableOpacity, FlatList, Switch, ActivityIndicator, Image } from 'react-native'; +import * as Location from 'expo-location'; +import { useFonts } from "expo-font"; +import AsyncStorage from "@react-native-async-storage/async-storage"; + +import Fira from "../assets/Fira.ttf"; +import LocIcon from "../assets/LocIcon.png"; + +const L_KEY = 'locs_key' + +export default function Main(props) { + const [fontLoaded] = useFonts({ + Fira, + }); + const [isLoading, setIsLoading] = useState(false); + const [locs, _setLocs] = useState([]); + const setLocs = async (nls) => { + await AsyncStorage.setItem(L_KEY, JSON.stringify(nls)) + _setLocs(nls) + } + const saveLocs = async () => { + await AsyncStorage.setItem(L_KEY, JSON.stringify(locs)) + } + useEffect(() => { + (async () => { + const x = JSON.parse(await AsyncStorage.getItem(L_KEY)) + if (x) _setLocs(x); + + const { status } = await Location.requestForegroundPermissionsAsync(); + if (status !== "granted") { + alert("Permission to access location was denied"); + } + })(); + }, []); + // useEffect(() => console.log(locs)) + const getPosition = async () => { + let loc = { c: false, l: await Location.getCurrentPositionAsync(), } + setLocs([...locs, loc]) + }; + const [switchState, setSwitchState] = useState(false); + const pins = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + if (isLoading) { + return ( + + ) + } + return ( + + + + LOAD{'\n'}AND SAVE{'\n'}POSITION + setLocs([])} style={styles.navBtn}>REMOVE{'\n'}ALL DATA + + + { await saveLocs(); props.navigation.navigate("mapV") }} style={styles.navBtnB}>GO TO THE MAP + { + setLocs(locs.map(l => { l.c = a; return l })) + setSwitchState(a) + }} + /> + + + { + console.log("item", item) + return ( + + + + - Timestamp {item.l.timestamp} + - Latitude {item.l.coords.latitude} + - Longitude {item.l.coords.longitude} + + { + setLocs(locs.map(l => { + if (l.l.timestamp === item.l.timestamp) + l.c = a + return l + } + )) + }} + /> + + ) + }} + keyExtractor={p => { + console.log('p', p); + p.l.timestamp + }} + style={styles.list} + /> + + ) +} + +const styles = StyleSheet.create({ + cont: { + flex: 1, + margin: 30, + }, + nav: { + flex: 1, + flexDirection: "column", + flexWrap: "wrap", + // backgroundColor: "red", + }, + navEl: { + flex: 1, + flexDirection: "row", + // backgroundColor: "blue", + }, + navTxt: { + fontSize: 26, + textAlign: "center", + fontWeight: "bold", + }, + navTxtSm: { + fontSize: 26, + fontWeight: "bold", + }, + navBtn: { + flex: 1, + }, + map: { + // backgroundColor: "orange", + flex: 1, + flexDirection: "row", + }, + mapSwitch: { + flex: 1, + height: 65, + }, + navBtnB: { + flex: 1, + }, + list: { + // height: 414, + flex: 1, + // margin: 9, + paddingBottom: 170, + // height: "100%", + // marginBottom: -20, + }, + itemTxt: { + fontSize: 15, + fontWeight: "bold", + }, +}) + -- cgit v1.3.1