From b9b5f28d5c27cdadaf46ce7573439ae837db0182 Mon Sep 17 00:00:00 2001 From: bohdanprog Date: Tue, 23 Apr 2024 11:56:41 +0200 Subject: [PATCH] restore changes with GPSPill --- src/frontend/screens/MapScreen/index.tsx | 11 ----- src/frontend/sharedComponents/GPSPill.tsx | 46 +++++++++++++------- src/frontend/sharedComponents/HomeHeader.tsx | 15 ++++--- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/frontend/screens/MapScreen/index.tsx b/src/frontend/screens/MapScreen/index.tsx index 6a7594345..899496083 100644 --- a/src/frontend/screens/MapScreen/index.tsx +++ b/src/frontend/screens/MapScreen/index.tsx @@ -21,7 +21,6 @@ import {GPSModal} from './GPSPermissions/GPSPermissionsModal'; import {TrackPathLayer} from './track/TrackPathLayer'; import {UserLocation} from './UserLocation'; import {useSharedLocationContext} from '../../contexts/SharedLocationContext'; -import {useNavigation} from '@react-navigation/native'; // This is the default zoom used when the map first loads, and also the zoom // that the map will zoom to if the user clicks the "Locate" button and the @@ -35,7 +34,6 @@ export const MAP_STYLE = Mapbox.StyleURL.Outdoors; export const MapScreen = () => { const [zoom, setZoom] = React.useState(DEFAULT_ZOOM); - const navigation = useNavigation(); const [isFinishedLoading, setIsFinishedLoading] = React.useState(false); const [following, setFollowing] = React.useState(true); const {newDraft} = useDraftObservation(); @@ -65,15 +63,6 @@ export const MapScreen = () => { setIsFinishedLoading(true); } - React.useEffect(() => { - const unsubscribe = navigation.addListener('focus', e => { - // Prevent default action - console.log(e, 'e'); - // e.preventDefault(); - }); - return () => unsubscribe(); - }, []); - return ( { +export const GPSPill = ({navigation}) => { const isFocused = useIsFocused(); const {formatMessage: t} = useIntl(); const {locationState, fgPermissions} = useSharedLocationContext(); @@ -51,27 +51,43 @@ export const GPSPill = () => { } else return `± ${Math.round(precision!)} m`; }, [precision, status, t]); - const navigation = useNavigationFromHomeTabs(); - return ( - navigation.navigate('GpsModal')}> - - + navigation.navigate('GPSModal' as never)} + testID="gpsPillButton"> + + {isFocused && } - {text} + + {text} + ); }; const styles = StyleSheet.create({ - indicatorWrapper: { - backgroundColor: '#333333', - borderRadius: 20, - paddingVertical: 14, - paddingHorizontal: 10, + container: { + flex: 0, + minWidth: 100, + maxWidth: 200, + borderRadius: 18, + height: 36, + paddingLeft: 32, + paddingRight: 20, + borderWidth: 3, + borderColor: '#33333366', + backgroundColor: BLACK, + justifyContent: 'center', + alignItems: 'center', + flexDirection: 'row', }, - wrapper: {flexDirection: 'row', alignItems: 'center'}, - text: {marginLeft: 5, color: '#fff', fontSize: 15}, + error: {backgroundColor: '#FF0000'}, + text: {color: WHITE}, + icon: {position: 'absolute', left: 6}, }); diff --git a/src/frontend/sharedComponents/HomeHeader.tsx b/src/frontend/sharedComponents/HomeHeader.tsx index 770fc73c7..de079690b 100644 --- a/src/frontend/sharedComponents/HomeHeader.tsx +++ b/src/frontend/sharedComponents/HomeHeader.tsx @@ -1,13 +1,16 @@ -import React from 'react'; +import React, {FC} from 'react'; import {View, StyleSheet} from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import {IconButton} from './IconButton'; import {ObservationListIcon} from './icons'; import {GPSPill} from './GPSPill'; -import {useNavigationFromHomeTabs} from '../hooks/useNavigationWithTypes'; +import {NavigationProp} from '@react-navigation/native'; -export const HomeHeader = () => { - const navigation = useNavigationFromHomeTabs(); +interface HomeHeader { + navigation: NavigationProp; +} + +export const HomeHeader: FC = ({navigation}) => { return ( { colors={['#0006', '#0000']} /> {/* Placeholder for left button */} - + { - navigation.navigate('ObservationList'); + navigation.navigate('ObservationList' as never); }} testID="observationListButton">