react-native-svg#SvgUri TypeScript Examples
The following examples show how to use
react-native-svg#SvgUri.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From NLW-1.0 with MIT License | 4 votes |
Points: React.FC = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPoints() {
const response = await api.get("/items");
setItems(response.data);
}
loadPoints();
}, []);
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== "granted") {
Alert.alert(
"Ooooops...",
"Precisamos de sua permissão para obter a localização"
);
return;
}
const location = await Location.getCurrentPositionAsync({
enableHighAccuracy: true,
});
const { latitude, longitude } = location.coords;
setInitialPosition([latitude, longitude]);
}
loadPosition();
});
useEffect(() => {
async function loadPoints() {
const response = await api.get("/points", {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems,
},
});
setPoints(response.data);
}
loadPoints();
}, [selectedItems]);
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate("Detail", { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex((item) => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter((item) => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([...selectedItems, id]);
}
}
return (
<>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>
Encontre no mapa um ponto de coleta.
</Text>
<View style={styles.mapContainer}>
{initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map((point) => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image
style={styles.mapMarkerImage}
source={{
uri: point.image_url,
}}
/>
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
)}
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
contentContainerStyle={{
paddingHorizontal: 32,
}}
horizontal
showsHorizontalScrollIndicator={false}
>
{items.map((item) => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {},
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</>
);
}
Example #2
Source File: index.tsx From ecoleta with MIT License | 4 votes |
Points: React.FC = () => {
const [items, setItems] = useState<IItem[]>([]);
const [points, setPoints] = useState<IPoint[]>([]);
const [selectedItems, setSelectedItems] = useState<string[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
const route = useRoute();
const { city, uf } = route.params as IParams;
const navigation = useNavigation();
useEffect(() => {
async function loadPosition(): Promise<void> {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert(
'Ooooops',
'Precisamos de sua permissão para obter a localização',
);
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([-21.6235108, -55.1598438]);
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
setItems(response.data);
});
}, []);
useEffect(() => {
if (selectedItems.length) {
api
.get('points', {
params: {
city,
uf,
items: selectedItems,
},
})
.then(response => setPoints(response.data));
}
}, [selectedItems, city, uf]);
const handleNavigateToDetail = useCallback(
(id: string) => {
navigation.navigate('Detail', { point_id: id });
},
[navigation],
);
const handleSelectItem = useCallback(
(id: string) => {
const alreadySelected = selectedItems.findIndex(item => item === id);
alreadySelected >= 0
? setSelectedItems(oldItems => oldItems.filter(item => item !== id))
: setSelectedItems(oldItems => [...oldItems, id]);
},
[selectedItems],
);
return (
<S.StyledSafeAreaView style={{ flex: 1 }}>
<S.Container>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<S.Title>Bem vindo.</S.Title>
<S.Description>Encontre no mapa um ponto de coleta.</S.Description>
<S.MapContainer>
{initialPosition[0] !== 0 && (
<S.Map
loadingEnabled={initialPosition[0] === 0}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.105,
longitudeDelta: 0.105,
}}
>
{points?.map(point => (
<S.MapMarker
key={point.id}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<S.MapMarkerContainer>
<S.MapMarkerImage
source={{
uri: point.image_url,
}}
/>
<S.MapMarkerTitle>{point.name}</S.MapMarkerTitle>
</S.MapMarkerContainer>
</S.MapMarker>
))}
</S.Map>
)}
</S.MapContainer>
</S.Container>
<S.ItemsContainer>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{
paddingHorizontal: 20,
}}
>
{items?.map((item: IItem) => (
<S.Item
style={
selectedItems.includes(item.id) && {
borderColor: '#34cb79',
borderWidth: 2,
}
}
key={item.id}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<S.ItemTitle>{item.title}</S.ItemTitle>
</S.Item>
))}
</ScrollView>
</S.ItemsContainer>
</S.StyledSafeAreaView>
);
}
Example #3
Source File: index.tsx From NextLevelWeek with MIT License | 4 votes |
Points: React.FC = () => {
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
// Salvando a lat e lon do usuário
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
useEffect(() => {
api.get("/items").then((res) => {
setItems(res.data);
});
}, []);
/**
* Função para pegar a localização do usuário.
*/
useEffect(() => {
async function LoadPosition() {
// Pedindo ao usuário para autorizar a localização.
const { status } = await Location.requestPermissionsAsync();
// Se não deu a permissão para acessar.
if (status !== "granted") {
Alert.alert(
"Ooooooops...",
"Precisamos de sua permissão para obter a localização."
);
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
// console.log(latitude, longitude);
setInitialPosition([latitude, longitude]);
}
LoadPosition();
}, []);
/**
* Carregando os Pontos.
*/
useEffect(() => {
api
.get("/points", {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems,
},
})
.then((res) => {
setPoints(res.data);
});
}, [selectedItems]);
/**
* Função para voltar na página anterior.
*/
function handleBackToTheFuture() {
navigation.goBack();
}
/**
* Função para navegar quando clicar na imagem no mapa.
*/
function handleNavigateToDetail(id: number) {
navigation.navigate("Detail", { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex((item) => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter((item) => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([...selectedItems, id]);
}
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleBackToTheFuture}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>
Encontre no mapa um ponto de coleta.
</Text>
<View style={styles.mapContainer}>
{initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map((point) => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image
style={styles.mapMarkerImage}
source={{
uri: point.image_url,
}}
/>
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
)}
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map((item) => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {},
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</SafeAreaView>
);
}
Example #4
Source File: index.tsx From nlw-ecoleta with MIT License | 4 votes |
Points = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([0, 0]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPosition(){
const { status } = await Location.requestPermissionsAsync();
if(status !== 'granted') {
Alert.alert('Oooops...', 'Precisamos da sua permissão para obter a localização');
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([
latitude,
longitude
])
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
console.log(response.data);
setItems(response.data);
});
}, []);
useEffect(() => {
api.get('points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems
}
}).then(response => {
console.log(response.data);
setPoints(response.data);
})
}, [selectedItems]);
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex(item => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter(item => item !== id);
setSelectedItems(filteredItems);
}
else {
setSelectedItems([ ...selectedItems, id ]);
}
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>Encontre no mapa um ponto de coleta.</Text>
<View style={styles.mapContainer}>
{ initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map(point => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image style={styles.mapMarkerImage} source={{ uri: point.image_url }} />
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
) }
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map(item => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {}
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</SafeAreaView>
);
}
Example #5
Source File: index.tsx From nlw-01-omnistack with MIT License | 4 votes |
Points = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([0, 0]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Oooops...', 'Precisamos de sua permissão para obter a localização');
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
console.log(latitude, longitude);
setInitialPosition([
latitude,
longitude
])
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
setItems(response.data);
});
}, []);
useEffect(() => {
api.get('points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems
}
}).then(response => {
setPoints(response.data);
})
}, [selectedItems]);
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex(item => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter(item => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([ ...selectedItems, id ]);
}
}
return (
<>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>Encontre no mapa um ponto de coleta.</Text>
<View style={styles.mapContainer}>
{ initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{selectedItems[0] !== undefined && (points.map(point => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image style={styles.mapMarkerImage} source={{ uri: point.image_url }} />
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
)))}
</MapView>
) }
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map(item => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {}
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</>
);
}
Example #6
Source File: index.tsx From ecoleta with MIT License | 4 votes |
Points = () => {
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
const [initialPosition, setInitialPosition] = useState<[number, number]>([
0,
0,
]);
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert(
'Oops!',
'Precisamos da sua permissão para obter a localização'
);
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([latitude, longitude]);
}
loadPosition();
}, []);
useEffect(() => {
api
.get('/points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems,
},
})
.then((response) => {
setPoints(response.data);
});
}, [selectedItems]);
useEffect(() => {
api.get('/items').then((response) => {
setItems(response.data);
});
}, []);
function handleSelectItem(id: number) {
const alreadySelected = selectedItems.findIndex((item) => item === id);
if (alreadySelected >= 0) {
const filteredItems = selectedItems.filter((item) => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([...selectedItems, id]);
}
}
function handleNavigateBack() {
navigation.goBack();
}
function handleNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Feather name="arrow-left" color="#34CB79" size={24} />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo</Text>
<Text style={styles.description}>
Encontre no mapa um pronto de coleta.
</Text>
<View style={styles.mapContainer}>
{initialPosition[0] !== 0 && (
<MapView
style={styles.map}
loadingEnabled={initialPosition[0] === 0}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map((point) => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handleNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image
style={styles.mapMarkerImage}
source={{
uri: point.image_url,
}}
/>
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
)}
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map((item) => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {},
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</SafeAreaView>
);
}
Example #7
Source File: index.tsx From ecoleta with MIT License | 4 votes |
Points = () => {
const [items, setItems] = useState<Item[]>([]);
const [points, setPoints] = useState<Point[]>([]);
const [selectedItems, setSelectedItems] = useState<number[]>([]);
const [initialPosition, setInitialPosition] = useState<[number, number]>([0, 0]);
const navigation = useNavigation();
const route = useRoute();
const routeParams = route.params as Params;
useEffect(() => {
async function loadPosition() {
const { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Ooops...', 'Precisamos de sua permissão para obter a localização.');
return;
}
const location = await Location.getCurrentPositionAsync();
const { latitude, longitude } = location.coords;
setInitialPosition([
latitude,
longitude
]);
}
loadPosition();
}, []);
useEffect(() => {
api.get('items').then(response => {
setItems(response.data);
});
}, []);
useEffect(() => {
api.get('points', {
params: {
city: routeParams.city,
uf: routeParams.uf,
items: selectedItems
}
}).then(response => {
setPoints(response.data);
})
}, [selectedItems])
function handleNavigateBack() {
navigation.goBack();
}
function handeNavigateToDetail(id: number) {
navigation.navigate('Detail', { point_id: id });
}
function handleSelectItem(id: number) {
const alreadSelected = selectedItems.findIndex(item => item === id);
if (alreadSelected >= 0) {
const filteredItems = selectedItems.filter(item => item !== id);
setSelectedItems(filteredItems);
} else {
setSelectedItems([ ...selectedItems, id]);
}
}
return (
<>
<View style={styles.container}>
<TouchableOpacity onPress={handleNavigateBack}>
<Icon name="arrow-left" size={20} color="#34cb79" />
</TouchableOpacity>
<Text style={styles.title}>Bem vindo.</Text>
<Text style={styles.description}>Encontre no mapa um ponto de coleta.</Text>
<View style={styles.mapContainer}>
{ initialPosition[0] !== 0 && (
<MapView
style={styles.map}
initialRegion={{
latitude: initialPosition[0],
longitude: initialPosition[1],
latitudeDelta: 0.014,
longitudeDelta: 0.014,
}}
>
{points.map(point => (
<Marker
key={String(point.id)}
style={styles.mapMarker}
onPress={() => handeNavigateToDetail(point.id)}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
>
<View style={styles.mapMarkerContainer}>
<Image style={styles.mapMarkerImage} source={{ uri: point.image_url }} />
<Text style={styles.mapMarkerTitle}>{point.name}</Text>
</View>
</Marker>
))}
</MapView>
) }
</View>
</View>
<View style={styles.itemsContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: 20 }}
>
{items.map(item => (
<TouchableOpacity
key={String(item.id)}
style={[
styles.item,
selectedItems.includes(item.id) ? styles.selectedItem : {}
]}
onPress={() => handleSelectItem(item.id)}
activeOpacity={0.6}
>
<SvgUri width={42} height={42} uri={item.image_url} />
<Text style={styles.itemTitle}>{item.title}</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</>
);
}