Skip to content

Commit bbc247c

Browse files
committed
feat: add ios version without events
1 parent 5fc980b commit bbc247c

7 files changed

+143
-12
lines changed

ios/FastImage/FFFastImageView.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,16 @@
2020
@property (nonatomic, strong) UIImage *defaultSource;
2121
@property (nonatomic, strong) UIColor *imageColor;
2222

23+
@property(nonatomic, assign) BOOL hasSentOnLoadStart;
24+
@property(nonatomic, assign) BOOL hasCompleted;
25+
@property(nonatomic, assign) BOOL hasErrored;
26+
// Whether the latest change of props requires the image to be reloaded
27+
@property(nonatomic, assign) BOOL needsReload;
28+
29+
@property(nonatomic, strong) NSDictionary* onLoadEvent;
30+
31+
- (void)reloadImage;
32+
- (void)didSetProps:(NSArray<NSString*>*)changedProps;
33+
2334
@end
2435

ios/FastImage/FFFastImageView.m

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
#import <SDWebImage/UIImage+MultiFormat.h>
33
#import <SDWebImage/UIView+WebCache.h>
44

5-
@interface FFFastImageView ()
6-
7-
@property(nonatomic, assign) BOOL hasSentOnLoadStart;
8-
@property(nonatomic, assign) BOOL hasCompleted;
9-
@property(nonatomic, assign) BOOL hasErrored;
10-
// Whether the latest change of props requires the image to be reloaded
11-
@property(nonatomic, assign) BOOL needsReload;
12-
13-
@property(nonatomic, strong) NSDictionary* onLoadEvent;
14-
15-
@end
16-
175
@implementation FFFastImageView
186

197
- (id) init {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
2+
3+
#import <React/RCTViewComponentView.h>
4+
5+
NS_ASSUME_NONNULL_BEGIN
6+
7+
@interface FFFastImageViewComponentView : RCTViewComponentView
8+
9+
10+
@end
11+
12+
NS_ASSUME_NONNULL_END
13+
14+
#endif
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
2+
3+
#import "FFFastImageViewComponentView.h"
4+
#import "FFFastImageView.h"
5+
6+
#import <React/RCTConversions.h>
7+
#import <React/RCTFabricComponentsPlugins.h>
8+
#import <react/renderer/components/rnfastimage/ComponentDescriptors.h>
9+
#import <react/renderer/components/rnfastimage/Props.h>
10+
11+
using namespace facebook::react;
12+
13+
@implementation FFFastImageViewComponentView
14+
{
15+
FFFastImageView *fastImageView;
16+
}
17+
18+
+ (ComponentDescriptorProvider)componentDescriptorProvider
19+
{
20+
return concreteComponentDescriptorProvider<FastImageViewComponentDescriptor>();
21+
}
22+
23+
- (instancetype)initWithFrame:(CGRect)frame
24+
{
25+
if (self = [super initWithFrame:frame]) {
26+
static const auto defaultProps = std::make_shared<const FastImageViewProps>();
27+
_props = defaultProps;
28+
fastImageView = [[FFFastImageView alloc] initWithFrame:self.bounds];
29+
self.contentView = fastImageView;
30+
}
31+
return self;
32+
}
33+
34+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps{
35+
36+
const auto &newViewProps = *std::static_pointer_cast<FastImageViewProps const>(props);
37+
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;
45+
46+
FFFCacheControl cacheControl;
47+
switch (newViewProps.source.cache) {
48+
case FastImageViewCache::Web:
49+
cacheControl = FFFCacheControl::FFFCacheControlWeb;
50+
break;
51+
case FastImageViewCache::CacheOnly:
52+
cacheControl = FFFCacheControl::FFFCacheControlCacheOnly;
53+
break;
54+
case FastImageViewCache::Immutable:
55+
default:
56+
cacheControl = FFFCacheControl::FFFCacheControlImmutable;
57+
break;
58+
}
59+
imageSource.cacheControl = cacheControl;
60+
61+
FFFPriority priority;
62+
switch (newViewProps.source.priority) {
63+
case FastImageViewPriority::Low:
64+
priority = FFFPriority::FFFPriorityLow;
65+
break;
66+
case FastImageViewPriority::Normal:
67+
priority = FFFPriority::FFFPriorityNormal;
68+
break;
69+
case FastImageViewPriority::High:
70+
default:
71+
priority = FFFPriority::FFFPriorityHigh;
72+
break;
73+
}
74+
75+
76+
imageSource.priority = priority;
77+
78+
[fastImageView setSource: imageSource];
79+
80+
81+
RCTResizeMode resizeMode;
82+
switch (newViewProps.resizeMode) {
83+
case FastImageViewResizeMode::Contain:
84+
resizeMode = RCTResizeMode::RCTResizeModeContain;
85+
break;
86+
case FastImageViewResizeMode::Stretch:
87+
resizeMode = RCTResizeMode::RCTResizeModeStretch;
88+
break;
89+
case FastImageViewResizeMode::Center:
90+
resizeMode = RCTResizeMode::RCTResizeModeCenter;
91+
break;
92+
case FastImageViewResizeMode::Cover:
93+
default:
94+
resizeMode = RCTResizeMode::RCTResizeModeCover;
95+
break;
96+
}
97+
[fastImageView setResizeMode:resizeMode];
98+
99+
fastImageView.imageColor = RCTUIColorFromSharedColor(newViewProps.tintColor);
100+
101+
[super updateProps:props oldProps:oldProps];
102+
[fastImageView didSetProps:nil];
103+
}
104+
105+
- (void)prepareForRecycle
106+
{
107+
[super prepareForRecycle];
108+
fastImageView = [[FFFastImageView alloc] initWithFrame:self.bounds];
109+
}
110+
111+
@end
112+
113+
Class<RCTComponentViewProtocol> FastImageViewCls(void)
114+
{
115+
return FFFastImageViewComponentView.class;
116+
}
117+
118+
#endif

0 commit comments

Comments
 (0)