-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Option To Resize Images On Android #401
base: main
Are you sure you want to change the base?
Conversation
Add suport for resizeImageAndroid prop
Fix typo in flow type for resizeImageAndroid
@@ -114,6 +117,13 @@ public void setResizeMode(FastImageViewWithUrl view, String resizeMode) { | |||
view.setScaleType(scaleType); | |||
} | |||
|
|||
@ReactProp(name = "resizeImageAndroid") | |||
public void setImageResize(FastImageViewWithUrl view, ReadableMap imageSizeOverride) { | |||
// Re-run Glide with width and height override values set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to put imageResize
into source, so we don't have to rerun Glide? It would be beneficial for iOS as well.
Any way I can help with getting this PR merged in? We are currently maintaining a fork with this solution implemented in the latest FastImage release and I'd prefer if I could just use the original and drop the fork 😁 |
I believe Glide does downsampling for us without any extra config.
From https://futurestud.io/tutorials/glide-image-resizing-scaling |
I am also doing as @madandrija states by maintaining a forked version with this pr implemented. I am not a expert with Glide but I did notice a huge difference when I implemented this solution (pretty much night and day). Really think it would be helpful for other android users to have at their disposal. |
You may be getting better performance because the quality of your rendered images is less if you are not accounting for DPI. Assuming Glide's auto downsampling works that's the reason I would guess you're seeing better performance. We could try to create a reproduction of this issue to check if that's the case, or if the auto sampling based on the view size is not working for some reason. |
We've updated our fork to the latest version and still we need the fork in order to speed up image loading (e.g. when scrolling through a FlatList, w/o the fork there were sometimes "blanks" until images loaded, whereas with the fork, everything was running smoothly), and I have two examples of images used. Regarding repro, still thinking about how to set up a minimal example, either on GitHub or in Snack. |
As discussed in issue #285, there are some cases where very large, down-sampled images can create performance issues on Android due to the entire image being loaded in the device's RAM.
There is an option in React Native's default
<Image />
component which allows you to specifyresizeMethod="resize"
. This uses Facebook's Fresco library to automatically downsample the image itself before being loaded into the devices memory, but sincereact-native-fast-image
uses Glide - there appears to be nothing similar available.The solution I came up with was to offer the ability to manually down sample the image size before it's loaded into the memory using a new prop called
resizeImageAndroid
. It uses Glide's.override()
method to achieve this.The only caveat is that you must know the exact image size, but it's nice to at least have this option if it's critical for the performance of large images on Android.
Example Usage: