import * as React from 'react'; import { Component, Types, View } from 'reactxp'; interface IProps { source: string; width?: number; height?: number; tintColor?: string; tintHoverColor?: string; disabled?: boolean; onPress?: (event: Types.SyntheticEvent) => void; style?: Types.StyleRuleSetRecursive; } interface IState { hovered: boolean; } export default class ImageView extends Component { public state = { hovered: false }; public render() { const { source, width, height, tintColor, tintHoverColor, ...otherProps } = this.props; const url = `../../assets/images/${source}.svg`; let image; const activeTintColor = (this.state.hovered && tintHoverColor) || tintColor; if (activeTintColor) { const maskWidth = typeof width === 'number' ? `${width}px` : 'auto'; const maskHeight = typeof height === 'number' ? `${height}px` : 'auto'; image = (
); } else { image = ; } return ( {image} ); } private onHoverStart = () => { if (!this.props.disabled) { this.setState({ hovered: true }); } }; private onHoverEnd = () => { if (!this.props.disabled) { this.setState({ hovered: false }); } }; }