@@ -9,6 +9,8 @@ const BROKEN_URL = 'file:///Desktop/website/img/cupcake.jpg';
9
9
const DEFAULT_SIZE = 100 ;
10
10
11
11
const file = Assets . svgs . demo . logo ;
12
+ const uri = { uri : 'http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg' } ;
13
+ const uriWithCss = { uri : 'http://thenewcode.com/assets/svg/accessibility.svg' } ;
12
14
const xml = `
13
15
<svg width="32" height="32" viewBox="0 0 32 32">
14
16
<path
@@ -38,6 +40,13 @@ enum SizeType {
38
40
Percentage = '50%'
39
41
}
40
42
43
+ enum SvgType {
44
+ File = 'file' ,
45
+ Uri = 'uri' ,
46
+ UriWithCss = 'use_with_css' ,
47
+ Xml = 'xml'
48
+ }
49
+
41
50
interface State {
42
51
cover : boolean ;
43
52
showOverlayContent : boolean ;
@@ -46,7 +55,7 @@ interface State {
46
55
margin : number ;
47
56
showErrorImage : boolean ;
48
57
showSvg : boolean ;
49
- isFile : boolean ;
58
+ svgType : SvgType ;
50
59
sizeType : SizeType ;
51
60
}
52
61
@@ -59,10 +68,25 @@ class ImageScreen extends Component<{}, State> {
59
68
margin : 0 ,
60
69
showErrorImage : false ,
61
70
showSvg : false ,
62
- isFile : false ,
71
+ svgType : SvgType . File ,
63
72
sizeType : SizeType . None
64
73
} ;
65
74
75
+ getSvgSource ( ) {
76
+ const { svgType} = this . state ;
77
+ switch ( svgType ) {
78
+ case SvgType . File :
79
+ return file ;
80
+ case SvgType . Uri :
81
+ return uri ;
82
+ case SvgType . UriWithCss :
83
+ return uriWithCss ;
84
+ case SvgType . Xml :
85
+ default :
86
+ return xml ;
87
+ }
88
+ }
89
+
66
90
renderOverlayContent ( ) {
67
91
const { cover, overlayType, showOverlayContent} = this . state ;
68
92
if ( showOverlayContent ) {
@@ -105,14 +129,15 @@ class ImageScreen extends Component<{}, State> {
105
129
}
106
130
107
131
renderSvgImage ( ) {
108
- const { isFile , sizeType} = this . state ;
132
+ const { sizeType} = this . state ;
109
133
const size : any = Number ( sizeType ) || sizeType ;
134
+ const source = this . getSvgSource ( ) ;
110
135
return (
111
136
< >
112
137
{ size ? (
113
- < Image source = { isFile ? file : xml } width = { size } height = { size } />
138
+ < Image source = { source } width = { size } height = { size } />
114
139
) : (
115
- < Image source = { isFile ? file : xml } />
140
+ < Image source = { source } />
116
141
) }
117
142
</ >
118
143
) ;
@@ -134,10 +159,9 @@ class ImageScreen extends Component<{}, State> {
134
159
}
135
160
136
161
renderSvgOptions ( ) {
137
- const { isFile} = this . state ;
138
162
return (
139
163
< >
140
- { renderBooleanOption . call ( this , isFile ? 'Load from file' : 'Use xml const ', 'isFile' ) }
164
+ { renderRadioGroup . call ( this , 'SVG Type' , 'svgType ', SvgType , { isRow : true } ) }
141
165
{ renderRadioGroup . call ( this , 'Size Type' , 'sizeType' , SizeType , { isRow : true } ) }
142
166
</ >
143
167
) ;
0 commit comments