Example usage for com.facebook.react.views.image ImageLoadEvent ImageLoadEvent

List of usage examples for com.facebook.react.views.image ImageLoadEvent ImageLoadEvent

Introduction

In this page you can find the example usage for com.facebook.react.views.image ImageLoadEvent ImageLoadEvent.

Prototype

public ImageLoadEvent(int viewId, @ImageEventType int eventType, String imageUri) 

Source Link

Usage

From source file:com.reactImageWand.RNImageWand.java

License:Open Source License

public void setShouldNotifyLoadEvents(boolean shouldNotify) {
    if (!shouldNotify) {
        mControllerListener = null;/*from   w  w  w .j  a va2  s .  c  o  m*/
    } else {
        final EventDispatcher mEventDispatcher = ((ReactContext) getContext())
                .getNativeModule(UIManagerModule.class).getEventDispatcher();

        mControllerListener = new BaseControllerListener<ImageInfo>() {
            @Override
            public void onSubmit(String id, Object callerContext) {
                mEventDispatcher.dispatchEvent(
                        new ImageLoadEvent(getId(), SystemClock.uptimeMillis(), ImageLoadEvent.ON_LOAD_START));
            }

            @Override
            public void onFinalImageSet(String id, @Nullable final ImageInfo imageInfo,
                    @Nullable Animatable animatable) {
                if (imageInfo != null) {
                    onImageInfo(imageInfo.getWidth(), imageInfo.getHeight());
                    mEventDispatcher.dispatchEvent(new ImageLoadEvent(getId(), SystemClock.uptimeMillis(),
                            ImageLoadEvent.ON_LOAD_END));
                    mEventDispatcher.dispatchEvent(
                            new ImageLoadEvent(getId(), SystemClock.uptimeMillis(), ImageLoadEvent.ON_LOAD));
                }
            }

            @Override
            public void onFailure(String id, Throwable throwable) {
                mEventDispatcher.dispatchEvent(
                        new ImageLoadEvent(getId(), SystemClock.uptimeMillis(), ImageLoadEvent.ON_LOAD_END));
            }
        };
    }

    mIsDirty = true;
}