-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Show icons associated with a preset (#348)
* add get image url to preset icon * handle error, and show default icon * update packages, add snipet to get all presets * add ability to show icon based on iconId, get icon based on presetName, pass new props in all components * rename interface in PresetIcon component, generate again package-lock.json * rename interface in PresetIcon component, generate again package-lock.json * restore package-lock.file
- Loading branch information
1 parent
2d7cdea
commit 907d251
Showing
7 changed files
with
85 additions
and
87 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
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
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 was deleted.
Oops, something went wrong.
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,53 @@ | ||
import React, {memo} from 'react'; | ||
import {Image} from 'react-native'; | ||
|
||
import {Circle} from './Circle'; | ||
import {IconSize} from '../../sharedTypes'; | ||
import {UIActivityIndicator} from 'react-native-indicators'; | ||
import {useGetPresetIcon} from '../../hooks/server/presets'; | ||
import MaterialIcon from 'react-native-vector-icons/MaterialIcons'; | ||
|
||
interface PresetIconProps { | ||
size?: IconSize; | ||
name?: string; | ||
} | ||
|
||
const iconSizes = { | ||
small: 22, | ||
medium: 35, | ||
large: 50, | ||
}; | ||
|
||
const radii = { | ||
small: 15, | ||
medium: 25, | ||
large: 35, | ||
}; | ||
|
||
export const PresetIcon = memo<PresetIconProps>(({size = 'medium', name}) => { | ||
const iconSize = iconSizes[size] || 35; | ||
const {data, isLoading} = useGetPresetIcon(size, name); | ||
const [error, setError] = React.useState(false); | ||
|
||
if (isLoading) return <UIActivityIndicator size={30} />; | ||
|
||
// Fallback to a default icon if we can't load the icon from mapeo-server | ||
if (error || !name) return <MaterialIcon name="place" size={iconSize} />; | ||
|
||
return ( | ||
<Image | ||
style={{width: iconSize, height: iconSize}} | ||
resizeMode="contain" | ||
source={{uri: data}} | ||
onError={() => setError(true)} | ||
/> | ||
); | ||
}); | ||
|
||
export const PresetCircleIcon = ({name, size = 'medium'}: PresetIconProps) => { | ||
return ( | ||
<Circle radius={radii[size]}> | ||
<PresetIcon name={name} size={size} /> | ||
</Circle> | ||
); | ||
}; |