-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from SustenTerra/feat/select-state
feat: add state selector component
- Loading branch information
Showing
7 changed files
with
232 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import Feather from '@expo/vector-icons/Feather'; | ||
import { useRouter } from 'expo-router'; | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import RNPickerSelect from 'react-native-picker-select'; | ||
import { useTheme, DefaultTheme } from 'styled-components/native'; | ||
import { brazilianStatesList, StateAcronym } from 'utils/brazilianStatesList'; | ||
|
||
import BackButton from '@/components/BackButton'; | ||
|
||
export default function StateSelector() { | ||
const router = useRouter(); | ||
const [selectedState, setSelectedState] = useState('Todos'); | ||
const theme = useTheme(); | ||
const ref = useRef<RNPickerSelect>(null); | ||
|
||
const handleChange = (value: string) => { | ||
setSelectedState(value); | ||
router.push(`/posts?selectedState=${value}`); | ||
}; | ||
|
||
useEffect(() => { | ||
if (selectedState === 'Todos' && brazilianStatesList.length > 0) { | ||
setSelectedState(brazilianStatesList[0].acronym); | ||
} | ||
}, [selectedState, brazilianStatesList]); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<BackButton defaultRoute="/posts" /> | ||
<View style={styles.pickerContainer}> | ||
<Feather name="map-pin" size={24} color={theme.colors.textBody} /> | ||
<RNPickerSelect | ||
ref={ref} | ||
style={pickerSelectStyles(theme)} | ||
placeholder={{ | ||
label: 'Selecione um Estado', | ||
value: '', | ||
}} | ||
doneText="Selecionar" | ||
onValueChange={handleChange} | ||
items={brazilianStatesList.map((state: StateAcronym) => ({ | ||
label: state.name, | ||
value: state.acronym, | ||
}))} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
const pickerSelectStyles = (theme: DefaultTheme) => | ||
StyleSheet.create({ | ||
viewContainer: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
paddingHorizontal: 20, | ||
backgroundColor: 'white', | ||
}, | ||
inputIOSContainer: { | ||
flex: 1, | ||
}, | ||
inputIOS: { | ||
fontSize: 16, | ||
paddingVertical: 12, | ||
}, | ||
inputWeb: { | ||
borderWidth: 0, | ||
fontSize: 16, | ||
paddingVertical: 12, | ||
}, | ||
inputAndroid: { | ||
fontSize: 16, | ||
paddingVertical: 12, | ||
}, | ||
inputAndroidContainer: { | ||
flex: 1, | ||
}, | ||
placeholder: { | ||
color: theme.colors.textBody, | ||
}, | ||
}); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
padding: 20, | ||
backgroundColor: '#F5F1F0', | ||
}, | ||
pickerContainer: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
borderRadius: 10, | ||
borderWidth: 1, | ||
borderColor: '#dcdcdc', | ||
padding: 8, | ||
marginTop: 16, | ||
width: '100%', | ||
backgroundColor: 'white', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Feather from '@expo/vector-icons/Feather'; | ||
import { Link, useLocalSearchParams } from 'expo-router'; | ||
import { useTheme } from 'styled-components/native'; | ||
|
||
import { Container, StateText } from './styles'; | ||
|
||
export default function StateSelector() { | ||
const theme = useTheme(); | ||
|
||
const { selectedState } = useLocalSearchParams<{ | ||
selectedState: string; | ||
}>(); | ||
|
||
const label = selectedState || 'Todos'; | ||
|
||
return ( | ||
<Link href="/posts/select-state"> | ||
<Container> | ||
<Feather name="map-pin" size={20} color={theme.colors.secondary} /> | ||
|
||
<StateText color="secondary" weight="bold"> | ||
{label} | ||
</StateText> | ||
</Container> | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import styled from 'styled-components/native'; | ||
|
||
import Text from '../Text'; | ||
|
||
import { horizontalScale, moderateScale, verticalScale } from '@/utils/scale'; | ||
|
||
export const Container = styled.TouchableOpacity` | ||
flex-direction: row; | ||
align-items: center; | ||
gap: ${horizontalScale(5)}px; | ||
padding: ${verticalScale(10)}px ${horizontalScale(15)}px; | ||
background-color: ${(props) => props.theme.colors.light}; | ||
border-radius: 100px; | ||
`; | ||
|
||
export const StateText = styled(Text)``; | ||
|
||
export const StatesList = styled.ScrollView` | ||
padding: ${verticalScale(10)}px 0; | ||
top: 100px; | ||
z-index: 1; | ||
`; | ||
|
||
interface ButtonProps { | ||
active: boolean; | ||
} | ||
|
||
export const Button = styled.TouchableOpacity<ButtonProps>` | ||
height: ${verticalScale(40)}px; | ||
padding: ${moderateScale(10)}px ${moderateScale(20)}px; | ||
border-radius: ${moderateScale(40)}px; | ||
margin-right: ${horizontalScale(10)}px; | ||
background-color: ${(props) => | ||
props.active ? props.theme.colors.primary : props.theme.colors.light}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters