From 73bd76e98634eab237d6974ba0c3422398a641be Mon Sep 17 00:00:00 2001 From: Yann-prak <75838267+Yann-prak@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:53:36 +0200 Subject: [PATCH] Handle undefined callbacks ios (#5) * update glide license url * Handle undefined callbacks in setters on iOS native module @onurersel --------- Co-authored-by: Lu --- README.md | 4 ++-- ios/FastImage/FFFastImageView.m | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index de1d2a5..faf1dc8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ ### ⚠️ This is a fork of https://github.com/DylanVann/react-native-fast-image. All credit goes to the original author. +

🚩 FastImage

@@ -186,7 +187,6 @@ e.g. `onLoad={e => console.log(e.nativeEvent.width, e.nativeEvent.height)}` Called on an image fetching error or when source is malformed (i.e: empty or null). - --- ### `onLoadEnd?: () => void` @@ -268,7 +268,7 @@ Thanks to [@mobinni](https://github.com/mobinni) for helping with the conceptual - FastImage - MIT © [Dream11](https://github.com/dream11) - SDWebImage - `MIT` -- Glide - BSD, part MIT and Apache 2.0. See the [LICENSE](https://github.com/bumptech/glide/blob/master/license) file for details. +- Glide - BSD, part MIT and Apache 2.0. See the [LICENSE](https://github.com/bumptech/glide/blob/master/LICENSE) file for details. [build-badge]: https://github.com/dream-sports-labs/react-native-fast-image/workflows/CI/badge.svg [build]: https://github.com/dream-sports-labs/react-native-fast-image/actions?query=workflow%3ACI diff --git a/ios/FastImage/FFFastImageView.m b/ios/FastImage/FFFastImageView.m index 7e1b016..3d3ad5c 100644 --- a/ios/FastImage/FFFastImageView.m +++ b/ios/FastImage/FFFastImageView.m @@ -32,21 +32,21 @@ - (void) setResizeMode: (RCTResizeMode)resizeMode { - (void) setOnFastImageLoadEnd: (RCTDirectEventBlock)onFastImageLoadEnd { _onFastImageLoadEnd = onFastImageLoadEnd; - if (self.hasCompleted) { + if (self.hasCompleted && _onFastImageLoadEnd) { _onFastImageLoadEnd(@{}); } } - (void) setOnFastImageLoad: (RCTDirectEventBlock)onFastImageLoad { _onFastImageLoad = onFastImageLoad; - if (self.hasCompleted) { + if (self.hasCompleted && _onFastImageLoad) { _onFastImageLoad(self.onLoadEvent); } } - (void) setOnFastImageError: (RCTDirectEventBlock)onFastImageError { _onFastImageError = onFastImageError; - if (self.hasErrored) { + if (self.hasErrored && _onFastImageError) { _onFastImageError(@{}); } } @@ -54,7 +54,9 @@ - (void) setOnFastImageError: (RCTDirectEventBlock)onFastImageError { - (void) setOnFastImageLoadStart: (RCTDirectEventBlock)onFastImageLoadStart { if (_source && !self.hasSentOnLoadStart) { _onFastImageLoadStart = onFastImageLoadStart; - onFastImageLoadStart(@{}); + if (onFastImageLoadStart) { + onFastImageLoadStart(@{}); + } self.hasSentOnLoadStart = YES; } else { _onFastImageLoadStart = onFastImageLoadStart;