Fix crash in RCTImageComponentView.didReceiveImage

Summary:
Changelog: [Internal]

I went over the ownership model in this call `_state->getData().getImageRequest().getImageInstrumentation().didSetImage();`

1. `getData()` returns reference to an object that is copied to state.
2. `getImageRequest()` returns a reference to an object that is strongly owned by `ImageState`.
3. `getImageInstrumentation()` returns a reference to an object that is strongly owned by `ImageRequest`.

I don't think any of these can cause a crash, however `_state` can be nullptr.

Reviewed By: shergin

Differential Revision: D19599258

fbshipit-source-id: 317f03cd9a53d83f64ccbb9f9abfce10fcc1fae5
This commit is contained in:
Samuel Susla
2020-01-28 12:02:25 -08:00
committed by Facebook Github Bot
parent f7c6066425
commit af1762cce5
@@ -136,7 +136,7 @@ using namespace facebook::react;
- (void)didReceiveImage:(UIImage *)image fromObserver:(void const *)observer
{
if (!_eventEmitter) {
if (!_eventEmitter || !_state) {
// Notifications are delivered asynchronously and might arrive after the view is already recycled.
// In the future, we should incorporate an `EventEmitter` into a separate object owned by `ImageRequest` or `State`.
// See for more info: T46311063.
@@ -167,7 +167,12 @@ using namespace facebook::react;
self->_imageView.layer.minificationFilter = kCAFilterTrilinear;
self->_imageView.layer.magnificationFilter = kCAFilterTrilinear;
_state->getData().getImageRequest().getImageInstrumentation().didSetImage();
auto data = _state->getData();
auto instrumentation = std::static_pointer_cast<RCTImageInstrumentationProxy const>(
data.getImageRequest().getSharedImageInstrumentation());
if (instrumentation) {
instrumentation->didSetImage();
}
}
- (void)didReceiveProgress:(float)progress fromObserver:(void const *)observer