-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Adds support for the `onProgress` event on `Image`, for Android. Since Fresco does not provide a progress listener on `ControllerListener`, this uses a forwarding progress indicator `Drawable` to pass along values from `onLevelChange`. Caveat: The ratio between `loaded` and `total` can be used, but `total` is currently always 10000. It seems that Fresco does not currently expose the content length from the network response headers. Changelog: [Android][Added] - Adds support for the `onProgress` event on `Image` Reviewed By: mdvacca Differential Revision: D22029915 fbshipit-source-id: 66174b55ed01e1a059c080e2b14415e7d268bc5c
- Loading branch information
1 parent
74ab8f6
commit fa0e6f8
Showing
5 changed files
with
179 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageDownloadListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.views.image; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.ColorFilter; | ||
import android.graphics.PixelFormat; | ||
import android.graphics.drawable.Animatable; | ||
import android.graphics.drawable.Drawable; | ||
import com.facebook.drawee.controller.ControllerListener; | ||
import com.facebook.drawee.drawable.ForwardingDrawable; | ||
import javax.annotation.Nullable; | ||
|
||
public class ReactImageDownloadListener<INFO> extends ForwardingDrawable | ||
implements ControllerListener<INFO> { | ||
|
||
private static final int MAX_LEVEL = 10000; | ||
|
||
public ReactImageDownloadListener() { | ||
super(new EmptyDrawable()); | ||
} | ||
|
||
public void onProgressChange(int loaded, int total) {} | ||
|
||
@Override | ||
protected boolean onLevelChange(int level) { | ||
onProgressChange(level, MAX_LEVEL); | ||
return super.onLevelChange(level); | ||
} | ||
|
||
@Override | ||
public void onSubmit(String id, Object callerContext) {} | ||
|
||
@Override | ||
public void onFinalImageSet( | ||
String id, @Nullable INFO imageInfo, @Nullable Animatable animatable) {} | ||
|
||
@Override | ||
public void onIntermediateImageSet(String id, @Nullable INFO imageInfo) {} | ||
|
||
@Override | ||
public void onIntermediateImageFailed(String id, Throwable throwable) {} | ||
|
||
@Override | ||
public void onFailure(String id, Throwable throwable) {} | ||
|
||
@Override | ||
public void onRelease(String id) {} | ||
|
||
/** A {@link Drawable} that renders nothing. */ | ||
private static final class EmptyDrawable extends Drawable { | ||
|
||
@Override | ||
public void draw(Canvas canvas) { | ||
// Do nothing. | ||
} | ||
|
||
@Override | ||
public void setAlpha(int alpha) { | ||
// Do nothing. | ||
} | ||
|
||
@Override | ||
public void setColorFilter(ColorFilter colorFilter) { | ||
// Do nothing. | ||
} | ||
|
||
@Override | ||
public int getOpacity() { | ||
return PixelFormat.OPAQUE; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.