1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // @flow
-
- import * as React from 'react';
- import {Badge, TouchableRipple, withTheme} from 'react-native-paper';
- import {Dimensions, Image, View} from "react-native";
- import type {CustomTheme} from "../../managers/ThemeManager";
- import * as Animatable from "react-native-animatable";
-
- type Props = {
- image: string,
- onPress: () => void,
- badgeCount: number | null,
- theme: CustomTheme,
- };
-
- const AnimatableBadge = Animatable.createAnimatableComponent(Badge);
-
- /**
- * Component used to render a small dashboard item
- */
- class SmallDashboardItem extends React.Component<Props> {
-
- itemSize: number;
-
- constructor(props: Props) {
- super(props);
- this.itemSize = Dimensions.get('window').width / 8;
- }
-
- shouldComponentUpdate(nextProps: Props) {
- return (nextProps.theme.dark !== this.props.theme.dark)
- || (nextProps.badgeCount !== this.props.badgeCount);
- }
-
- render() {
- const props = this.props;
- return (
- <TouchableRipple
- onPress={this.props.onPress}
- borderless={true}
- style={{
- marginLeft: this.itemSize / 6,
- marginRight: this.itemSize / 6,
- }}
- >
- <View style={{
- width: this.itemSize,
- height: this.itemSize,
- }}>
- <Image
- source={{uri: props.image}}
- style={{
- width: "80%",
- height: "80%",
- marginLeft: "auto",
- marginRight: "auto",
- marginTop: "auto",
- marginBottom: "auto",
- }}
- />
- {
- props.badgeCount != null && props.badgeCount > 0 ?
- <AnimatableBadge
- animation={"zoomIn"}
- duration={300}
- useNativeDriver
- style={{
- position: 'absolute',
- top: 0,
- right: 0,
- backgroundColor: props.theme.colors.primary,
- borderColor: props.theme.colors.background,
- borderWidth: 2,
- }}>
- {props.badgeCount}
- </AnimatableBadge> : null
- }
- </View>
- </TouchableRipple>
-
- );
- }
-
- }
-
- export default withTheme(SmallDashboardItem);
|