Fix server history
This commit is contained in:
parent
a32817202f
commit
f0b4722499
|
@ -1,16 +1,11 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { StyleSheet, Text, View } from 'react-native';
|
import { StyleSheet, View } from 'react-native';
|
||||||
import { createImageProgress } from 'react-native-image-progress';
|
|
||||||
import * as Progress from 'react-native-progress';
|
|
||||||
import FastImage from 'react-native-fast-image';
|
import FastImage from 'react-native-fast-image';
|
||||||
|
|
||||||
import sharedStyles from '../Styles';
|
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import { isTablet } from '../../lib/methods/helpers';
|
import { isTablet } from '../../lib/methods/helpers';
|
||||||
import { TSupportedThemes } from '../../theme';
|
import { TSupportedThemes } from '../../theme';
|
||||||
|
|
||||||
const ImageProgress = createImageProgress(FastImage);
|
|
||||||
|
|
||||||
const SIZE = 96;
|
const SIZE = 96;
|
||||||
const MARGIN_TOP = isTablet ? 0 : 64;
|
const MARGIN_TOP = isTablet ? 0 : 64;
|
||||||
const BORDER_RADIUS = 8;
|
const BORDER_RADIUS = 8;
|
||||||
|
@ -27,50 +22,20 @@ const styles = StyleSheet.create({
|
||||||
width: SIZE,
|
width: SIZE,
|
||||||
height: SIZE,
|
height: SIZE,
|
||||||
borderRadius: BORDER_RADIUS
|
borderRadius: BORDER_RADIUS
|
||||||
},
|
|
||||||
fallback: {
|
|
||||||
width: SIZE,
|
|
||||||
height: SIZE,
|
|
||||||
borderRadius: BORDER_RADIUS,
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center'
|
|
||||||
},
|
|
||||||
initial: {
|
|
||||||
...sharedStyles.textBold,
|
|
||||||
fontSize: 42
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const getInitial = (url: string) => url && url.replace(/http(s?):\/\//, '').slice(0, 1);
|
|
||||||
|
|
||||||
interface IFallback {
|
|
||||||
theme: TSupportedThemes;
|
|
||||||
initial: string;
|
|
||||||
}
|
|
||||||
const Fallback = ({ theme, initial }: IFallback) => (
|
|
||||||
<View style={[styles.container, styles.fallback, { backgroundColor: themes[theme].dangerColor }]}>
|
|
||||||
<Text style={[styles.initial, { color: themes[theme].buttonText }]}>{initial}</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
|
|
||||||
interface IServerAvatar {
|
interface IServerAvatar {
|
||||||
theme: TSupportedThemes;
|
theme: TSupportedThemes;
|
||||||
url: string;
|
url: string;
|
||||||
image: string;
|
image: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: missing skeleton
|
||||||
const ServerAvatar = React.memo(({ theme, url, image }: IServerAvatar) => (
|
const ServerAvatar = React.memo(({ theme, url, image }: IServerAvatar) => (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
{image && (
|
{image && (
|
||||||
<ImageProgress
|
<FastImage style={[styles.image, { borderColor: themes[theme].borderColor }]} source={{ uri: `${url}/${image}` }} />
|
||||||
style={[styles.image, { borderColor: themes[theme].borderColor }]}
|
|
||||||
source={{ uri: `${url}/${image}` }}
|
|
||||||
resizeMode={FastImage.resizeMode.cover}
|
|
||||||
indicator={Progress.Pie}
|
|
||||||
indicatorProps={{
|
|
||||||
color: themes[theme].actionTintColor
|
|
||||||
}}
|
|
||||||
renderError={() => <Fallback theme={theme} initial={getInitial(url)} />}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in New Issue