11#ifdef RCT_NEW_ARCH_ENABLED
22
33#import " FFFastImageViewComponentView.h"
4+ #import " RCTConvert+FFFastImage.h"
45#import " FFFastImageView.h"
56
67#import < React/RCTConversions.h>
@@ -35,46 +36,47 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
3536
3637 const auto &newViewProps = *std::static_pointer_cast<FastImageViewProps const >(props);
3738
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+ }
4548
46- FFFCacheControl cacheControl;
49+ NSString * cacheControl;
4750 switch (newViewProps.source .cache ) {
4851 case FastImageViewCache::Web:
49- cacheControl = FFFCacheControl::FFFCacheControlWeb ;
52+ cacheControl = @" web " ;
5053 break ;
5154 case FastImageViewCache::CacheOnly:
52- cacheControl = FFFCacheControl::FFFCacheControlCacheOnly ;
55+ cacheControl = @" cacheOnly " ;
5356 break ;
5457 case FastImageViewCache::Immutable:
5558 default :
56- cacheControl = FFFCacheControl::FFFCacheControlImmutable ;
59+ cacheControl = @" immutable " ;
5760 break ;
5861 }
59- imageSource. cacheControl = cacheControl;
62+ imageSourcePropsDict[ @" cache " ] = cacheControl;
6063
61- FFFPriority priority;
64+ NSString * priority;
6265 switch (newViewProps.source .priority ) {
6366 case FastImageViewPriority::Low:
64- priority = FFFPriority::FFFPriorityLow ;
67+ priority = @" low " ;
6568 break ;
6669 case FastImageViewPriority::Normal:
67- priority = FFFPriority::FFFPriorityNormal ;
70+ priority = @" normal " ;
6871 break ;
6972 case FastImageViewPriority::High:
7073 default :
71- priority = FFFPriority::FFFPriorityHigh ;
74+ priority = @" high " ;
7275 break ;
7376 }
77+ imageSourcePropsDict[@" priority" ] = priority;
78+ FFFastImageSource *imageSource = [RCTConvert FFFastImageSource: imageSourcePropsDict];
7479
75-
76- imageSource.priority = priority;
77-
7880 [fastImageView setSource: imageSource];
7981
8082
@@ -99,6 +101,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
99101 fastImageView.imageColor = RCTUIColorFromSharedColor (newViewProps.tintColor );
100102
101103 [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
102106 [fastImageView didSetProps: nil ];
103107}
104108
0 commit comments