react-native APIs
- View
- StyleSheet
- Text
- Platform
- TouchableOpacity
- ScrollView
- Image
- ViewStyle
- Dimensions
- StatusBar
- TextInput
- FlatList
- SafeAreaView
- TextStyle
- ActivityIndicator
- Alert
- StyleProp
- Animated
- Linking
- TouchableWithoutFeedback
- Button
- NativeModules
- KeyboardAvoidingView
- TextInputProps
- ViewProps
- Keyboard
- Easing
- ImageBackground
- TextProps
- LayoutChangeEvent
- NativeSyntheticEvent
- NativeEventEmitter
- Switch
- AppRegistry
- ImageStyle
- ImageSourcePropType
- TouchableOpacityProps
- Modal
- AppState
- RefreshControl
- TouchableHighlight
- BackHandler
- useWindowDimensions
- GestureResponderEvent
- AppStateStatus
- PixelRatio
- useColorScheme
- SectionList
- Pressable
- AsyncStorage
- UIManager
- I18nManager
- ImageProps
- LogBox
- FlatListProps
- LayoutRectangle
- findNodeHandle
- EmitterSubscription
- requireNativeComponent
- PermissionsAndroid
- InteractionManager
- ScrollViewProps
- TextInputFocusEventData
- Share
- ColorSchemeName
- ScaledSize
- Clipboard
- Insets
- NativeScrollEvent
- ListRenderItem
- LayoutAnimation
- TouchableNativeFeedback
- PanResponder
- SectionListData
- ListRenderItemInfo
- AccessibilityRole
- AccessibilityInfo
- ImageURISource
- ViewToken
- SectionListProps
- DeviceEventEmitter
- KeyboardEvent
- ActionSheetIOS
- processColor
- YellowBox
- DevSettings
- Slider
- ViewabilityConfig
- AccessibilityState
- EventSubscription
- Permission
- TextInputSelectionChangeEventData
- EasingFunction
- TouchableHighlightProps
- TextInputSubmitEditingEventData
- TextInputChangeEventData
- Appearance
- KeyboardTypeOptions
- AccessibilityEvent
- NativeScrollPoint
- ActionSheetIOSOptions
- HostComponent
- PlatformOSType
- ITheme
- IThemeColors
- IThemeFonts
- IThemeLayout
- IThemeUtils
- ViewPropTypes
- SectionListRenderItem
- NativeAppEventEmitter
- Picker
- VirtualizedList
- SectionListRenderItemInfo
- TextInputKeyPressEventData
- ShareAction
- ImageErrorEventData
- ProgressViewIOS
- ProgressBarAndroid
- RotateXTransform
- RotateYTransform
- PerpectiveTransform
- RotateTransform
- RotateZTransform
- ScaleTransform
- ScaleXTransform
- ScaleYTransform
- TranslateXTransform
- TranslateYTransform
- SkewXTransform
- SkewYTransform
- TransformsStyle
- NativeModulesStatic
- CheckBox
Other Related APIs
- react#useState
- react#useCallback
- react#ReactNode
- react#useRef
- react-native#View
- react-native#Animated
- react-native#StyleSheet
- react-native#StyleProp
- react-native#ViewStyle
- react-native#Image
- react-native#ImageBackground
- react-native#ImageSourcePropType
- react-native#NativeSyntheticEvent
- react-native#ImageProps
react-native#ImageErrorEventData TypeScript Examples
The following examples show how to use
react-native#ImageErrorEventData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From react-native-better-image with MIT License | 4 votes |
BetterImage = ({
viewStyle,
thumbnailFadeDuration = 250,
imageFadeDuration = 250,
thumbnailSource,
source,
onLoadEnd,
resizeMethod,
resizeMode,
thumbnailBlurRadius = 1,
style,
fallbackSource = { uri: '' },
onError,
children,
...otherProps
}: BetterImageProps) => {
const imageOpacity = useRef(new Value(0)).current;
const thumbnailOpacity = useRef(new Value(0)).current;
const thumbnailAnimationProgress = useRef<
Animated.CompositeAnimation | undefined
>();
const [hasError, setHasError] = useState(false);
const [hasLoaded, setHasLoaded] = useState(false);
const onImageLoad = () => {
setHasLoaded(true);
timing(imageOpacity, {
toValue: 1,
duration: imageFadeDuration,
useNativeDriver: true,
}).start(() => {
thumbnailAnimationProgress.current?.stop();
timing(thumbnailOpacity, {
toValue: 0,
duration: thumbnailFadeDuration,
useNativeDriver: true,
}).start();
});
onLoadEnd && onLoadEnd();
};
const onThumbnailLoad = () => {
if (!hasLoaded) {
const progress = timing(thumbnailOpacity, {
toValue: 1,
duration: thumbnailFadeDuration,
useNativeDriver: true,
});
thumbnailAnimationProgress.current = progress;
thumbnailAnimationProgress.current.start();
}
};
const onImageLoadError = (
event: NativeSyntheticEvent<ImageErrorEventData>
) => {
setHasError(true);
onError && onError(event);
};
useDeepCompareEffectNoCheck(
useCallback(() => {
imageOpacity.setValue(0);
thumbnailOpacity.setValue(0);
setHasError(false);
setHasLoaded(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []),
[source, thumbnailSource]
);
const ImageComponent = children ? AnimatedImageBackground : AnimatedImage;
return (
<View style={[styles.imageContainerStyle, viewStyle]}>
{thumbnailSource ? (
<ImageComponent
children={children}
onLoadEnd={onThumbnailLoad}
style={[
styles.thumbnailImageStyle,
{ opacity: thumbnailOpacity },
style,
]}
source={thumbnailSource}
blurRadius={thumbnailBlurRadius}
resizeMethod={resizeMethod}
resizeMode={resizeMode}
/>
) : null}
<ImageComponent
children={children}
resizeMethod={resizeMethod}
resizeMode={resizeMode}
onLoadEnd={onImageLoad}
onError={hasError ? () => null : onImageLoadError}
source={hasError ? fallbackSource : source}
style={[styles.imageStyle, { opacity: imageOpacity }, style]}
{...otherProps}
/>
</View>
);
}