@@ -160,6 +160,22 @@ - (UIImage *)imageWithSize:(UIImage *)image convertToSize:(CGSize)size {
160
160
return destImage;
161
161
}
162
162
163
+ - (void )updateItemImageWithURL : (CPListItem *)item imgUrl : (NSString *)imgUrlString {
164
+ NSURL *imgUrl = [NSURL URLWithString: imgUrlString];
165
+
166
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession ] dataTaskWithURL: imgUrl completionHandler: ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
167
+ if (data) {
168
+ UIImage *image = [UIImage imageWithData: data];
169
+ dispatch_async (dispatch_get_main_queue (), ^{
170
+ [item setImage: image];
171
+ });
172
+ } else {
173
+ NSLog (@" Failed to load image from URL: %@ " , imgUrl);
174
+ }
175
+ }];
176
+ [task resume ];
177
+ }
178
+
163
179
RCT_EXPORT_METHOD (checkForConnection) {
164
180
RNCPStore *store = [RNCPStore sharedManager ];
165
181
if ([store isConnected ] && hasListeners) {
@@ -599,7 +615,8 @@ - (UIImage *)imageWithSize:(UIImage *)image convertToSize:(CGSize)size {
599
615
}
600
616
CPListItem *item = (CPListItem *)section.items [index ];
601
617
if (config[@" imgUrl" ]) {
602
- [item setImage: [[UIImage alloc ] initWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [RCTConvert NSString: config[@" imgUrl" ]]]]]];
618
+ NSString *imgUrlString = [RCTConvert NSString: config[@" imgUrl" ]];
619
+ [self updateItemImageWithURL: item imgUrl: imgUrlString];
603
620
}
604
621
if (config[@" image" ]) {
605
622
[item setImage: [RCTConvert UIImage: config[@" image" ]]];
@@ -956,9 +973,6 @@ - (void) applyConfigForMapTemplate:(CPMapTemplate*)mapTemplate templateId:(NSStr
956
973
NSString *_detailText = [item objectForKey: @" detailText" ];
957
974
NSString *_text = [item objectForKey: @" text" ];
958
975
UIImage *_image = [RCTConvert UIImage: [item objectForKey: @" image" ]];
959
- if (item[@" imgUrl" ]) {
960
- _image = [[UIImage alloc ] initWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [RCTConvert NSString: item[@" imgUrl" ]]]]];
961
- }
962
976
CPListItem *_item;
963
977
if (@available (iOS 14.0 , *)) {
964
978
CPListItemAccessoryType accessoryType = _showsDisclosureIndicator ? CPListItemAccessoryTypeDisclosureIndicator : CPListItemAccessoryTypeNone;
@@ -969,6 +983,10 @@ - (void) applyConfigForMapTemplate:(CPMapTemplate*)mapTemplate templateId:(NSStr
969
983
if ([item objectForKey: @" isPlaying" ]) {
970
984
[_item setPlaying: [RCTConvert BOOL: [item objectForKey: @" isPlaying" ]]];
971
985
}
986
+ if (item[@" imgUrl" ]) {
987
+ NSString *imgUrlString = [RCTConvert NSString: item[@" imgUrl" ]];
988
+ [self updateItemImageWithURL: _item imgUrl: imgUrlString];
989
+ }
972
990
[_item setUserInfo: @{ @" index" : @(index ) }];
973
991
[_items addObject: _item];
974
992
index = index + 1 ;
0 commit comments