8
8
#import < React/RCTFabricComponentsPlugins.h>
9
9
#import < react/renderer/components/rnfastimage/ComponentDescriptors.h>
10
10
#import < react/renderer/components/rnfastimage/Props.h>
11
+ #import < react/renderer/components/rnfastimage/EventEmitters.h>
11
12
12
13
using namespace facebook ::react;
13
14
14
15
@implementation FFFastImageViewComponentView
15
16
{
16
17
FFFastImageView *fastImageView;
18
+ BOOL _shouldPostponeUpdate;
17
19
}
18
20
19
21
+ (ComponentDescriptorProvider)componentDescriptorProvider
@@ -32,10 +34,8 @@ - (instancetype)initWithFrame:(CGRect)frame
32
34
return self;
33
35
}
34
36
35
- - (void )updateProps : (Props::Shared const &)props oldProps : (Props::Shared const &)oldProps {
36
-
37
- // TODO: not sure if it is the right place to do it.
38
- [fastImageView setEventEmitter: _eventEmitter];
37
+ - (void )updateProps : (Props::Shared const &)props oldProps : (Props::Shared const &)oldProps
38
+ {
39
39
const auto &newViewProps = *std::static_pointer_cast<FastImageViewProps const >(props);
40
40
41
41
NSMutableDictionary *imageSourcePropsDict = [NSMutableDictionary new ];
@@ -103,9 +103,27 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
103
103
fastImageView.imageColor = RCTUIColorFromSharedColor (newViewProps.tintColor );
104
104
105
105
[super updateProps: props oldProps: oldProps];
106
- // this method decides whether to reload the image so we call it after updating the props
107
- // It does not care about the changed props, but
108
- [fastImageView didSetProps: nil ];
106
+ // this method decides whether to reload the image based on changed props
107
+ // so we call it after updating the props. If the _eventEmitter is not present yet,
108
+ // we postpone the update till it is set in `updateEventEmitter` since we want to send
109
+ // events to JS.
110
+ if (!_eventEmitter) {
111
+ _shouldPostponeUpdate = YES ;
112
+ } else {
113
+ _shouldPostponeUpdate = NO ;
114
+ [fastImageView didSetProps: nil ];
115
+ }
116
+ }
117
+
118
+ - (void )updateEventEmitter : (const facebook::react::EventEmitter::Shared &)eventEmitter
119
+ {
120
+ [super updateEventEmitter: eventEmitter];
121
+ assert (std::dynamic_pointer_cast<FastImageViewEventEmitter const >(eventEmitter));
122
+ [fastImageView setEventEmitter: std: :static_pointer_cast<FastImageViewEventEmitter const >(eventEmitter)];
123
+ if (_shouldPostponeUpdate) {
124
+ // we do the update here since it is the moment we can send events to JS
125
+ [fastImageView didSetProps: nil ];
126
+ }
109
127
}
110
128
111
129
- (void )prepareForRecycle
0 commit comments