Skip to content

Instantly share code, notes, and snippets.

@adderly
Created June 17, 2023 20:59
Show Gist options
  • Save adderly/9cf1b5c2d6f51365a870c7ac70388c9a to your computer and use it in GitHub Desktop.
Save adderly/9cf1b5c2d6f51365a870c7ac70388c9a to your computer and use it in GitHub Desktop.
React native web fixes patch react-native-fast-image+8.6.3.patch
diff --git a/node_modules/react-native-fast-image/dist/index.js b/node_modules/react-native-fast-image/dist/index.js
index 58e0308..7762e14 100644
--- a/node_modules/react-native-fast-image/dist/index.js
+++ b/node_modules/react-native-fast-image/dist/index.js
@@ -1,6 +1,6 @@
import _extends from '@babel/runtime/helpers/extends';
import React, { forwardRef, memo } from 'react';
-import { NativeModules, StyleSheet, requireNativeComponent, Image, View, Platform } from 'react-native';
+import { NativeModules, StyleSheet, Platform, View, Image } from 'react-native';
const resizeMode = {
contain: 'contain',
@@ -60,11 +60,10 @@ function FastImageBase({
forwardedRef,
...props
}) {
- if (fallback) {
+ if (fallback || Platform.OS === 'web') {
const cleanedSource = { ...source
};
delete cleanedSource.cache;
- const resolvedSource = Image.resolveAssetSource(cleanedSource);
return /*#__PURE__*/React.createElement(View, {
style: [styles.imageContainer, style],
ref: forwardedRef
@@ -72,8 +71,8 @@ function FastImageBase({
style: [StyleSheet.absoluteFill, {
tintColor
}],
- source: resolvedSource,
- defaultSource: defaultSource,
+ source: cleanedSource,
+ defaultSource: cleanedSource,
onLoadStart: onLoadStart,
onProgress: onProgress,
onLoad: onLoad,
@@ -122,16 +121,26 @@ const styles = StyleSheet.create({
imageContainer: {
overflow: 'hidden'
}
-}); // Types of requireNativeComponent are not correct.
-
-const FastImageView = requireNativeComponent('FastImageView', FastImage, {
- nativeOnly: {
- onFastImageLoadStart: true,
- onFastImageProgress: true,
- onFastImageLoad: true,
- onFastImageError: true,
- onFastImageLoadEnd: true
- }
});
+let FastImageView;
+
+if (Platform.OS === 'web') {
+ FastImageView = Image;
+} else {
+ // Types of requireNativeComponent are not correct.
+ const {
+ requireNativeComponent
+ } = require('react-native');
+
+ FastImageView = requireNativeComponent('FastImageView', FastImage, {
+ nativeOnly: {
+ onFastImageLoadStart: true,
+ onFastImageProgress: true,
+ onFastImageLoad: true,
+ onFastImageError: true,
+ onFastImageLoadEnd: true
+ }
+ });
+}
export default FastImage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment