Skip to content

Commit 9bb2409

Browse files
authored
fix(iOS): handle variable icons in header items (#3323)
Didn't consider usage of variable icons (2x, 3x) in header items when I implemented RCTImageLoader in RNSBarButtonItem. Sorry about that! This PR fixes this. **Before** <img width="1206" height="2622" alt="Simulator Screenshot - iPhone 17 Pro - 2025-10-22 at 11 55 20" src="https://github.com/user-attachments/assets/5512c0d6-f96c-4c2a-9088-746eb5f539a6" /> **After** <img width="1206" height="2622" alt="Simulator Screenshot - iPhone 17 Pro - 2025-10-22 at 11 50 45" src="https://github.com/user-attachments/assets/20c05364-32fd-4054-b700-444e883c259c" />
1 parent dab5b21 commit 9bb2409

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

apps/src/screens/BarButtonItems.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default function BarButtonItemsExample() {
106106
type: "button",
107107
icon: {
108108
type: "imageSource",
109-
imageSource: require('../../assets/search_black.png')
109+
imageSource: require('../../assets/variableIcons/icon_fill.png')
110110
},
111111
title: "Title",
112112
onPress: () => Alert.alert('Icon pressed'),

ios/RNSBarButtonItem.mm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ - (instancetype)initWithConfig:(NSDictionary<NSString *, id> *)dict
2626
if (imageSourceObj) {
2727
RCTImageSource *imageSource = [RCTConvert RCTImageSource:imageSourceObj];
2828
[imageLoader loadImageWithURLRequest:imageSource.request
29-
callback:^(NSError *_Nullable error, UIImage *_Nullable image) {
30-
dispatch_async(dispatch_get_main_queue(), ^{
31-
self.image = image;
32-
});
33-
}];
29+
size:imageSource.size
30+
scale:imageSource.scale
31+
clipped:true
32+
resizeMode:RCTResizeModeContain
33+
progressBlock:^(int64_t progress, int64_t total) {
34+
}
35+
partialLoadBlock:^(UIImage *_Nonnull image) {
36+
}
37+
completionBlock:^(NSError *_Nullable error, UIImage *_Nullable image) {
38+
dispatch_async(dispatch_get_main_queue(), ^{
39+
self.image = image;
40+
});
41+
}];
3442
}
3543
NSString *sfSymbolName = dict[@"sfSymbolName"];
3644
if (sfSymbolName) {

0 commit comments

Comments
 (0)