Được TopGit lập chỉ mục từ metadata GitHub: mrousavy/react-native-nitro-image có 632 sao, viết chủ yếu bằng TypeScript. 🖼️ A superfast in-memory Image type and view component for React Native, built with Nitro!
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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!
mrousavy/react-native-nitro-image thuộc nhóm Image Tools trên TopGit, cùng 13 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về mrousavy/react-native-nitro-image ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/mrousavy/react-native-nitro-image là nguồn chính thức.
mrousavy/react-native-nitro-image có bao nhiêu sao?
mrousavy/react-native-nitro-image có 632 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/mrousavy/react-native-nitro-image. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
mrousavy/react-native-nitro-image có những chủ đề gì?
mrousavy/react-native-nitro-image còn đang phát triển không?
Commit gần nhất trên mrousavy/react-native-nitro-image là 10 ngày trước (theo timestamp GitHub). Repo có 33 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
mrousavy/react-native-nitro-image viết bằng ngôn ngữ gì?
mrousavy/react-native-nitro-image chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao mrousavy/react-native-nitro-image được xếp vào nhóm Image Tools?
TopGit xếp mrousavy/react-native-nitro-image vào nhóm Image Tools dựa trên GitHub topics và mô tả của repo (gắn thẻ: "crop", "download", "fast"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.