2022-05-23 15:02:14 +00:00
|
|
|
import React from 'react';
|
2022-07-11 12:30:37 +00:00
|
|
|
import { Image, ImageStyle, StyleProp, ViewStyle } from 'react-native';
|
2022-05-23 15:02:14 +00:00
|
|
|
import { SvgUri } from 'react-native-svg';
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2022-07-27 09:56:07 +00:00
|
|
|
import { connect } from '../../../base/redux/functions';
|
2022-06-18 19:59:10 +00:00
|
|
|
|
2022-05-23 15:02:14 +00:00
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps {
|
2022-09-06 17:32:20 +00:00
|
|
|
uri?: string;
|
2022-05-23 15:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that displays a branding background image.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IProps} props - The props of the component.
|
2022-05-23 15:02:14 +00:00
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
const BrandingImageBackground: React.FC<IProps> = ({ uri }: IProps) => {
|
2022-05-23 15:02:14 +00:00
|
|
|
const imageType = uri?.substr(uri.lastIndexOf('/') + 1);
|
|
|
|
const imgSrc = uri ? uri : undefined;
|
|
|
|
|
|
|
|
let backgroundImage;
|
|
|
|
|
2022-06-18 19:59:10 +00:00
|
|
|
if (!uri) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-05-23 15:02:14 +00:00
|
|
|
if (imageType?.includes('.svg')) {
|
|
|
|
backgroundImage
|
|
|
|
= (
|
|
|
|
<SvgUri
|
|
|
|
height = '100%'
|
2022-06-21 14:51:25 +00:00
|
|
|
|
|
|
|
// Force uniform scaling.
|
|
|
|
// Align the <min-x> of the element's viewBox
|
|
|
|
// with the smallest X value of the viewport.
|
|
|
|
// Align the <min-y> of the element's viewBox
|
|
|
|
// with the smallest Y value of the viewport.
|
|
|
|
preserveAspectRatio = 'xMinYMin'
|
2022-07-11 12:30:37 +00:00
|
|
|
style = { styles.brandingImageBackgroundSvg as StyleProp<ViewStyle> }
|
2022-09-06 17:32:20 +00:00
|
|
|
uri = { imgSrc ?? null }
|
2022-06-21 14:51:25 +00:00
|
|
|
viewBox = '0 0 400 650'
|
2022-05-23 15:02:14 +00:00
|
|
|
width = '100%' />
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
backgroundImage
|
|
|
|
= (
|
|
|
|
<Image
|
|
|
|
source = {{ uri: imgSrc }}
|
2022-07-11 12:30:37 +00:00
|
|
|
style = { styles.brandingImageBackground as StyleProp<ImageStyle> } />
|
2022-05-23 15:02:14 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return backgroundImage;
|
|
|
|
};
|
|
|
|
|
2022-06-18 19:59:10 +00:00
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code DialInLink} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
2022-10-20 09:11:27 +00:00
|
|
|
* @returns {IProps}
|
2022-06-18 19:59:10 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function _mapStateToProps(state: IReduxState) {
|
2022-06-18 19:59:10 +00:00
|
|
|
const { backgroundImageUrl } = state['features/dynamic-branding'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
uri: backgroundImageUrl
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(BrandingImageBackground);
|