Skip to content

Commit

Permalink
Use ConcreteStateTeller in RCTImageComponentView
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D23239098

fbshipit-source-id: fa558e705e121f3d3fbded80ae99e5f51c80ae4a
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Aug 24, 2020
1 parent 0f7a114 commit 1704a72
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @interface RCTImageComponentView () <RCTImageResponseDelegate>

@implementation RCTImageComponentView {
UIImageView *_imageView;
ImageShadowNode::ConcreteState::Shared _state;
ImageShadowNode::ConcreteStateTeller _stateTeller;
ImageResponseObserverCoordinator const *_coordinator;
RCTImageResponseObserverProxy _imageResponseObserverProxy;
}
Expand Down Expand Up @@ -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<ImageShadowNode::ConcreteState const>(state);
_stateTeller.setConcreteState(state);
auto _oldState = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(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.
Expand Down Expand Up @@ -120,7 +120,7 @@ - (void)prepareForRecycle
[super prepareForRecycle];
self.coordinator = nullptr;
_imageView.image = nil;
_state.reset();
_stateTeller.invalidate();
}

- (void)dealloc
Expand All @@ -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.
Expand All @@ -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<RCTImageInstrumentationProxy const>(
data.getImageRequest().getSharedImageInstrumentation());
data.value().getImageRequest().getSharedImageInstrumentation());
if (instrumentation) {
instrumentation->didSetImage();
}
Expand Down

0 comments on commit 1704a72

Please sign in to comment.