Skip to content

Commit d943efc

Browse files
committed
feat: Update SettWrapper to support onBackPress prop and enhance LocationSpeed title
1 parent 16954a3 commit d943efc

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@
7777
"engines": {
7878
"node": ">=18"
7979
}
80-
}
80+
}

src/components/Settings/SettWrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import { ScrollViewProps, useColorScheme, View } from 'react-native'
1111
type SettWrapperProps = ScrollViewProps & {
1212
Header?: React.ReactNode
1313
title?: string
14+
onBackPress?: () => void
1415
}
15-
export default function SettWrapper({ Header, title, children, ...rest }: SettWrapperProps) {
16+
export default function SettWrapper({ Header, title, children, onBackPress, ...rest }: SettWrapperProps) {
1617
const navigation = useNavigation<StackNav>()
1718
const scheme = useColorScheme()
1819
return (
1920
<View className='bg flex-1'>
2021
<AutoStatusBar scheme={scheme} />
21-
{Header ? Header : <BackHeader title={title || 'Test Title'} navigation={navigation} />}
22+
{Header ? Header : <BackHeader title={title || 'Test Title'} navigation={navigation} onBackPress={onBackPress} />}
2223
<KeyboardAvoid
2324
contentContainerStyle={{ paddingBottom: 20 }}
2425
showsHorizontalScrollIndicator={false}

src/screens/LocationNotes/LocationNote.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function LocationNote({ navigation, route }: LocationNoteProps) {
8888
</SettGroup>
8989
<SettGroup title='Description'>
9090
<Input
91-
placeholder='This is a input field with multiple lines. You can type as much as you want.'
91+
placeholder='Describe this location...'
9292
multiline
9393
numberOfLines={10}
9494
value={description}

src/screens/LocationNotes/NewLocationNote.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Home01SolidIcon, InformationCircleSolidIcon, Location01Icon } from '@assets/icons/icons'
2-
import { BtnTransparent } from '@components/Button'
2+
import Btn, { BtnTransparent } from '@components/Button'
33
import { Gap12 } from '@components/Gap'
44
import { Input } from '@components/Input'
55
import RoundedIcon from '@components/RoundedIcon'
@@ -9,12 +9,13 @@ import SettWrapper from '@components/Settings/SettWrapper'
99
import { fetchLocation } from '@screens/LocationNotes/lib'
1010
import { locationNotesStore } from '@screens/LocationNotes/locationNotesStore'
1111
import { useQuery } from '@tanstack/react-query'
12+
import { NavProp } from '@utils/types'
1213
import { useCallback, useEffect, useState } from 'react'
1314
import { BackHandler, View } from 'react-native'
1415
import { GeoPosition } from 'react-native-geolocation-service'
1516
import LocationDetails from './LocationDetails'
1617

17-
export default function NewLocationNote() {
18+
export default function NewLocationNote({ navigation }: NavProp) {
1819
const [name, setName] = useState<string>('')
1920
const [description, setDescription] = useState<string>('')
2021
const updateNote = locationNotesStore((state) => state.updateNote)
@@ -45,6 +46,11 @@ export default function NewLocationNote() {
4546
return false
4647
}, [handleSave])
4748

49+
function saveAndGoBack() {
50+
handleSave()
51+
navigation.goBack()
52+
}
53+
4854
useEffect(() => {
4955
const backHandler = BackHandler.addEventListener('hardwareBackPress', onBackPress)
5056
return () => backHandler.remove()
@@ -55,8 +61,10 @@ export default function NewLocationNote() {
5561
return () => clearTimeout(timer)
5662
}, [handleSave])
5763

64+
const isDisabled = !name || name.trim().length === 0 || !data
65+
5866
return (
59-
<SettWrapper className='flex-1' title={name || 'New Location Note'}>
67+
<SettWrapper className='flex-1' title={name || 'New Location Note'} onBackPress={saveAndGoBack}>
6068
<Gap12 className='mt-3'>
6169
<SettGroup title='Location Name'>
6270
<Input
@@ -68,7 +76,7 @@ export default function NewLocationNote() {
6876
</SettGroup>
6977
<SettGroup title='Description'>
7078
<Input
71-
placeholder='This is a input field with multiple lines. You can type as much as you want.'
79+
placeholder='Describe this location...'
7280
multiline
7381
numberOfLines={10}
7482
value={description}
@@ -85,12 +93,13 @@ export default function NewLocationNote() {
8593
/>
8694
</SettGroup>
8795
<LocationDetails data={data} />
88-
<View className='px-5'>
96+
<View className='gap-8 px-5'>
8997
<BtnTransparent
9098
title={isFetching ? 'Fetching...' : 'Refetch Location'}
9199
onPress={() => refetch()}
92100
disabled={isFetching}
93101
/>
102+
<Btn title='Save This Location' onPress={saveAndGoBack} disabled={isDisabled} />
94103
</View>
95104
</Gap12>
96105
</SettWrapper>

src/screens/LocationSpeed/LocationSpeed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default function LocationSpeed() {
4242
let s = speed < 10 ? speed.toFixed(1) : speed.toFixed(0)
4343

4444
return (
45-
<SettWrapper title='Location Speed'>
45+
<SettWrapper title='Location Speed Meter'>
4646
<View className='py-20 pb-16'>
4747
<Bold className='text pl-12 text-center' style={{ fontSize: 100, lineHeight: 100 }}>
4848
{s}

0 commit comments

Comments
 (0)