1
1
#ifdef RCT_NEW_ARCH_ENABLED
2
2
3
3
#import " FFFastImageViewComponentView.h"
4
+ #import " RCTConvert+FFFastImage.h"
4
5
#import " FFFastImageView.h"
5
6
6
7
#import < React/RCTConversions.h>
@@ -35,46 +36,47 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
35
36
36
37
const auto &newViewProps = *std::static_pointer_cast<FastImageViewProps const >(props);
37
38
38
- NSString *sourceStr = [NSString stringWithCString: newViewProps.source.uri.c_str () encoding: [NSString defaultCStringEncoding ]];
39
- NSURL *imageUrl = [[NSURL alloc ] initWithString: sourceStr];
40
- FFFastImageSource *imageSource = fastImageView.source ;
41
- if (imageSource == NULL ){
42
- imageSource = [[FFFastImageSource alloc ] init ];
43
- }
44
- imageSource.url = imageUrl;
39
+ NSMutableDictionary *imageSourcePropsDict = [NSMutableDictionary new ];
40
+ imageSourcePropsDict[@" uri" ] = RCTNSStringFromStringNilIfEmpty (newViewProps.source .uri );
41
+ NSMutableDictionary * headers = [[NSMutableDictionary alloc ] init ];
42
+ for (auto & element : newViewProps.source .headers ) {
43
+ [headers setValue: RCTNSStringFromString (element.value) forKey: RCTNSStringFromString (element.name)];
44
+ }
45
+ if (headers.count > 0 ) {
46
+ imageSourcePropsDict[@" headers" ] = headers;
47
+ }
45
48
46
- FFFCacheControl cacheControl;
49
+ NSString * cacheControl;
47
50
switch (newViewProps.source .cache ) {
48
51
case FastImageViewCache::Web:
49
- cacheControl = FFFCacheControl::FFFCacheControlWeb ;
52
+ cacheControl = @" web " ;
50
53
break ;
51
54
case FastImageViewCache::CacheOnly:
52
- cacheControl = FFFCacheControl::FFFCacheControlCacheOnly ;
55
+ cacheControl = @" cacheOnly " ;
53
56
break ;
54
57
case FastImageViewCache::Immutable:
55
58
default :
56
- cacheControl = FFFCacheControl::FFFCacheControlImmutable ;
59
+ cacheControl = @" immutable " ;
57
60
break ;
58
61
}
59
- imageSource. cacheControl = cacheControl;
62
+ imageSourcePropsDict[ @" cache " ] = cacheControl;
60
63
61
- FFFPriority priority;
64
+ NSString * priority;
62
65
switch (newViewProps.source .priority ) {
63
66
case FastImageViewPriority::Low:
64
- priority = FFFPriority::FFFPriorityLow ;
67
+ priority = @" low " ;
65
68
break ;
66
69
case FastImageViewPriority::Normal:
67
- priority = FFFPriority::FFFPriorityNormal ;
70
+ priority = @" normal " ;
68
71
break ;
69
72
case FastImageViewPriority::High:
70
73
default :
71
- priority = FFFPriority::FFFPriorityHigh ;
74
+ priority = @" high " ;
72
75
break ;
73
76
}
77
+ imageSourcePropsDict[@" priority" ] = priority;
78
+ FFFastImageSource *imageSource = [RCTConvert FFFastImageSource: imageSourcePropsDict];
74
79
75
-
76
- imageSource.priority = priority;
77
-
78
80
[fastImageView setSource: imageSource];
79
81
80
82
@@ -99,6 +101,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
99
101
fastImageView.imageColor = RCTUIColorFromSharedColor (newViewProps.tintColor );
100
102
101
103
[super updateProps: props oldProps: oldProps];
104
+ // this method decides whether to reload the image so we call it after updating the props
105
+ // It does not care about the changed props, but
102
106
[fastImageView didSetProps: nil ];
103
107
}
104
108
0 commit comments