88#import < React/RCTFabricComponentsPlugins.h>
99#import < react/renderer/components/rnfastimage/ComponentDescriptors.h>
1010#import < react/renderer/components/rnfastimage/Props.h>
11+ #import < react/renderer/components/rnfastimage/EventEmitters.h>
1112
1213using namespace facebook ::react;
1314
1415@implementation FFFastImageViewComponentView
1516{
1617 FFFastImageView *fastImageView;
18+ BOOL _shouldPostponeUpdate;
1719}
1820
1921+ (ComponentDescriptorProvider)componentDescriptorProvider
@@ -32,10 +34,8 @@ - (instancetype)initWithFrame:(CGRect)frame
3234 return self;
3335}
3436
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+ {
3939 const auto &newViewProps = *std::static_pointer_cast<FastImageViewProps const >(props);
4040
4141 NSMutableDictionary *imageSourcePropsDict = [NSMutableDictionary new ];
@@ -103,9 +103,27 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
103103 fastImageView.imageColor = RCTUIColorFromSharedColor (newViewProps.tintColor );
104104
105105 [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+ }
109127}
110128
111129- (void )prepareForRecycle
0 commit comments