import React, {Component} from 'react'; import {ScrollView} from 'react-native'; import {View, Text, Icon, Image, Colors, Assets, OverlayTypes} from 'react-native-ui-lib'; import {renderBooleanOption, renderRadioGroup, renderSliderOption} from '../ExampleScreenPresenter'; const IMAGE_URL = 'https://images.pexels.com/photos/748837/pexels-photo-748837.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260'; const BROKEN_URL = 'file:///Desktop/website/img/cupcake.jpg'; const DEFAULT_SIZE = 100; const file = Assets.svgs.demo.logo; const uri = {uri: 'https://www.svgrepo.com/show/530581/cell-phone.svg'}; // const uriWithCss = {uri: ''}; // TODO: find an example const xml = ` `; enum SizeType { None = '', Fixed = '50', Percentage = '50%' } enum SvgType { File = 'file', Uri = 'uri', // UriWithCss = 'use_with_css', Xml = 'xml' } interface State { cover: boolean; showOverlayContent: boolean; overlayType: 'none' | OverlayTypes['type']; overlayIntensity: OverlayTypes['intensity']; margin: number; showErrorImage: boolean; showSvg: boolean; svgType: SvgType; sizeType: SizeType; } class ImageScreen extends Component<{}, State> { state = { cover: true, showOverlayContent: false, overlayType: 'none', overlayIntensity: Image.overlayIntensityType.LOW, margin: 0, showErrorImage: false, showSvg: false, svgType: SvgType.File, sizeType: SizeType.None, borderRadius: 0 }; getSvgSource() { const {svgType} = this.state; switch (svgType) { case SvgType.File: return file; case SvgType.Uri: return uri; // case SvgType.UriWithCss: // return uriWithCss; case SvgType.Xml: default: return xml; } } renderOverlayContent() { const {cover, overlayType, showOverlayContent} = this.state; if (showOverlayContent) { if (cover) { return ( Overlay Content ); } else { return ; } } } renderImage() { const {cover, overlayType, overlayIntensity, margin, showErrorImage, borderRadius} = this.state; return ( ); } renderSvgImage() { const {sizeType} = this.state; const size: any = Number(sizeType) || sizeType; const source = this.getSvgSource(); return ( <> {size ? ( ) : ( )} ); } renderOptions() { return ( <> {renderBooleanOption.call(this, 'Show as Cover Image', 'cover')} {renderBooleanOption.call(this, 'Show Overlay Content', 'showOverlayContent')} {renderBooleanOption.call(this, 'Show Error Image', 'showErrorImage')} {renderRadioGroup.call(this, 'Overlay Type', 'overlayType', {none: 'none', ...Image.overlayTypes})} {renderRadioGroup.call(this, 'Overlay Intensity', 'overlayIntensity', Image.overlayIntensityType)} {renderSliderOption.call(this, 'Margin(margin-XX)', 'margin', {step: 4, min: 0, max: 40})} {renderSliderOption.call(this, 'Border Radius', 'borderRadius', {step: 5, min: 0, max: 100})} ); } renderSvgOptions() { return ( <> {renderRadioGroup.call(this, 'SVG Type', 'svgType', SvgType, {isRow: true})} {renderRadioGroup.call(this, 'Size Type', 'sizeType', SizeType, {isRow: true})} ); } render() { const {showSvg} = this.state; return ( {showSvg ? this.renderSvgImage() : this.renderImage()} Image Screen {renderBooleanOption.call(this, 'Show SVG', 'showSvg')} {showSvg ? this.renderSvgOptions() : this.renderOptions()} ); } } export default ImageScreen;