Skip to content

Commit ca5250d

Browse files
committed
feat: Refactor watchLocation to use default options and enhance LocationSpeed display
1 parent d943efc commit ca5250d

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ android {
103103
applicationId "com.techtriangle"
104104
minSdkVersion rootProject.ext.minSdkVersion
105105
targetSdkVersion rootProject.ext.targetSdkVersion
106-
versionCode 14
107-
versionName "1.5.0"
106+
versionCode 15
107+
versionName "1.5.1"
108108
}
109109

110110
splits {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export const variants = [
2+
'stroke-rounded' as const,
3+
'stroke-standard' as const,
4+
'solid-standard' as const,
5+
'duotone-rounded' as const,
6+
'twotone-rounded' as const,
7+
'solid-rounded' as const,
8+
'bulk-rounded' as const,
9+
'stroke-sharp' as const,
10+
'solid-sharp' as const,
11+
]
12+
13+
export type Variant = (typeof variants)[number]
14+
15+
export type IconProps = {
16+
variant?: Variant
17+
size?: number
18+
color?: string
19+
strokeWidth?: number
20+
className?: string
21+
fill?: string
22+
}
23+
24+
export const defaultStrokeWidth = 1.5
25+
export const defaultColor = 'currentColor'
26+
export const defaultVariant = 'stroke-rounded'
27+
export const defaultSize = 24

src/screens/LocationNotes/lib.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@ export const fetchLocation = async (): Promise<Geolocation.GeoPosition> => {
2626
export const watchLocation = async (
2727
onSuccess: (position: Geolocation.GeoPosition) => void,
2828
onError: (error: LocationError) => void,
29-
options: Geolocation.GeoWatchOptions = {},
3029
): Promise<number> => {
3130
const hasPermission = await requestPermissions()
3231
if (!hasPermission) {
3332
onError({ code: 1, message: 'Location permission not granted' })
3433
return -1
3534
}
36-
return Geolocation.watchPosition(onSuccess, onError, options)
35+
return Geolocation.watchPosition(onSuccess, onError, {
36+
accuracy: {
37+
android: 'high',
38+
ios: 'best',
39+
},
40+
enableHighAccuracy: true,
41+
distanceFilter: 0, // Update on every change
42+
interval: 1000,
43+
fastestInterval: 1000,
44+
})
3745
}
3846

3947
export const requestPermissions = async (): Promise<boolean> => {

src/screens/LocationSpeed/LocationSpeed.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import SettWrapper from '@components/Settings/SettWrapper'
22
import { watchLocation } from '@screens/LocationNotes/lib'
33
import LocationDetails from '@screens/LocationNotes/LocationDetails'
4-
import { Bold, SemiBold } from '@utils/fonts'
4+
import { Bold, MEDIUM, SemiBold } from '@utils/fonts'
5+
import { layout } from '@utils/utils'
56
import { useEffect, useState } from 'react'
67
import { View } from 'react-native'
78
import Geolocation from 'react-native-geolocation-service'
9+
import Animated from 'react-native-reanimated'
810

911
export default function LocationSpeed() {
1012
const [pos, setPos] = useState<Geolocation.GeoPosition | null>(null)
@@ -21,10 +23,6 @@ export default function LocationSpeed() {
2123
(err) => {
2224
console.log(err)
2325
},
24-
{
25-
enableHighAccuracy: true,
26-
interval: 1000,
27-
},
2826
)
2927
}
3028

@@ -39,15 +37,21 @@ export default function LocationSpeed() {
3937
}, [])
4038

4139
let speed = pos?.coords.speed || 0
42-
let s = speed < 10 ? speed.toFixed(1) : speed.toFixed(0)
40+
// Convert from m/s to km/h (multiply by 3.6)
41+
let speedKmh = speed * 3.6
42+
let s = speedKmh < 10 ? speedKmh.toFixed(1) : speedKmh.toFixed(0)
4343

4444
return (
4545
<SettWrapper title='Location Speed Meter'>
4646
<View className='py-20 pb-16'>
47-
<Bold className='text pl-12 text-center' style={{ fontSize: 100, lineHeight: 100 }}>
47+
<Animated.Text
48+
className='text pl-14 text-center'
49+
style={[{ fontSize: 130, lineHeight: 130 }, MEDIUM]}
50+
layout={layout}
51+
>
4852
{s}
49-
<Bold style={{ fontSize: 30 }}>m/s</Bold>
50-
</Bold>
53+
<Bold style={{ fontSize: 25 }}>km/h</Bold>
54+
</Animated.Text>
5155
<SemiBold className='text text-center text-xl'>Your Speed</SemiBold>
5256
</View>
5357
<LocationDetails data={pos} />

0 commit comments

Comments
 (0)