How to disable image fade in effect in React Native? How to disable image fade in effect in React Native? reactjs reactjs

How to disable image fade in effect in React Native?


Just set fadeDuration={0} to Image component, this is not documented

You can check here for more information


I managed to prevent the fade animation by wrapping my <Image /> with a custom ViewGroupManager and setting ReactImageView.mFadeDuration to zero with reflection before the Image is added to the custom ViewGroup.Edit: But this adds a noticeable delay when displaying the image :( There's actually no delay.

Something like this:

public class NoFadeImageWrapper extends ViewGroup {    public NoFadeImageWrapper(Context context) {        super(context);    }    @Override    public void onViewAdded(View child) {        if (child instanceof ReactImageView) {            ((ReactImageView) child).setFadeDuration(0);            ReflectionUtils.setField(child, "mIsDirty", true);        }        super.onViewAdded(child);    }}

ReflectionUtils.setField implementation:

public class ReflectionUtils {    public static void setField(Object obj, String name, Object value) {        try {            Field field = getField(obj.getClass(), name);            if (field == null) {                return;            }            field.setAccessible(true);            field.set(obj, value);        } catch (Exception e) {            e.printStackTrace();        }    }}