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#Component
- react#PropsWithChildren
- react-native#Platform
- react-native#StyleSheet
- react-native#StyleProp
- react-native#Image
- react-native#ImageStyle
- react-native#LayoutChangeEvent
- react-native#InteractionManager
- react-native#ImageBackground
- react-native#ImageProps
- react-native-reanimated#always
- react-native-reanimated#block
- react-native-reanimated#Extrapolate
- react-native-reanimated#interpolate
- react-native-reanimated#multiply
- react-native-reanimated#Node
- react-native-reanimated#set
react-native#ImageURISource TypeScript Examples
The following examples show how to use
react-native#ImageURISource.
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: CachedImage.tsx From companion-kit with MIT License | 5 votes |
export function CachedImage(this: void, props: CachedImageProps) {
const [imgURI, setImgURI] = React.useState('');
const state = React.useMemo(() => ({ loading: false, mounted: false }), []);
const safeCall = React.useCallback((cb: () => any) => {
if (state.mounted) {
cb();
}
}, [state]);
const loadImage = async (filesystemURI: string, remoteURI: string) => {
try {
// Use the cached image if it exists
const metadata = await FileSystem.getInfoAsync(filesystemURI);
if (metadata.exists) {
safeCall(() => setImgURI(filesystemURI));
return;
}
// otherwise download to cache
const imageObject = await FileSystem.downloadAsync(
remoteURI,
filesystemURI,
);
safeCall(() => setImgURI(imageObject.uri));
} catch (err) {
console.log('Image loading error:', err);
safeCall(() => setImgURI(remoteURI));
}
};
React.useEffect(() => {
state.mounted = true;
(async () => {
const uri = (props.source as ImageURISource).uri;
if (uri) {
const filesystemURI = await getImageFilesystemKey(uri);
if (imgURI !== uri && imgURI !== filesystemURI) {
await loadImage(filesystemURI, uri);
}
}
})();
return () => {
state.mounted = false;
};
}, [(props.source as ImageURISource).uri]);
let source: ImageProps['source'] = imgURI ? { uri: imgURI } : null;
if (!source && props.source) {
source = props.source;
}
if (props.isBackground) {
return (
<ImageBackground
{...props}
source={source}
>
{props.children}
</ImageBackground>
);
} else {
return (
<Image
{...props}
source={source}
/>
);
}
}