RCTImageResponseObserverProxy.mm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import "RCTImageResponseObserverProxy.h"
  8. #import <react/imagemanager/ImageResponseObserver.h>
  9. #import <react/imagemanager/ImageResponse.h>
  10. namespace facebook {
  11. namespace react {
  12. RCTImageResponseObserverProxy::RCTImageResponseObserverProxy(void* delegate): delegate_((__bridge id<RCTImageResponseDelegate>)delegate) {}
  13. void RCTImageResponseObserverProxy::didReceiveImage(const ImageResponse &imageResponse) {
  14. UIImage *image = (__bridge UIImage *)imageResponse.getImage().get();
  15. void *this_ = this;
  16. dispatch_async(dispatch_get_main_queue(), ^{
  17. [delegate_ didReceiveImage:image fromObserver:this_];
  18. });
  19. }
  20. void RCTImageResponseObserverProxy::didReceiveProgress (float p) {
  21. void *this_ = this;
  22. dispatch_async(dispatch_get_main_queue(), ^{
  23. [delegate_ didReceiveProgress:p fromObserver:this_];
  24. });
  25. }
  26. void RCTImageResponseObserverProxy::didReceiveFailure() {
  27. void *this_ = this;
  28. dispatch_async(dispatch_get_main_queue(), ^{
  29. [delegate_ didReceiveFailureFromObserver:this_];
  30. });
  31. }
  32. } // namespace react
  33. } // namespace facebook