You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BrandingImageBackground.tsx 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react';
  2. import { Image, ImageStyle, StyleProp, ViewStyle } from 'react-native';
  3. import { SvgUri } from 'react-native-svg';
  4. import { IReduxState } from '../../../app/types';
  5. import { connect } from '../../../base/redux/functions';
  6. import styles from './styles';
  7. interface IProps {
  8. uri?: string;
  9. }
  10. /**
  11. * Component that displays a branding background image.
  12. *
  13. * @param {IProps} props - The props of the component.
  14. * @returns {ReactElement}
  15. */
  16. const BrandingImageBackground: React.FC<IProps> = ({ uri }: IProps) => {
  17. const imageType = uri?.substr(uri.lastIndexOf('/') + 1);
  18. const imgSrc = uri ? uri : undefined;
  19. let backgroundImage;
  20. if (!uri) {
  21. return null;
  22. }
  23. if (imageType?.includes('.svg')) {
  24. backgroundImage
  25. = (
  26. <SvgUri
  27. height = '100%'
  28. // Force uniform scaling.
  29. // Align the <min-x> of the element's viewBox
  30. // with the smallest X value of the viewport.
  31. // Align the <min-y> of the element's viewBox
  32. // with the smallest Y value of the viewport.
  33. preserveAspectRatio = 'xMinYMin'
  34. style = { styles.brandingImageBackgroundSvg as StyleProp<ViewStyle> }
  35. uri = { imgSrc ?? null }
  36. viewBox = '0 0 400 650'
  37. width = '100%' />
  38. );
  39. } else {
  40. backgroundImage
  41. = (
  42. <Image
  43. source = {{ uri: imgSrc }}
  44. style = { styles.brandingImageBackground as StyleProp<ImageStyle> } />
  45. );
  46. }
  47. return backgroundImage;
  48. };
  49. /**
  50. * Maps (parts of) the Redux state to the associated props for the
  51. * {@code DialInLink} component.
  52. *
  53. * @param {Object} state - The Redux state.
  54. * @private
  55. * @returns {IProps}
  56. */
  57. function _mapStateToProps(state: IReduxState) {
  58. const { backgroundImageUrl } = state['features/dynamic-branding'];
  59. return {
  60. uri: backgroundImageUrl
  61. };
  62. }
  63. export default connect(_mapStateToProps)(BrandingImageBackground);