@depup/react-native-fast-image 8.6.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/RNFastImage.podspec +21 -0
- package/android/build.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageCacheControl.java +8 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageGlideModule.java +9 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageOkHttpProgressGlideModule.java +176 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageProgressListener.java +14 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageRequestListener.java +60 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java +112 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewConverter.java +153 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +183 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewModule.java +89 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewPackage.java +25 -0
- package/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java +159 -0
- package/changes.json +5 -0
- package/dist/index.cjs.js +144 -0
- package/dist/index.cjs.js.flow +75 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +137 -0
- package/dist/index.js.flow +75 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/ios/FastImage/FFFastImageSource.h +33 -0
- package/ios/FastImage/FFFastImageSource.m +20 -0
- package/ios/FastImage/FFFastImageView.h +24 -0
- package/ios/FastImage/FFFastImageView.m +244 -0
- package/ios/FastImage/FFFastImageViewManager.h +5 -0
- package/ios/FastImage/FFFastImageViewManager.m +52 -0
- package/ios/FastImage/RCTConvert+FFFastImage.h +9 -0
- package/ios/FastImage/RCTConvert+FFFastImage.m +53 -0
- package/ios/FastImage.xcodeproj/project.pbxproj +479 -0
- package/ios/FastImage.xcodeproj/xcshareddata/xcschemes/FastImage-tvOS.xcscheme +80 -0
- package/package.json +98 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlexStyle, LayoutChangeEvent, ShadowStyleIOS, StyleProp, TransformsStyle, ImageRequireSource, AccessibilityProps, ViewProps, ColorValue } from 'react-native';
|
|
3
|
+
export declare type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center';
|
|
4
|
+
declare const resizeMode: {
|
|
5
|
+
readonly contain: "contain";
|
|
6
|
+
readonly cover: "cover";
|
|
7
|
+
readonly stretch: "stretch";
|
|
8
|
+
readonly center: "center";
|
|
9
|
+
};
|
|
10
|
+
export declare type Priority = 'low' | 'normal' | 'high';
|
|
11
|
+
declare const priority: {
|
|
12
|
+
readonly low: "low";
|
|
13
|
+
readonly normal: "normal";
|
|
14
|
+
readonly high: "high";
|
|
15
|
+
};
|
|
16
|
+
declare type Cache = 'immutable' | 'web' | 'cacheOnly';
|
|
17
|
+
declare const cacheControl: {
|
|
18
|
+
readonly immutable: "immutable";
|
|
19
|
+
readonly web: "web";
|
|
20
|
+
readonly cacheOnly: "cacheOnly";
|
|
21
|
+
};
|
|
22
|
+
export declare type Source = {
|
|
23
|
+
uri?: string;
|
|
24
|
+
headers?: {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
};
|
|
27
|
+
priority?: Priority;
|
|
28
|
+
cache?: Cache;
|
|
29
|
+
};
|
|
30
|
+
export interface OnLoadEvent {
|
|
31
|
+
nativeEvent: {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface OnProgressEvent {
|
|
37
|
+
nativeEvent: {
|
|
38
|
+
loaded: number;
|
|
39
|
+
total: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface ImageStyle extends FlexStyle, TransformsStyle, ShadowStyleIOS {
|
|
43
|
+
backfaceVisibility?: 'visible' | 'hidden';
|
|
44
|
+
borderBottomLeftRadius?: number;
|
|
45
|
+
borderBottomRightRadius?: number;
|
|
46
|
+
backgroundColor?: string;
|
|
47
|
+
borderColor?: string;
|
|
48
|
+
borderWidth?: number;
|
|
49
|
+
borderRadius?: number;
|
|
50
|
+
borderTopLeftRadius?: number;
|
|
51
|
+
borderTopRightRadius?: number;
|
|
52
|
+
overlayColor?: string;
|
|
53
|
+
opacity?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface FastImageProps extends AccessibilityProps, ViewProps {
|
|
56
|
+
source?: Source | ImageRequireSource;
|
|
57
|
+
defaultSource?: ImageRequireSource;
|
|
58
|
+
resizeMode?: ResizeMode;
|
|
59
|
+
fallback?: boolean;
|
|
60
|
+
onLoadStart?(): void;
|
|
61
|
+
onProgress?(event: OnProgressEvent): void;
|
|
62
|
+
onLoad?(event: OnLoadEvent): void;
|
|
63
|
+
onError?(): void;
|
|
64
|
+
onLoadEnd?(): void;
|
|
65
|
+
/**
|
|
66
|
+
* onLayout function
|
|
67
|
+
*
|
|
68
|
+
* Invoked on mount and layout changes with
|
|
69
|
+
*
|
|
70
|
+
* {nativeEvent: { layout: {x, y, width, height}}}.
|
|
71
|
+
*/
|
|
72
|
+
onLayout?: (event: LayoutChangeEvent) => void;
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* Style
|
|
76
|
+
*/
|
|
77
|
+
style?: StyleProp<ImageStyle>;
|
|
78
|
+
/**
|
|
79
|
+
* TintColor
|
|
80
|
+
*
|
|
81
|
+
* If supplied, changes the color of all the non-transparent pixels to the given color.
|
|
82
|
+
*/
|
|
83
|
+
tintColor?: ColorValue;
|
|
84
|
+
/**
|
|
85
|
+
* A unique identifier for this element to be used in UI Automation testing scripts.
|
|
86
|
+
*/
|
|
87
|
+
testID?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Render children within the image.
|
|
90
|
+
*/
|
|
91
|
+
children?: React.ReactNode;
|
|
92
|
+
}
|
|
93
|
+
export interface FastImageStaticProperties {
|
|
94
|
+
resizeMode: typeof resizeMode;
|
|
95
|
+
priority: typeof priority;
|
|
96
|
+
cacheControl: typeof cacheControl;
|
|
97
|
+
preload: (sources: Source[]) => void;
|
|
98
|
+
clearMemoryCache: () => Promise<void>;
|
|
99
|
+
clearDiskCache: () => Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
declare const FastImage: React.ComponentType<FastImageProps> & FastImageStaticProperties;
|
|
102
|
+
export default FastImage;
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
+
import React, { forwardRef, memo } from 'react';
|
|
3
|
+
import { NativeModules, StyleSheet, requireNativeComponent, Image, View, Platform } from 'react-native';
|
|
4
|
+
|
|
5
|
+
const resizeMode = {
|
|
6
|
+
contain: 'contain',
|
|
7
|
+
cover: 'cover',
|
|
8
|
+
stretch: 'stretch',
|
|
9
|
+
center: 'center'
|
|
10
|
+
};
|
|
11
|
+
const priority = {
|
|
12
|
+
low: 'low',
|
|
13
|
+
normal: 'normal',
|
|
14
|
+
high: 'high'
|
|
15
|
+
};
|
|
16
|
+
const cacheControl = {
|
|
17
|
+
// Ignore headers, use uri as cache key, fetch only if not in cache.
|
|
18
|
+
immutable: 'immutable',
|
|
19
|
+
// Respect http headers, no aggressive caching.
|
|
20
|
+
web: 'web',
|
|
21
|
+
// Only load from cache.
|
|
22
|
+
cacheOnly: 'cacheOnly'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const resolveDefaultSource = defaultSource => {
|
|
26
|
+
if (!defaultSource) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (Platform.OS === 'android') {
|
|
31
|
+
// Android receives a URI string, and resolves into a Drawable using RN's methods.
|
|
32
|
+
const resolved = Image.resolveAssetSource(defaultSource);
|
|
33
|
+
|
|
34
|
+
if (resolved) {
|
|
35
|
+
return resolved.uri;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
} // iOS or other number mapped assets
|
|
40
|
+
// In iOS the number is passed, and bridged automatically into a UIImage
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
return defaultSource;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function FastImageBase({
|
|
47
|
+
source,
|
|
48
|
+
defaultSource,
|
|
49
|
+
tintColor,
|
|
50
|
+
onLoadStart,
|
|
51
|
+
onProgress,
|
|
52
|
+
onLoad,
|
|
53
|
+
onError,
|
|
54
|
+
onLoadEnd,
|
|
55
|
+
style,
|
|
56
|
+
fallback,
|
|
57
|
+
children,
|
|
58
|
+
// eslint-disable-next-line no-shadow
|
|
59
|
+
resizeMode = 'cover',
|
|
60
|
+
forwardedRef,
|
|
61
|
+
...props
|
|
62
|
+
}) {
|
|
63
|
+
if (fallback) {
|
|
64
|
+
const cleanedSource = { ...source
|
|
65
|
+
};
|
|
66
|
+
delete cleanedSource.cache;
|
|
67
|
+
const resolvedSource = Image.resolveAssetSource(cleanedSource);
|
|
68
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
69
|
+
style: [styles.imageContainer, style],
|
|
70
|
+
ref: forwardedRef
|
|
71
|
+
}, /*#__PURE__*/React.createElement(Image, _extends({}, props, {
|
|
72
|
+
style: [StyleSheet.absoluteFill, {
|
|
73
|
+
tintColor
|
|
74
|
+
}],
|
|
75
|
+
source: resolvedSource,
|
|
76
|
+
defaultSource: defaultSource,
|
|
77
|
+
onLoadStart: onLoadStart,
|
|
78
|
+
onProgress: onProgress,
|
|
79
|
+
onLoad: onLoad,
|
|
80
|
+
onError: onError,
|
|
81
|
+
onLoadEnd: onLoadEnd,
|
|
82
|
+
resizeMode: resizeMode
|
|
83
|
+
})), children);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const resolvedSource = Image.resolveAssetSource(source);
|
|
87
|
+
const resolvedDefaultSource = resolveDefaultSource(defaultSource);
|
|
88
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
89
|
+
style: [styles.imageContainer, style],
|
|
90
|
+
ref: forwardedRef
|
|
91
|
+
}, /*#__PURE__*/React.createElement(FastImageView, _extends({}, props, {
|
|
92
|
+
tintColor: tintColor,
|
|
93
|
+
style: StyleSheet.absoluteFill,
|
|
94
|
+
source: resolvedSource,
|
|
95
|
+
defaultSource: resolvedDefaultSource,
|
|
96
|
+
onFastImageLoadStart: onLoadStart,
|
|
97
|
+
onFastImageProgress: onProgress,
|
|
98
|
+
onFastImageLoad: onLoad,
|
|
99
|
+
onFastImageError: onError,
|
|
100
|
+
onFastImageLoadEnd: onLoadEnd,
|
|
101
|
+
resizeMode: resizeMode
|
|
102
|
+
})), children);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const FastImageMemo = /*#__PURE__*/memo(FastImageBase);
|
|
106
|
+
const FastImageComponent = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(FastImageMemo, _extends({
|
|
107
|
+
forwardedRef: ref
|
|
108
|
+
}, props)));
|
|
109
|
+
FastImageComponent.displayName = 'FastImage';
|
|
110
|
+
const FastImage = FastImageComponent;
|
|
111
|
+
FastImage.resizeMode = resizeMode;
|
|
112
|
+
FastImage.cacheControl = cacheControl;
|
|
113
|
+
FastImage.priority = priority;
|
|
114
|
+
|
|
115
|
+
FastImage.preload = sources => NativeModules.FastImageView.preload(sources);
|
|
116
|
+
|
|
117
|
+
FastImage.clearMemoryCache = () => NativeModules.FastImageView.clearMemoryCache();
|
|
118
|
+
|
|
119
|
+
FastImage.clearDiskCache = () => NativeModules.FastImageView.clearDiskCache();
|
|
120
|
+
|
|
121
|
+
const styles = StyleSheet.create({
|
|
122
|
+
imageContainer: {
|
|
123
|
+
overflow: 'hidden'
|
|
124
|
+
}
|
|
125
|
+
}); // Types of requireNativeComponent are not correct.
|
|
126
|
+
|
|
127
|
+
const FastImageView = requireNativeComponent('FastImageView', FastImage, {
|
|
128
|
+
nativeOnly: {
|
|
129
|
+
onFastImageLoadStart: true,
|
|
130
|
+
onFastImageProgress: true,
|
|
131
|
+
onFastImageLoad: true,
|
|
132
|
+
onFastImageError: true,
|
|
133
|
+
onFastImageLoadEnd: true
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export default FastImage;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes'
|
|
4
|
+
import type { SyntheticEvent } from 'react-native/Libraries/Types/CoreEventTypes'
|
|
5
|
+
|
|
6
|
+
export type OnLoadEvent = SyntheticEvent<
|
|
7
|
+
$ReadOnly<{
|
|
8
|
+
width: number,
|
|
9
|
+
height: number,
|
|
10
|
+
}>,
|
|
11
|
+
>
|
|
12
|
+
|
|
13
|
+
export type OnProgressEvent = SyntheticEvent<
|
|
14
|
+
$ReadOnly<{|
|
|
15
|
+
loaded: number,
|
|
16
|
+
total: number,
|
|
17
|
+
|}>,
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
export type ResizeMode = $ReadOnly<{|
|
|
21
|
+
contain: 'contain',
|
|
22
|
+
cover: 'cover',
|
|
23
|
+
stretch: 'stretch',
|
|
24
|
+
center: 'center',
|
|
25
|
+
|}>
|
|
26
|
+
|
|
27
|
+
export type Priority = $ReadOnly<{|
|
|
28
|
+
low: 'low',
|
|
29
|
+
normal: 'normal',
|
|
30
|
+
high: 'high',
|
|
31
|
+
|}>
|
|
32
|
+
|
|
33
|
+
export type CacheControl = $ReadOnly<{|
|
|
34
|
+
immutable: 'immutable',
|
|
35
|
+
web: 'web',
|
|
36
|
+
cacheOnly: 'cacheOnly',
|
|
37
|
+
|}>
|
|
38
|
+
|
|
39
|
+
export type ResizeModes = $Values<ResizeMode>
|
|
40
|
+
export type Priorities = $Values<Priority>
|
|
41
|
+
export type CacheControls = $Values<CacheControl>
|
|
42
|
+
|
|
43
|
+
export type PreloadFn = (sources: Array<FastImageSource>) => void
|
|
44
|
+
export type FastImageSource = {
|
|
45
|
+
uri?: string,
|
|
46
|
+
headers?: Object,
|
|
47
|
+
priority?: Priorities,
|
|
48
|
+
cache?: CacheControls,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type FastImageProps = $ReadOnly<{|
|
|
52
|
+
...ViewProps,
|
|
53
|
+
onError?: ?() => void,
|
|
54
|
+
onLoad?: ?(event: OnLoadEvent) => void,
|
|
55
|
+
onLoadEnd?: ?() => void,
|
|
56
|
+
onLoadStart?: ?() => void,
|
|
57
|
+
onProgress?: ?(event: OnProgressEvent) => void,
|
|
58
|
+
|
|
59
|
+
source?: ?(FastImageSource | number),
|
|
60
|
+
defaultSource?: ?number,
|
|
61
|
+
|
|
62
|
+
tintColor?: number | string,
|
|
63
|
+
resizeMode?: ?ResizeModes,
|
|
64
|
+
fallback?: ?boolean,
|
|
65
|
+
testID?: ?string,
|
|
66
|
+
|}>
|
|
67
|
+
|
|
68
|
+
declare export default class FastImage extends React$Component<FastImageProps> {
|
|
69
|
+
static resizeMode: ResizeMode;
|
|
70
|
+
static priority: Priority;
|
|
71
|
+
static cacheControl: CacheControl;
|
|
72
|
+
static preload: PreloadFn;
|
|
73
|
+
static clearMemoryCache: () => Promise<void>;
|
|
74
|
+
static clearDiskCache: () => Promise<void>;
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <UIKit/UIKit.h>
|
|
3
|
+
|
|
4
|
+
typedef NS_ENUM(NSInteger, FFFPriority) {
|
|
5
|
+
FFFPriorityLow,
|
|
6
|
+
FFFPriorityNormal,
|
|
7
|
+
FFFPriorityHigh
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
typedef NS_ENUM(NSInteger, FFFCacheControl) {
|
|
11
|
+
FFFCacheControlImmutable,
|
|
12
|
+
FFFCacheControlWeb,
|
|
13
|
+
FFFCacheControlCacheOnly
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Object containing an image uri and metadata.
|
|
17
|
+
@interface FFFastImageSource : NSObject
|
|
18
|
+
|
|
19
|
+
// uri for image, or base64
|
|
20
|
+
@property (nonatomic) NSURL* url;
|
|
21
|
+
// priority for image request
|
|
22
|
+
@property (nonatomic) FFFPriority priority;
|
|
23
|
+
// headers for the image request
|
|
24
|
+
@property (nonatomic) NSDictionary *headers;
|
|
25
|
+
// cache control mode
|
|
26
|
+
@property (nonatomic) FFFCacheControl cacheControl;
|
|
27
|
+
|
|
28
|
+
- (instancetype)initWithURL:(NSURL *)url
|
|
29
|
+
priority:(FFFPriority)priority
|
|
30
|
+
headers:(NSDictionary *)headers
|
|
31
|
+
cacheControl:(FFFCacheControl)cacheControl;
|
|
32
|
+
|
|
33
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import "FFFastImageSource.h"
|
|
2
|
+
|
|
3
|
+
@implementation FFFastImageSource
|
|
4
|
+
|
|
5
|
+
- (instancetype)initWithURL:(NSURL *)url
|
|
6
|
+
priority:(FFFPriority)priority
|
|
7
|
+
headers:(NSDictionary *)headers
|
|
8
|
+
cacheControl:(FFFCacheControl)cacheControl
|
|
9
|
+
{
|
|
10
|
+
self = [super init];
|
|
11
|
+
if (self) {
|
|
12
|
+
_url = url;
|
|
13
|
+
_priority = priority;
|
|
14
|
+
_headers = headers;
|
|
15
|
+
_cacheControl = cacheControl;
|
|
16
|
+
}
|
|
17
|
+
return self;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
#import <SDWebImage/SDAnimatedImageView+WebCache.h>
|
|
4
|
+
#import <SDWebImage/SDWebImageDownloader.h>
|
|
5
|
+
|
|
6
|
+
#import <React/RCTComponent.h>
|
|
7
|
+
#import <React/RCTResizeMode.h>
|
|
8
|
+
|
|
9
|
+
#import "FFFastImageSource.h"
|
|
10
|
+
|
|
11
|
+
@interface FFFastImageView : SDAnimatedImageView
|
|
12
|
+
|
|
13
|
+
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoadStart;
|
|
14
|
+
@property (nonatomic, copy) RCTDirectEventBlock onFastImageProgress;
|
|
15
|
+
@property (nonatomic, copy) RCTDirectEventBlock onFastImageError;
|
|
16
|
+
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoad;
|
|
17
|
+
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoadEnd;
|
|
18
|
+
@property (nonatomic, assign) RCTResizeMode resizeMode;
|
|
19
|
+
@property (nonatomic, strong) FFFastImageSource *source;
|
|
20
|
+
@property (nonatomic, strong) UIImage *defaultSource;
|
|
21
|
+
@property (nonatomic, strong) UIColor *imageColor;
|
|
22
|
+
|
|
23
|
+
@end
|
|
24
|
+
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#import "FFFastImageView.h"
|
|
2
|
+
#import <SDWebImage/UIImage+MultiFormat.h>
|
|
3
|
+
#import <SDWebImage/UIView+WebCache.h>
|
|
4
|
+
|
|
5
|
+
@interface FFFastImageView ()
|
|
6
|
+
|
|
7
|
+
@property(nonatomic, assign) BOOL hasSentOnLoadStart;
|
|
8
|
+
@property(nonatomic, assign) BOOL hasCompleted;
|
|
9
|
+
@property(nonatomic, assign) BOOL hasErrored;
|
|
10
|
+
// Whether the latest change of props requires the image to be reloaded
|
|
11
|
+
@property(nonatomic, assign) BOOL needsReload;
|
|
12
|
+
|
|
13
|
+
@property(nonatomic, strong) NSDictionary* onLoadEvent;
|
|
14
|
+
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
@implementation FFFastImageView
|
|
18
|
+
|
|
19
|
+
- (id) init {
|
|
20
|
+
self = [super init];
|
|
21
|
+
self.resizeMode = RCTResizeModeCover;
|
|
22
|
+
self.clipsToBounds = YES;
|
|
23
|
+
return self;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (void) setResizeMode: (RCTResizeMode)resizeMode {
|
|
27
|
+
if (_resizeMode != resizeMode) {
|
|
28
|
+
_resizeMode = resizeMode;
|
|
29
|
+
self.contentMode = (UIViewContentMode) resizeMode;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (void) setOnFastImageLoadEnd: (RCTDirectEventBlock)onFastImageLoadEnd {
|
|
34
|
+
_onFastImageLoadEnd = onFastImageLoadEnd;
|
|
35
|
+
if (self.hasCompleted) {
|
|
36
|
+
_onFastImageLoadEnd(@{});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- (void) setOnFastImageLoad: (RCTDirectEventBlock)onFastImageLoad {
|
|
41
|
+
_onFastImageLoad = onFastImageLoad;
|
|
42
|
+
if (self.hasCompleted) {
|
|
43
|
+
_onFastImageLoad(self.onLoadEvent);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void) setOnFastImageError: (RCTDirectEventBlock)onFastImageError {
|
|
48
|
+
_onFastImageError = onFastImageError;
|
|
49
|
+
if (self.hasErrored) {
|
|
50
|
+
_onFastImageError(@{});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void) setOnFastImageLoadStart: (RCTDirectEventBlock)onFastImageLoadStart {
|
|
55
|
+
if (_source && !self.hasSentOnLoadStart) {
|
|
56
|
+
_onFastImageLoadStart = onFastImageLoadStart;
|
|
57
|
+
onFastImageLoadStart(@{});
|
|
58
|
+
self.hasSentOnLoadStart = YES;
|
|
59
|
+
} else {
|
|
60
|
+
_onFastImageLoadStart = onFastImageLoadStart;
|
|
61
|
+
self.hasSentOnLoadStart = NO;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void) setImageColor: (UIColor*)imageColor {
|
|
66
|
+
if (imageColor != nil) {
|
|
67
|
+
_imageColor = imageColor;
|
|
68
|
+
if (super.image) {
|
|
69
|
+
super.image = [self makeImage: super.image withTint: self.imageColor];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
- (UIImage*) makeImage: (UIImage*)image withTint: (UIColor*)color {
|
|
75
|
+
UIImage* newImage = [image imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];
|
|
76
|
+
UIGraphicsBeginImageContextWithOptions(image.size, NO, newImage.scale);
|
|
77
|
+
[color set];
|
|
78
|
+
[newImage drawInRect: CGRectMake(0, 0, image.size.width, newImage.size.height)];
|
|
79
|
+
newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
80
|
+
UIGraphicsEndImageContext();
|
|
81
|
+
return newImage;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
- (void) setImage: (UIImage*)image {
|
|
85
|
+
if (self.imageColor != nil) {
|
|
86
|
+
super.image = [self makeImage: image withTint: self.imageColor];
|
|
87
|
+
} else {
|
|
88
|
+
super.image = image;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
- (void) sendOnLoad: (UIImage*)image {
|
|
93
|
+
self.onLoadEvent = @{
|
|
94
|
+
@"width": [NSNumber numberWithDouble: image.size.width],
|
|
95
|
+
@"height": [NSNumber numberWithDouble: image.size.height]
|
|
96
|
+
};
|
|
97
|
+
if (self.onFastImageLoad) {
|
|
98
|
+
self.onFastImageLoad(self.onLoadEvent);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
- (void) setSource: (FFFastImageSource*)source {
|
|
103
|
+
if (_source != source) {
|
|
104
|
+
_source = source;
|
|
105
|
+
_needsReload = YES;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (void) setDefaultSource: (UIImage*)defaultSource {
|
|
110
|
+
if (_defaultSource != defaultSource) {
|
|
111
|
+
_defaultSource = defaultSource;
|
|
112
|
+
_needsReload = YES;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
- (void) didSetProps: (NSArray<NSString*>*)changedProps {
|
|
117
|
+
if (_needsReload) {
|
|
118
|
+
[self reloadImage];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
- (void) reloadImage {
|
|
123
|
+
_needsReload = NO;
|
|
124
|
+
|
|
125
|
+
if (_source) {
|
|
126
|
+
// Load base64 images.
|
|
127
|
+
NSString* url = [_source.url absoluteString];
|
|
128
|
+
if (url && [url hasPrefix: @"data:image"]) {
|
|
129
|
+
if (self.onFastImageLoadStart) {
|
|
130
|
+
self.onFastImageLoadStart(@{});
|
|
131
|
+
self.hasSentOnLoadStart = YES;
|
|
132
|
+
} else {
|
|
133
|
+
self.hasSentOnLoadStart = NO;
|
|
134
|
+
}
|
|
135
|
+
// Use SDWebImage API to support external format like WebP images
|
|
136
|
+
UIImage* image = [UIImage sd_imageWithData: [NSData dataWithContentsOfURL: _source.url]];
|
|
137
|
+
[self setImage: image];
|
|
138
|
+
if (self.onFastImageProgress) {
|
|
139
|
+
self.onFastImageProgress(@{
|
|
140
|
+
@"loaded": @(1),
|
|
141
|
+
@"total": @(1)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
self.hasCompleted = YES;
|
|
145
|
+
[self sendOnLoad: image];
|
|
146
|
+
|
|
147
|
+
if (self.onFastImageLoadEnd) {
|
|
148
|
+
self.onFastImageLoadEnd(@{});
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Set headers.
|
|
154
|
+
NSDictionary* headers = _source.headers;
|
|
155
|
+
SDWebImageDownloaderRequestModifier* requestModifier = [SDWebImageDownloaderRequestModifier requestModifierWithBlock: ^NSURLRequest* _Nullable (NSURLRequest* _Nonnull request) {
|
|
156
|
+
NSMutableURLRequest* mutableRequest = [request mutableCopy];
|
|
157
|
+
for (NSString* header in headers) {
|
|
158
|
+
NSString* value = headers[header];
|
|
159
|
+
[mutableRequest setValue: value forHTTPHeaderField: header];
|
|
160
|
+
}
|
|
161
|
+
return [mutableRequest copy];
|
|
162
|
+
}];
|
|
163
|
+
SDWebImageContext* context = @{SDWebImageContextDownloadRequestModifier: requestModifier};
|
|
164
|
+
|
|
165
|
+
// Set priority.
|
|
166
|
+
SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageHandleCookies;
|
|
167
|
+
switch (_source.priority) {
|
|
168
|
+
case FFFPriorityLow:
|
|
169
|
+
options |= SDWebImageLowPriority;
|
|
170
|
+
break;
|
|
171
|
+
case FFFPriorityNormal:
|
|
172
|
+
// Priority is normal by default.
|
|
173
|
+
break;
|
|
174
|
+
case FFFPriorityHigh:
|
|
175
|
+
options |= SDWebImageHighPriority;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
switch (_source.cacheControl) {
|
|
180
|
+
case FFFCacheControlWeb:
|
|
181
|
+
options |= SDWebImageRefreshCached;
|
|
182
|
+
break;
|
|
183
|
+
case FFFCacheControlCacheOnly:
|
|
184
|
+
options |= SDWebImageFromCacheOnly;
|
|
185
|
+
break;
|
|
186
|
+
case FFFCacheControlImmutable:
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (self.onFastImageLoadStart) {
|
|
191
|
+
self.onFastImageLoadStart(@{});
|
|
192
|
+
self.hasSentOnLoadStart = YES;
|
|
193
|
+
} else {
|
|
194
|
+
self.hasSentOnLoadStart = NO;
|
|
195
|
+
}
|
|
196
|
+
self.hasCompleted = NO;
|
|
197
|
+
self.hasErrored = NO;
|
|
198
|
+
|
|
199
|
+
[self downloadImage: _source options: options context: context];
|
|
200
|
+
} else if (_defaultSource) {
|
|
201
|
+
[self setImage: _defaultSource];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
- (void) downloadImage: (FFFastImageSource*)source options: (SDWebImageOptions)options context: (SDWebImageContext*)context {
|
|
206
|
+
__weak typeof(self) weakSelf = self; // Always use a weak reference to self in blocks
|
|
207
|
+
[self sd_setImageWithURL: _source.url
|
|
208
|
+
placeholderImage: _defaultSource
|
|
209
|
+
options: options
|
|
210
|
+
context: context
|
|
211
|
+
progress: ^(NSInteger receivedSize, NSInteger expectedSize, NSURL* _Nullable targetURL) {
|
|
212
|
+
if (weakSelf.onFastImageProgress) {
|
|
213
|
+
weakSelf.onFastImageProgress(@{
|
|
214
|
+
@"loaded": @(receivedSize),
|
|
215
|
+
@"total": @(expectedSize)
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
} completed: ^(UIImage* _Nullable image,
|
|
219
|
+
NSError* _Nullable error,
|
|
220
|
+
SDImageCacheType cacheType,
|
|
221
|
+
NSURL* _Nullable imageURL) {
|
|
222
|
+
if (error) {
|
|
223
|
+
weakSelf.hasErrored = YES;
|
|
224
|
+
if (weakSelf.onFastImageError) {
|
|
225
|
+
weakSelf.onFastImageError(@{});
|
|
226
|
+
}
|
|
227
|
+
if (weakSelf.onFastImageLoadEnd) {
|
|
228
|
+
weakSelf.onFastImageLoadEnd(@{});
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
weakSelf.hasCompleted = YES;
|
|
232
|
+
[weakSelf sendOnLoad: image];
|
|
233
|
+
if (weakSelf.onFastImageLoadEnd) {
|
|
234
|
+
weakSelf.onFastImageLoadEnd(@{});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
- (void) dealloc {
|
|
241
|
+
[self sd_cancelCurrentImageLoad];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@end
|