From 1704a725c5ec1e3d53c39b0830fb79e3597d818e Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 24 Aug 2020 06:39:29 -0700 Subject: [PATCH] Use ConcreteStateTeller in RCTImageComponentView Summary: Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D23239098 fbshipit-source-id: fa558e705e121f3d3fbded80ae99e5f51c80ae4a --- .../Image/RCTImageComponentView.mm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm b/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm index e617f20b72c702..0de4b95a59235a 100644 --- a/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm @@ -26,7 +26,7 @@ @interface RCTImageComponentView () @implementation RCTImageComponentView { UIImageView *_imageView; - ImageShadowNode::ConcreteState::Shared _state; + ImageShadowNode::ConcreteStateTeller _stateTeller; ImageResponseObserverCoordinator const *_coordinator; RCTImageResponseObserverProxy _imageResponseObserverProxy; } @@ -84,9 +84,9 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & - (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState { - _state = std::static_pointer_cast(state); + _stateTeller.setConcreteState(state); auto _oldState = std::static_pointer_cast(oldState); - auto data = _state->getData(); + auto data = _stateTeller.getData().value(); // This call (setting `coordinator`) must be unconditional (at the same block as setting `State`) // because the setter stores a raw pointer to object that `State` owns. @@ -120,7 +120,7 @@ - (void)prepareForRecycle [super prepareForRecycle]; self.coordinator = nullptr; _imageView.image = nil; - _state.reset(); + _stateTeller.invalidate(); } - (void)dealloc @@ -132,7 +132,7 @@ - (void)dealloc - (void)didReceiveImage:(UIImage *)image fromObserver:(void const *)observer { - if (!_eventEmitter || !_state) { + if (!_eventEmitter || !_stateTeller.isValid()) { // 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. @@ -158,12 +158,12 @@ - (void)didReceiveImage:(UIImage *)image fromObserver:(void const *)observer } void (^didSetImage)() = ^() { - if (!self->_state) { + auto data = self->_stateTeller.getData(); + if (!data.hasValue()) { return; } - auto data = self->_state->getData(); auto instrumentation = std::static_pointer_cast( - data.getImageRequest().getSharedImageInstrumentation()); + data.value().getImageRequest().getSharedImageInstrumentation()); if (instrumentation) { instrumentation->didSetImage(); }