@@ -2,6 +2,25 @@ import { Image as RNImage } from 'react-native';
22
33export * from 'react-native' ;
44
5+ function getSizeWithHeaders ( uri , headers , success , failure ) {
6+ setTimeout ( ( ) => {
7+ let dimensions = [ 0 , 0 ] ;
8+ if ( typeof uri === 'string' ) {
9+ if ( uri === 'error' ) {
10+ failure ?. apply ( null , new Error ( 'Could not fetch image dimensions' ) ) ;
11+ return ;
12+ }
13+ const match = / ( \d + ) x ( \d + ) / gi. exec ( uri ) ;
14+ if ( ! match ) {
15+ dimensions = [ 640 , 360 ] ;
16+ } else {
17+ dimensions = [ parseInt ( match [ 1 ] , 10 ) , parseInt ( match [ 2 ] , 10 ) ] ;
18+ }
19+ }
20+ success . apply ( null , dimensions ) ;
21+ } , 50 ) ;
22+ }
23+
524export class Image extends RNImage {
625 /**
726 * This mock function will parse the uri to find a dimension pattern
@@ -13,26 +32,11 @@ export class Image extends RNImage {
1332 * be extracted, it will use 640x360.
1433 */
1534 static getSizeWithHeaders ( uri , headers , success , failure ) {
16- setTimeout ( ( ) => {
17- let dimensions = [ 0 , 0 ] ;
18- if ( typeof uri === 'string' ) {
19- if ( uri === 'error' ) {
20- failure ?. apply ( null , new Error ( 'Could not fetch image dimensions' ) ) ;
21- return ;
22- }
23- const match = / ( \d + ) x ( \d + ) / gi. exec ( uri ) ;
24- if ( ! match ) {
25- dimensions = [ 640 , 360 ] ;
26- } else {
27- dimensions = [ parseInt ( match [ 1 ] , 10 ) , parseInt ( match [ 2 ] , 10 ) ] ;
28- }
29- }
30- success . apply ( null , dimensions ) ;
31- } , 50 ) ;
35+ getSizeWithHeaders ( uri , headers , callback , failure ) ;
3236 }
3337
3438 static getSize ( uri , callback , failure ) {
35- Image . getSizeWithHeaders ( uri , undefined , callback , failure ) ;
39+ getSizeWithHeaders ( uri , undefined , callback , failure ) ;
3640 }
3741}
3842
0 commit comments