On GitHub, mrousavy/react-native-nitro-image has picked up 632 stars, Image Tools, TypeScript. πΌοΈ A superfast in-memory Image type and view component for React Native, built with Nitro!
Snapshot summary built from the project's own GitHub metadata β there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then β see the READ ME tab for the original README in full.
npm i react-native-nitro-image
npm i react-native-nitro-modules
cd ios && pod install
[!NOTE]
Since NitroImage is built with Nitro Views, it requires the new architecture to be enabled.
Web Images
To keep NitroImage super lightweight, it does not ship a web image loader and caching system.
If you want to load images from the web, install react-native-nitro-web-image as well:
npm i react-native-nitro-web-image
cd ios && pod install
Then, since SDWebImage does not enable modular headers for static linkage, you need to enable those yourself in your app's Podfile:
target 'β¦' do
config = use_native_modules!
# Add this line:
pod 'SDWebImage', :modular_headers => true
Usage
Creating Images
The simplest way to load an Image is to use the exported loadImage(β¦) method:
[!NOTE]
Local File APIs (filePath: ...) use filesystem paths, not file:// URLs. To load a local file with the Web Loader, pass it to url: ... with a file:// prefix.
If you know what Images are going to be rendered soon, you can pre-load them using the preload(...) API:
WebImages.preload(profilePictureLargeUrl)
require(β¦)
A React Native require(β¦) returns a resource-ID. In debug, resources are streamed over Metro (localhost://β¦), while in release, they are embedded in the resources bundle.
NitroImage wraps those APIs so you can just pass a require(β¦) to useImage(β¦), useImageLoader(β¦), or <NitroImage /> directly:
const image = useImage(require('./image.png'))
RawPixelData (ArrayBuffer)
The Image type can be converted to- and from- an ArrayBuffer, which gives you access to the raw pixel data in an RGB format:
When saving to an explicit path, the format argument controls the encoded bytes. The path should still use a matching extension so other APIs can identify the file type:
The <NitroImage /> view is a React Native view that allows you to render Image - either asynchronously (by wrapping ImageLoaders), or synchronously (by passing Image instances directly):
The <NativeNitroImage /> view is the actual native Nitro View component for rendering an Image instance. It is recommended to use abstractions like <NitroImage /> instead of the actual native component. However if you need to use the native component instead, it is still exposed:
This will now resize the height dimension to match the same aspect ratio as the image - in this case it will be 1:1 since the image is 400x400.
If the image is 400x200, the height of the view will be half of the width of the view, i.e. a 0.5 aspect ratio.
ThumbHash
A ThumbHash is a short binary (or base64 string) representation of a blurry image.
Since it is a very small buffer (or base64 string), it can be added to a payload (like a user object in your database) to immediately display an image placeholder while the actual image loads.
Usage Example
For example, your users database could have a users.profile_picture_url field which you use to asynchronously load the web Image, and a users.profile_picture_thumbhash field which contains the ThumbHash buffer (or base64 string) which you can display on-device immediately.
Everytime you upload a new profile picture for the user, you should encode the image to a new ThumbHash again and update the users.profile_picture_thumbhash field. This should ideally happen on your backend, but can also be performed on-device if needed.
ThumbHash (ArrayBuffer) <> Image
NitroImage supports conversion from- and to- ThumbHash representations out of the box.
For performance reasons, a ThumbHash is represented as an ArrayBuffer.
Using the native Image type in a third-party library
To use the native Image type in your library (e.g. in a Camera library), you need to follow these steps:
Add the dependency on react-native-nitro-image
JS: Add react-native-nitro-image to peerDependencies and devDependencies
Android: Add :react-native-nitro-image to your build.gradle's dependencies, and react-native-nitro-image::NitroImage to your CMake's dependencies (it's a prefab)
iOS: Add NitroImage to your *.podspec's dependencies
In your Nitro specs (*.nitro.ts), just import Image from 'react-native-nitro-image' and use it as a type
In your native implementation, you can either;
Implement HybridImageSpec, HybridImageLoaderSpec or HybridImageViewSpec with your custom implementation, e.g. to create a Image implementation that doesn't use UIImage but instead uses CGImage, or an AVPhoto
Use the HybridImageSpec, HybridImageLoaderSpec or HybridImageViewSpec types. You can either use them abstract (with all the methods that are also exposed to JS), or by downcasting them to a specific type - all of them follow a protocol like NativeImage:
class HybridCustom: HybridCustomSpec {
func doSomething(image: any HybridImageSpec) throws {
guard let image = image as? NativeImage else { return }
let uiImage = image.uiImage
// ...
}
}
Done! π Now you can benefit from a common, shared Image type - e.g. your Camera library can directly return an Image instance in takePhoto(), which can be instantly rendered using <NitroImage /> - no more file I/O!
How active is development on mrousavy/react-native-nitro-image?
The most recent commit recorded on mrousavy/react-native-nitro-image was 8 days ago, based on the GitHub push timestamp. The repository has 33 forks β one of the better signals of community interest.
How many stars does mrousavy/react-native-nitro-image have?
mrousavy/react-native-nitro-image has 632 GitHub stars β refresh the page for the live number, or check github.com/mrousavy/react-native-nitro-image. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Image Tools space?
mrousavy/react-native-nitro-image is tracked by TopGit under the Image Tools category, alongside 13 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is mrousavy/react-native-nitro-image written in?
mrousavy/react-native-nitro-image is written primarily in TypeScript. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is mrousavy/react-native-nitro-image associated with?
Where do I read more about mrousavy/react-native-nitro-image?
This TopGit page is a snapshot β the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/mrousavy/react-native-nitro-image is the definitive source.
Why is mrousavy/react-native-nitro-image categorized under Image Tools?
TopGit places mrousavy/react-native-nitro-image in the Image Tools category based on its GitHub topics and description (tagged: "crop", "download", "fast"). Categories are assigned from real repository metadata, not editorial guesswork.