Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ead60db
Add onProgress and onComplete callbacks for `preload` both on Android…
doomsower Aug 29, 2018
5c11dec
Merge branch 'master' into preload_callbacks
doomsower Jan 19, 2019
5f9b91c
Merge remote-tracking branch 'banana/preload_callbacks' into feature/…
Mickagd Mar 26, 2019
179af4c
fix flow
Mickagd Mar 28, 2019
29b01a9
fix: an empty sources array never called onComplete
Elindorath Apr 18, 2019
39d4cd5
Merge pull request #1 from DylanVann/master
Mickagd Jun 19, 2019
4c09121
Merge branch 'master' into feature/preload-callbacks
Mickagd Jun 19, 2019
40cb5b8
fix lint
Mickagd Jun 19, 2019
c86abda
update swebimage
Mickagd Jun 19, 2019
1d93c0d
Merge pull request #2 from DylanVann/master
joan-saum Oct 28, 2019
0f67ddb
Merge branch 'master' into feature/preload-callbacks
Nov 4, 2019
3812d45
Merge remote-tracking branch 'upstream/master' into feature/preload-c…
Aug 18, 2021
6dd7261
fix: revert FastImagePreloaderModule class to FastImageViewModule + a…
Aug 18, 2021
70fe646
fix lint
Aug 18, 2021
7dffb00
fix NativeEventEmitter mock in test
Aug 18, 2021
7dcb4ae
fix NativeEventEmitter mock in test
Aug 18, 2021
d7ea691
turn preloadermanager.js to typescript file
Aug 18, 2021
440ee83
fix lint + add listener to FastImageViewModule.java
Aug 19, 2021
2af79e5
bind context to listeners
Aug 19, 2021
f8d13ec
add SDWebImageDownloader.h import in FFFastImagePreloaderManager.m file
Aug 20, 2021
bbe6c9d
Merge pull request #4 from Sparted/feature/preload-callbacks-fetch-up…
Mickagd Aug 20, 2021
0ee6e1f
Merge branch 'main' into feature/preload-callbacks
Flictuum Jan 25, 2022
4f88f36
Import FastImageViewNativeModule into index file
nicomontanari Feb 14, 2022
a5a45e9
Update FastImageViewNativeModule variable
nicomontanari Jan 16, 2023
1d13dcd
Added animation support & Added fade animation
geroale Mar 6, 2023
519dba7
Added animation support & Added fade animation
geroale Mar 6, 2023
bd8ffd1
Revert "Added animation support & Added fade animation"
geroale Mar 6, 2023
be64a04
Added animation support & Added fade animation
geroale Mar 6, 2023
7a771d5
Update README.md
geroale Mar 6, 2023
f5847b3
Merge remote-tracking branch 'upstream/main'
nicomontanari Jul 17, 2023
fbb6199
Update android/src/main/java/com/dylanvann/fastimage/FastImagePreload…
nicomontanari Oct 12, 2023
242add2
Update preload manager references
nicomontanari Oct 17, 2023
4f70201
Removed fade animation for unchanged URI
andreamorandi Dec 21, 2023
e8bdefd
Fixed package name
andreamorandi Dec 21, 2023
21bd55f
Bumped version
andreamorandi Dec 21, 2023
4a70860
Merge remote-tracking branch 'preload/master'
geroale Oct 31, 2024
2e335cf
Update package.json
geroale Oct 31, 2024
9b0076d
Bumped version
geroale Oct 31, 2024
336baa5
Update FastImageViewWithUrl.java
geroale Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ Headers to load the image with. e.g. `{ Authorization: 'someAuthToken' }`.

---

### `animation?: enum`

- `FastImage.animation.none` **(Default)** - No animation in image loading.
- `FastImage.animation.fade` - Fade in animation in image loading.

---

### `onLoadStart?: () => void`

Called when the image starts to load.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dylanvann.fastimage;

public enum FastImageAnimation {
FADE,
NONE
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class FastImageViewConverter {
put("center", ScaleType.CENTER_INSIDE);
}};

private static final Map<String, FastImageAnimation> FAST_IMAGE_ANIMATION_MAP =
new HashMap<String, FastImageAnimation>() {{
put("fade", FastImageAnimation.FADE);
put("none", FastImageAnimation.NONE);
}};

// Resolve the source uri to a file path that android understands.
static @Nullable
FastImageSource getImageSource(Context context, @Nullable ReadableMap source) {
Expand Down Expand Up @@ -133,6 +139,10 @@ static ScaleType getScaleType(String propValue) {
return getValue("resizeMode", "cover", FAST_IMAGE_RESIZE_MODE_MAP, propValue);
}

static FastImageAnimation getAnimation(String propValue) {
return getValue("animation", "none", FAST_IMAGE_ANIMATION_MAP, propValue);
}

private static <T> T getValue(String propName, String defaultPropValue, Map<String, T> map, String propValue) {
if (propValue == null) propValue = defaultPropValue;
T value = map.get(propValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public void setResizeMode(FastImageViewWithUrl view, String resizeMode) {
view.setScaleType(scaleType);
}

@ReactProp(name = "animation")
public void setAnimation(FastImageViewWithUrl view, String animation) {
final FastImageAnimation animationType = FastImageViewConverter.getAnimation(animation);
view.setAnimation(animationType);
}

@Override
public void onDropViewInstance(@NonNull FastImageViewWithUrl view) {
// This will cancel existing requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.Request;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
Expand All @@ -30,6 +31,7 @@ class FastImageViewWithUrl extends AppCompatImageView {
private boolean mNeedsReload = false;
private ReadableMap mSource = null;
private Drawable mDefaultSource = null;
private FastImageAnimation mAnimation = FastImageAnimation.NONE;

public GlideUrl glideUrl;

Expand All @@ -47,6 +49,10 @@ public void setDefaultSource(@Nullable Drawable source) {
mDefaultSource = source;
}

public void setAnimation(FastImageAnimation animation) {
mAnimation = animation;
}

private boolean isNullOrEmpty(final String url) {
return url == null || url.trim().isEmpty();
}
Expand Down Expand Up @@ -144,6 +150,10 @@ public void onAfterUpdate(
.placeholder(mDefaultSource) // show until loaded
.fallback(mDefaultSource)); // null will not be treated as error

if(mAnimation == FastImageAnimation.FADE) {
builder = builder.transition(DrawableTransitionOptions.withCrossFade());
}

if (key != null)
builder.listener(new FastImageRequestListener(key));

Expand Down
1 change: 1 addition & 0 deletions ios/FastImage/FFFastImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@property (nonatomic, strong) FFFastImageSource *source;
@property (nonatomic, strong) UIImage *defaultSource;
@property (nonatomic, strong) UIColor *imageColor;
@property (nonatomic, assign) NSString *animation;

@end

8 changes: 8 additions & 0 deletions ios/FastImage/FFFastImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ - (void) setResizeMode: (RCTResizeMode)resizeMode {
}
}

- (void)setAnimation:(NSString*)animation {
if(_animation != animation) {
_animation = animation;
if([_animation isEqual: @"fade"])
self.sd_imageTransition = SDWebImageTransition.fadeTransition;
}
}

- (void) setOnFastImageLoadEnd: (RCTDirectEventBlock)onFastImageLoadEnd {
_onFastImageLoadEnd = onFastImageLoadEnd;
if (self.hasCompleted) {
Expand Down
1 change: 1 addition & 0 deletions ios/FastImage/FFFastImageViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ - (FFFastImageView*)view {
RCT_EXPORT_VIEW_PROPERTY(source, FFFastImageSource)
RCT_EXPORT_VIEW_PROPERTY(defaultSource, UIImage)
RCT_EXPORT_VIEW_PROPERTY(resizeMode, RCTResizeMode)
RCT_EXPORT_VIEW_PROPERTY(animation, NSString)
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadStart, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onFastImageProgress, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onFastImageError, RCTDirectEventBlock)
Expand Down
13 changes: 13 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const resizeMode = {
center: 'center',
} as const

export type Animation = 'none' | 'fade'

const animation = {
none: 'none',
fade: 'fade'
} as const

export type Priority = 'low' | 'normal' | 'high'

const priority = {
Expand Down Expand Up @@ -84,6 +91,7 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
source?: Source | ImageRequireSource
defaultSource?: ImageRequireSource
resizeMode?: ResizeMode
animation?: Animation
fallback?: boolean

onLoadStart?(): void
Expand Down Expand Up @@ -167,6 +175,7 @@ function FastImageBase({
children,
// eslint-disable-next-line no-shadow
resizeMode = 'cover',
animation = 'none',
forwardedRef,
...props
}: FastImageProps & { forwardedRef: React.Ref<any> }) {
Expand Down Expand Up @@ -211,6 +220,7 @@ function FastImageBase({
onFastImageError={onError}
onFastImageLoadEnd={onLoadEnd}
resizeMode={resizeMode}
animation={animation}
/>
{children}
</View>
Expand All @@ -229,6 +239,7 @@ FastImageComponent.displayName = 'FastImage'

export interface FastImageStaticProperties {
resizeMode: typeof resizeMode
animation: typeof animation
priority: typeof priority
cacheControl: typeof cacheControl
preload: (sources: Source[]) => void
Expand All @@ -245,6 +256,8 @@ FastImage.cacheControl = cacheControl

FastImage.priority = priority

FastImage.animation = animation

FastImage.preload = (sources: Source[]) =>
NativeModules.FastImageView.preload(sources)

Expand Down