@nativescript-community/ui-image 4.3.41 → 4.5.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/CHANGELOG.md +12 -0
- package/README.md +9 -2
- package/blueprint.md +9 -2
- package/index-common.d.ts +5 -2
- package/index-common.js +11 -3
- package/index.android.js +19 -10
- package/index.d.ts +5 -0
- package/index.ios.js +41 -5
- package/package.json +2 -2
- package/platforms/android/include.gradle +1 -0
- package/platforms/android/java/com/nativescript/image/DraweeView.java +5 -3
- package/platforms/android/java/com/nativescript/image/NetworkImageRequest.java +55 -0
- package/platforms/android/java/com/nativescript/image/OkHttpNetworkFetcher.java +56 -0
- package/platforms/android/native-api-usage.json +4 -0
- package/platforms/android/ui_image.aar +0 -0
- package/typings/android.d.ts +3 -0
- package/typings/ios.d.ts +2 -0
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [4.5.0](https://github.com/nativescript-community/ui-image/compare/v4.4.0...v4.5.0) (2024-04-23)
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* **image:** headers property support. Thanks to @Logikgate ([8704ee7](https://github.com/nativescript-community/ui-image/commit/8704ee7dcd17518f1e330b57103eab23b514aac2))
|
11
|
+
|
12
|
+
## [4.4.0](https://github.com/nativescript-community/ui-image/compare/v4.3.41...v4.4.0) (2024-04-23)
|
13
|
+
|
14
|
+
### Features
|
15
|
+
|
16
|
+
* **image:** add progress indicator for ios ([11b894a](https://github.com/nativescript-community/ui-image/commit/11b894a787afae629ba53038bbbcad4e1a48fc54))
|
17
|
+
|
6
18
|
## [4.3.41](https://github.com/nativescript-community/ui-image/compare/v4.3.40...v4.3.41) (2024-04-23)
|
7
19
|
|
8
20
|
### Bug Fixes
|
package/README.md
CHANGED
@@ -439,6 +439,13 @@ Number value used as the downsampled width of the imageModule drawable.
|
|
439
439
|
<@nativescript-community/ui-image:Img decodeHeight="100"/>
|
440
440
|
```
|
441
441
|
|
442
|
+
- **headers**
|
443
|
+
|
444
|
+
Object that defines custom request headers to be sent with the image download request.
|
445
|
+
|
446
|
+
```xml
|
447
|
+
<@nativescript-community/ui-image:Img headers="{Authorization: 'bearer abcdefghijk'}"/>
|
448
|
+
```
|
442
449
|
|
443
450
|
- **progressiveRenderingEnabled**
|
444
451
|
|
@@ -448,7 +455,7 @@ Boolean value used for enabling or disabling the streaming of progressive JPEG i
|
|
448
455
|
<@nativescript-community/ui-image:Img progressiveRenderingEnabled="true"/>
|
449
456
|
```
|
450
457
|
|
451
|
-
- **showProgressBar**
|
458
|
+
- **showProgressBar**
|
452
459
|
|
453
460
|
Boolean value used for showing or hiding the progress bar.
|
454
461
|
|
@@ -456,7 +463,7 @@ Boolean value used for showing or hiding the progress bar.
|
|
456
463
|
<@nativescript-community/ui-image:Img showProgressBar="true"/>
|
457
464
|
```
|
458
465
|
|
459
|
-
- **progressBarColor**
|
466
|
+
- **progressBarColor**
|
460
467
|
|
461
468
|
String value used for setting the color of the progress bar. You can set it to hex values ("*#FF0000*") and/or predefined colors ("*green*").
|
462
469
|
|
package/blueprint.md
CHANGED
@@ -372,6 +372,13 @@ Number value used as the downsampled width of the imageModule drawable.
|
|
372
372
|
<@nativescript-community/ui-image:Img decodeHeight="100"/>
|
373
373
|
```
|
374
374
|
|
375
|
+
- **headers**
|
376
|
+
|
377
|
+
Object that defines custom request headers to be sent with the image download request.
|
378
|
+
|
379
|
+
```xml
|
380
|
+
<@nativescript-community/ui-image:Img headers="{Authorization: 'bearer abcdefghijk'}"/>
|
381
|
+
```
|
375
382
|
|
376
383
|
- **progressiveRenderingEnabled**
|
377
384
|
|
@@ -381,7 +388,7 @@ Boolean value used for enabling or disabling the streaming of progressive JPEG i
|
|
381
388
|
<@nativescript-community/ui-image:Img progressiveRenderingEnabled="true"/>
|
382
389
|
```
|
383
390
|
|
384
|
-
- **showProgressBar**
|
391
|
+
- **showProgressBar**
|
385
392
|
|
386
393
|
Boolean value used for showing or hiding the progress bar.
|
387
394
|
|
@@ -389,7 +396,7 @@ Boolean value used for showing or hiding the progress bar.
|
|
389
396
|
<@nativescript-community/ui-image:Img showProgressBar="true"/>
|
390
397
|
```
|
391
398
|
|
392
|
-
- **progressBarColor**
|
399
|
+
- **progressBarColor**
|
393
400
|
|
394
401
|
String value used for setting the color of the progress bar. You can set it to hex values ("*#FF0000*") and/or predefined colors ("*green*").
|
395
402
|
|
package/index-common.d.ts
CHANGED
@@ -2,6 +2,7 @@ import { Color, CoreTypes, Property, View } from '@nativescript/core';
|
|
2
2
|
import { EventData as IEventData } from '@nativescript/core/data/observable';
|
3
3
|
import { ImageAsset } from '@nativescript/core/image-asset';
|
4
4
|
import { ImageSource } from '@nativescript/core/image-source';
|
5
|
+
export declare function colorConverter(v: string | Color): Color;
|
5
6
|
export declare enum CLogTypes {
|
6
7
|
log = 0,
|
7
8
|
info = 1,
|
@@ -55,6 +56,7 @@ export declare class EventData implements IEventData {
|
|
55
56
|
}
|
56
57
|
export type Stretch = 'none' | 'fill' | 'aspectFill' | 'aspectFit';
|
57
58
|
export declare const srcProperty: Property<ImageBase, string | ImageSource | ImageAsset>;
|
59
|
+
export declare const headersProperty: Property<ImageBase, Record<string, string>>;
|
58
60
|
export declare const lowerResSrcProperty: Property<ImageBase, string>;
|
59
61
|
export declare const placeholderImageUriProperty: Property<ImageBase, string>;
|
60
62
|
export declare const failureImageUriProperty: Property<ImageBase, string>;
|
@@ -63,7 +65,7 @@ export declare const backgroundUriProperty: Property<ImageBase, string>;
|
|
63
65
|
export declare const progressiveRenderingEnabledProperty: Property<ImageBase, boolean>;
|
64
66
|
export declare const localThumbnailPreviewsEnabledProperty: Property<ImageBase, boolean>;
|
65
67
|
export declare const showProgressBarProperty: Property<ImageBase, boolean>;
|
66
|
-
export declare const progressBarColorProperty: Property<ImageBase,
|
68
|
+
export declare const progressBarColorProperty: Property<ImageBase, Color>;
|
67
69
|
export declare const roundAsCircleProperty: Property<ImageBase, boolean>;
|
68
70
|
export declare const blurRadiusProperty: Property<ImageBase, number>;
|
69
71
|
export declare const blurDownSamplingProperty: Property<ImageBase, number>;
|
@@ -105,7 +107,7 @@ export declare abstract class ImageBase extends View {
|
|
105
107
|
progressiveRenderingEnabled: boolean;
|
106
108
|
localThumbnailPreviewsEnabled: boolean;
|
107
109
|
showProgressBar: boolean;
|
108
|
-
progressBarColor:
|
110
|
+
progressBarColor: Color;
|
109
111
|
roundAsCircle: boolean;
|
110
112
|
roundBottomRightRadius: number;
|
111
113
|
roundTopLeftRadius: number;
|
@@ -123,6 +125,7 @@ export declare abstract class ImageBase extends View {
|
|
123
125
|
alwaysFade: boolean;
|
124
126
|
noCache: boolean;
|
125
127
|
tintColor: Color;
|
128
|
+
headers: Record<string, string>;
|
126
129
|
readonly isLoading: boolean;
|
127
130
|
get nativeImageViewProtected(): any;
|
128
131
|
mCanRequestImage: boolean;
|
package/index-common.js
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
import { Length, Property, Trace, View, booleanConverter } from '@nativescript/core';
|
1
|
+
import { Color, Length, Property, Trace, View, booleanConverter } from '@nativescript/core';
|
2
2
|
import { isAndroid } from '@nativescript/core/platform';
|
3
|
+
export function colorConverter(v) {
|
4
|
+
if (!v || v instanceof Color) {
|
5
|
+
return v;
|
6
|
+
}
|
7
|
+
return new Color(v);
|
8
|
+
}
|
3
9
|
function isNonNegativeFiniteNumber(value) {
|
4
10
|
return isFinite(value) && !isNaN(value) && value >= 0;
|
5
11
|
}
|
@@ -112,6 +118,7 @@ export class EventData {
|
|
112
118
|
}
|
113
119
|
}
|
114
120
|
export const srcProperty = new Property({ name: 'src' });
|
121
|
+
export const headersProperty = new Property({ name: 'headers' });
|
115
122
|
export const lowerResSrcProperty = new Property({ name: 'lowerResSrc' });
|
116
123
|
export const placeholderImageUriProperty = new Property({ name: 'placeholderImageUri' });
|
117
124
|
export const failureImageUriProperty = new Property({ name: 'failureImageUri' });
|
@@ -119,8 +126,8 @@ export const stretchProperty = new Property({ name: 'stretch' });
|
|
119
126
|
export const backgroundUriProperty = new Property({ name: 'backgroundUri' });
|
120
127
|
export const progressiveRenderingEnabledProperty = new Property({ name: 'progressiveRenderingEnabled', valueConverter: booleanConverter });
|
121
128
|
export const localThumbnailPreviewsEnabledProperty = new Property({ name: 'localThumbnailPreviewsEnabled', valueConverter: booleanConverter });
|
122
|
-
export const showProgressBarProperty = new Property({ name: 'showProgressBar', valueConverter: booleanConverter });
|
123
|
-
export const progressBarColorProperty = new Property({ name: 'progressBarColor',
|
129
|
+
export const showProgressBarProperty = new Property({ name: 'showProgressBar', valueConverter: booleanConverter, defaultValue: false });
|
130
|
+
export const progressBarColorProperty = new Property({ name: 'progressBarColor', valueConverter: colorConverter });
|
124
131
|
export const roundAsCircleProperty = new Property({ name: 'roundAsCircle', valueConverter: booleanConverter, affectsLayout: isAndroid });
|
125
132
|
export const blurRadiusProperty = new Property({ name: 'blurRadius', valueConverter: (v) => parseFloat(v) });
|
126
133
|
export const blurDownSamplingProperty = new Property({ name: 'blurDownSampling', valueConverter: (v) => parseFloat(v) });
|
@@ -303,6 +310,7 @@ ImageBase.intermediateImageSetEvent = 'intermediateImageSet';
|
|
303
310
|
ImageBase.releaseEvent = 'release';
|
304
311
|
ImageBase.submitEvent = 'submit';
|
305
312
|
srcProperty.register(ImageBase);
|
313
|
+
headersProperty.register(ImageBase);
|
306
314
|
lowerResSrcProperty.register(ImageBase);
|
307
315
|
placeholderImageUriProperty.register(ImageBase);
|
308
316
|
failureImageUriProperty.register(ImageBase);
|
package/index.android.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
2
2
|
export * from './index-common';
|
3
3
|
import { Application, ImageAsset, ImageSource, Trace, Utils, backgroundInternalProperty, knownFolders, path } from '@nativescript/core';
|
4
4
|
import { isString } from '@nativescript/core/utils/types';
|
5
5
|
import { layout } from '@nativescript/core/utils/layout-helper';
|
6
|
-
import { CLog, CLogTypes, EventData, ImageBase, ScaleType, aspectRatioProperty, backgroundUriProperty, blurDownSamplingProperty, blurRadiusProperty, fadeDurationProperty, failureImageUriProperty, imageRotationProperty, lowerResSrcProperty, needRequestImage, placeholderImageUriProperty, progressBarColorProperty, roundAsCircleProperty, roundBottomLeftRadiusProperty, roundBottomRightRadiusProperty, roundTopLeftRadiusProperty, roundTopRightRadiusProperty, showProgressBarProperty, srcProperty, stretchProperty, tintColorProperty, wrapNativeException } from './index-common';
|
6
|
+
import { CLog, CLogTypes, EventData, ImageBase, ScaleType, aspectRatioProperty, backgroundUriProperty, blurDownSamplingProperty, blurRadiusProperty, fadeDurationProperty, failureImageUriProperty, headersProperty, imageRotationProperty, lowerResSrcProperty, needRequestImage, placeholderImageUriProperty, progressBarColorProperty, roundAsCircleProperty, roundBottomLeftRadiusProperty, roundBottomRightRadiusProperty, roundTopLeftRadiusProperty, roundTopRightRadiusProperty, showProgressBarProperty, srcProperty, stretchProperty, tintColorProperty, wrapNativeException } from './index-common';
|
7
7
|
let initialized = false;
|
8
8
|
let initializeConfig;
|
9
9
|
export function initialize(config) {
|
@@ -14,23 +14,25 @@ export function initialize(config) {
|
|
14
14
|
return;
|
15
15
|
}
|
16
16
|
let builder;
|
17
|
-
const useOkhttp = config?.useOkhttp;
|
17
|
+
const useOkhttp = config?.useOkhttp !== false;
|
18
18
|
if (useOkhttp) {
|
19
|
+
//@ts-ignore
|
20
|
+
let client;
|
19
21
|
//@ts-ignore
|
20
22
|
if (useOkhttp instanceof okhttp3.OkHttpClient) {
|
21
|
-
|
23
|
+
client = useOkhttp;
|
22
24
|
}
|
23
25
|
else {
|
24
26
|
//@ts-ignore
|
25
|
-
|
27
|
+
client = new okhttp3.OkHttpClient();
|
26
28
|
}
|
29
|
+
builder = com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory.newBuilder(context, client);
|
30
|
+
builder.setNetworkFetcher(new com.nativescript.image.OkHttpNetworkFetcher(client));
|
27
31
|
}
|
28
32
|
else {
|
29
33
|
builder = com.facebook.imagepipeline.core.ImagePipelineConfig.newBuilder(context);
|
30
34
|
}
|
31
|
-
|
32
|
-
builder.setDownsampleEnabled(true);
|
33
|
-
}
|
35
|
+
builder.setDownsampleEnabled(config?.isDownsampleEnabled === true);
|
34
36
|
if (config?.leakTracker) {
|
35
37
|
builder.setCloseableReferenceLeakTracker(config.leakTracker);
|
36
38
|
}
|
@@ -424,6 +426,9 @@ export class Img extends ImageBase {
|
|
424
426
|
[_u = aspectRatioProperty.setNative]() {
|
425
427
|
this.initImage();
|
426
428
|
}
|
429
|
+
[_v = headersProperty.setNative](value) {
|
430
|
+
this.initImage();
|
431
|
+
}
|
427
432
|
[backgroundInternalProperty.setNative](value) {
|
428
433
|
super[backgroundInternalProperty.setNative](value);
|
429
434
|
this.nativeViewProtected.setClipToOutline(value?.hasBorderRadius());
|
@@ -586,7 +591,8 @@ export class Img extends ImageBase {
|
|
586
591
|
lowerResSrc: this.lowerResSrc ? getUri(this.lowerResSrc, false) : undefined,
|
587
592
|
blurDownSampling: this.blurDownSampling,
|
588
593
|
autoPlayAnimations: this.autoPlayAnimations,
|
589
|
-
tapToRetryEnabled: this.tapToRetryEnabled
|
594
|
+
tapToRetryEnabled: this.tapToRetryEnabled,
|
595
|
+
headers: this.headers
|
590
596
|
});
|
591
597
|
view.setUri(uri, options, this.controllerListener);
|
592
598
|
// const async = this.loadMode === 'async';
|
@@ -673,7 +679,7 @@ export class Img extends ImageBase {
|
|
673
679
|
builder.setBackground(backgroundDrawable);
|
674
680
|
}
|
675
681
|
if (this.showProgressBar) {
|
676
|
-
builder.setProgressBarImage(this.progressBarColor, this.stretch);
|
682
|
+
builder.setProgressBarImage(this.progressBarColor?.hex, this.stretch);
|
677
683
|
}
|
678
684
|
if (this.roundAsCircle) {
|
679
685
|
builder.setRoundingParamsAsCircle();
|
@@ -813,6 +819,9 @@ __decorate([
|
|
813
819
|
__decorate([
|
814
820
|
needRequestImage
|
815
821
|
], Img.prototype, _u, null);
|
822
|
+
__decorate([
|
823
|
+
needRequestImage
|
824
|
+
], Img.prototype, _v, null);
|
816
825
|
class GenericDraweeHierarchyBuilder {
|
817
826
|
constructor() {
|
818
827
|
const res = Utils.android.getApplicationContext().getResources();
|
package/index.d.ts
CHANGED
@@ -194,6 +194,11 @@ export class Img extends View {
|
|
194
194
|
*/
|
195
195
|
decodeHeight: number;
|
196
196
|
|
197
|
+
/**
|
198
|
+
* add custom headers to the image download request
|
199
|
+
*/
|
200
|
+
headers: Record<string, string>;
|
201
|
+
|
197
202
|
/**
|
198
203
|
* IOS: if you want to show animated images you need to set this to true
|
199
204
|
*/
|
package/index.ios.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
var _a, _b, _c;
|
1
|
+
var _a, _b, _c, _d, _e;
|
2
2
|
export * from './index-common';
|
3
3
|
import { ImageAsset, ImageSource, Screen, Trace, Utils, knownFolders, path } from '@nativescript/core';
|
4
4
|
import { layout } from '@nativescript/core/utils/layout-helper';
|
5
5
|
import { isString } from '@nativescript/core/utils/types';
|
6
|
-
import { CLog, CLogTypes, ImageBase, ScaleType, failureImageUriProperty, imageRotationProperty, placeholderImageUriProperty, srcProperty, stretchProperty, wrapNativeException } from './index-common';
|
6
|
+
import { CLog, CLogTypes, ImageBase, ScaleType, failureImageUriProperty, headersProperty, imageRotationProperty, placeholderImageUriProperty, progressBarColorProperty, showProgressBarProperty, srcProperty, stretchProperty, wrapNativeException } from './index-common';
|
7
7
|
export class ImageInfo {
|
8
8
|
constructor(width, height) {
|
9
9
|
this.width = width;
|
@@ -456,7 +456,32 @@ export class Img extends ImageBase {
|
|
456
456
|
context.setValueForKey(value, k);
|
457
457
|
});
|
458
458
|
}
|
459
|
+
if (this.headers) {
|
460
|
+
const requestModifier = SDWebImageDownloaderRequestModifier.requestModifierWithBlock((request) => {
|
461
|
+
const newRequest = request.mutableCopy();
|
462
|
+
Object.keys(this.headers).forEach((k) => {
|
463
|
+
newRequest.addValueForHTTPHeaderField(this.headers[k], k);
|
464
|
+
});
|
465
|
+
return newRequest.copy();
|
466
|
+
});
|
467
|
+
context.setValueForKey(requestModifier, SDWebImageContextDownloadRequestModifier);
|
468
|
+
}
|
459
469
|
this.mCacheKey = SDWebImageManager.sharedManager.cacheKeyForURLContext(uri, context);
|
470
|
+
if (this.showProgressBar) {
|
471
|
+
try {
|
472
|
+
if (this.progressBarColor) {
|
473
|
+
const indicator = new SDWebImageActivityIndicator();
|
474
|
+
indicator.indicatorView.color = this.progressBarColor.ios;
|
475
|
+
this.nativeImageViewProtected.sd_imageIndicator = indicator;
|
476
|
+
}
|
477
|
+
else {
|
478
|
+
this.nativeImageViewProtected.sd_imageIndicator = SDWebImageActivityIndicator.grayIndicator;
|
479
|
+
}
|
480
|
+
}
|
481
|
+
catch (ex) {
|
482
|
+
console.error(ex);
|
483
|
+
}
|
484
|
+
}
|
460
485
|
this.nativeImageViewProtected.sd_setImageWithURLPlaceholderImageOptionsContextProgressCompleted(uri, this.placeholderImage, options, context, this.onLoadProgress, this.handleImageLoaded);
|
461
486
|
}
|
462
487
|
else if (this.placeholderImage) {
|
@@ -473,9 +498,14 @@ export class Img extends ImageBase {
|
|
473
498
|
[_b = imageRotationProperty.setNative](value) {
|
474
499
|
this.initImage();
|
475
500
|
}
|
476
|
-
[_c = placeholderImageUriProperty.setNative]() {
|
477
|
-
|
478
|
-
|
501
|
+
[_c = placeholderImageUriProperty.setNative]() { }
|
502
|
+
[_d = showProgressBarProperty.setNative](value) {
|
503
|
+
this.showProgressBar = value;
|
504
|
+
}
|
505
|
+
[progressBarColorProperty.setNative](value) {
|
506
|
+
this.progressBarColor = value;
|
507
|
+
}
|
508
|
+
[_e = headersProperty.setNative](value) {
|
479
509
|
}
|
480
510
|
[failureImageUriProperty.setNative]() {
|
481
511
|
// this.updateHierarchy();
|
@@ -515,4 +545,10 @@ __decorate([
|
|
515
545
|
__decorate([
|
516
546
|
needRequestImage
|
517
547
|
], Img.prototype, _c, null);
|
548
|
+
__decorate([
|
549
|
+
needRequestImage
|
550
|
+
], Img.prototype, _d, null);
|
551
|
+
__decorate([
|
552
|
+
needRequestImage
|
553
|
+
], Img.prototype, _e, null);
|
518
554
|
//# sourceMappingURL=index.ios.js.map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nativescript-community/ui-image",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.5.0",
|
4
4
|
"description": "Advanced and efficient image display plugin which uses Fresco (Android) and SDWebImage (iOS) to implement caching, placeholders, image effects, and much more.",
|
5
5
|
"main": "./index",
|
6
6
|
"sideEffects": false,
|
@@ -36,5 +36,5 @@
|
|
36
36
|
},
|
37
37
|
"license": "Apache-2.0",
|
38
38
|
"readmeFilename": "README.md",
|
39
|
-
"gitHead": "
|
39
|
+
"gitHead": "c9982accf6b1ecbd0fcdfd298f70152b1e65f4c3"
|
40
40
|
}
|
@@ -9,6 +9,7 @@ dependencies {
|
|
9
9
|
implementation("com.facebook.fresco:imagepipeline-okhttp3:$frescoVersion") {
|
10
10
|
exclude group: 'com.facebook.soloader', module: 'soloader'
|
11
11
|
}
|
12
|
+
implementation("com.facebook.fresco:middleware:$frescoVersion")
|
12
13
|
implementation("com.facebook.fresco:nativeimagetranscoder:$frescoVersion")
|
13
14
|
implementation 'com.facebook.infer.annotation:infer-annotation:0.18.0'
|
14
15
|
// implementation ("com.facebook.fresco:animated-gif:$frescoVersion") {
|
@@ -272,10 +272,12 @@ public class DraweeView extends SimpleDraweeView {
|
|
272
272
|
public void setUri(android.net.Uri uri, String jsonOptions, com.facebook.drawee.controller.ControllerListener listener) {
|
273
273
|
ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri).setRotationOptions( com.facebook.imagepipeline.common.RotationOptions.autoRotate());
|
274
274
|
JSONObject object = null;
|
275
|
+
JSONObject headers = null;
|
275
276
|
if (jsonOptions.length() > 2) {
|
276
277
|
try {
|
277
278
|
object = new JSONObject(jsonOptions);
|
278
|
-
} catch (Exception
|
279
|
+
} catch (Exception e) {
|
280
|
+
e.printStackTrace();
|
279
281
|
}
|
280
282
|
}
|
281
283
|
if (object != null) {
|
@@ -296,9 +298,9 @@ public class DraweeView extends SimpleDraweeView {
|
|
296
298
|
int blurDownSampling = object.optInt("blurDownSampling", 1);
|
297
299
|
requestBuilder = requestBuilder.setPostprocessor(new com.nativescript.image.ScalingBlurPostprocessor(2, blurRadius, blurDownSampling));
|
298
300
|
}
|
301
|
+
headers = object.optJSONObject("headers");
|
299
302
|
}
|
300
|
-
|
301
|
-
ImageRequest request = requestBuilder.build();
|
303
|
+
ImageRequest request = NetworkImageRequest.fromBuilderWithHeaders(requestBuilder, headers);
|
302
304
|
|
303
305
|
// if (object != null && object.optBoolean("async") == false) {
|
304
306
|
// DataSource<CloseableReference<CloseableImage>> dataSource =
|
@@ -0,0 +1,55 @@
|
|
1
|
+
package com.nativescript.image;
|
2
|
+
|
3
|
+
import com.facebook.imagepipeline.request.ImageRequest;
|
4
|
+
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
5
|
+
|
6
|
+
import org.json.JSONObject;
|
7
|
+
import org.json.JSONException;
|
8
|
+
|
9
|
+
import java.util.HashMap;
|
10
|
+
import java.util.Map;
|
11
|
+
import java.util.Iterator;
|
12
|
+
|
13
|
+
import android.util.Log;
|
14
|
+
|
15
|
+
/** Extended ImageRequest with request headers */
|
16
|
+
public class NetworkImageRequest extends ImageRequest {
|
17
|
+
|
18
|
+
/** Headers for the request */
|
19
|
+
private Map<String, String> mHeaders = null;
|
20
|
+
|
21
|
+
static Map<String, String> toMap(JSONObject object) throws JSONException {
|
22
|
+
Map<String, String> map = new HashMap<String, String>();
|
23
|
+
|
24
|
+
Iterator<String> keysItr = object.keys();
|
25
|
+
while(keysItr.hasNext()) {
|
26
|
+
String key = keysItr.next();
|
27
|
+
Object value = object.get(key);
|
28
|
+
|
29
|
+
if(value instanceof String) {
|
30
|
+
map.put(key, (String)value);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
return map;
|
34
|
+
}
|
35
|
+
|
36
|
+
public static NetworkImageRequest fromBuilderWithHeaders(
|
37
|
+
ImageRequestBuilder builder, JSONObject headers) {
|
38
|
+
return new NetworkImageRequest(builder, headers);
|
39
|
+
}
|
40
|
+
|
41
|
+
protected NetworkImageRequest(ImageRequestBuilder builder, JSONObject headers) {
|
42
|
+
super(builder);
|
43
|
+
if (headers != null) {
|
44
|
+
try {
|
45
|
+
mHeaders = toMap(headers);
|
46
|
+
} catch (Exception e) {
|
47
|
+
e.printStackTrace();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
public Map<String, String> getHeaders() {
|
53
|
+
return mHeaders;
|
54
|
+
}
|
55
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
package com.nativescript.image;
|
2
|
+
|
3
|
+
import android.net.Uri;
|
4
|
+
import android.os.SystemClock;
|
5
|
+
import android.util.Log;
|
6
|
+
import com.facebook.imagepipeline.producers.NetworkFetcher;
|
7
|
+
import java.util.Collections;
|
8
|
+
import java.util.HashMap;
|
9
|
+
import java.util.Map;
|
10
|
+
import java.util.concurrent.Executor;
|
11
|
+
import okhttp3.CacheControl;
|
12
|
+
import okhttp3.Headers;
|
13
|
+
import okhttp3.OkHttpClient;
|
14
|
+
import okhttp3.Request;
|
15
|
+
|
16
|
+
class OkHttpNetworkFetcher extends com.facebook.imagepipeline.backends.okhttp3.OkHttpNetworkFetcher {
|
17
|
+
|
18
|
+
private static final String TAG = "OkHttpNetworkFetcher";
|
19
|
+
|
20
|
+
private final OkHttpClient mOkHttpClient;
|
21
|
+
private final Executor mCancellationExecutor;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @param okHttpClient client to use
|
25
|
+
*/
|
26
|
+
public OkHttpNetworkFetcher(OkHttpClient okHttpClient) {
|
27
|
+
super(okHttpClient);
|
28
|
+
mOkHttpClient = okHttpClient;
|
29
|
+
mCancellationExecutor = okHttpClient.dispatcher().executorService();
|
30
|
+
}
|
31
|
+
|
32
|
+
@Override
|
33
|
+
public void fetch(
|
34
|
+
final OkHttpNetworkFetcher.OkHttpNetworkFetchState fetchState,
|
35
|
+
final NetworkFetcher.Callback callback) {
|
36
|
+
fetchState.submitTime = SystemClock.elapsedRealtime();
|
37
|
+
final Uri uri = fetchState.getUri();
|
38
|
+
Map<String, String> requestHeaders = null;
|
39
|
+
if (fetchState.getContext().getImageRequest() instanceof NetworkImageRequest) {
|
40
|
+
NetworkImageRequest networkImageRequest =
|
41
|
+
(NetworkImageRequest) fetchState.getContext().getImageRequest();
|
42
|
+
requestHeaders = networkImageRequest.getHeaders();
|
43
|
+
}
|
44
|
+
if (requestHeaders == null) {
|
45
|
+
requestHeaders = Collections.emptyMap();
|
46
|
+
}
|
47
|
+
final Request request =
|
48
|
+
new Request.Builder()
|
49
|
+
.url(uri.toString())
|
50
|
+
.headers(Headers.of(requestHeaders))
|
51
|
+
.get()
|
52
|
+
.build();
|
53
|
+
|
54
|
+
fetchWithRequest(fetchState, callback, request);
|
55
|
+
}
|
56
|
+
}
|
@@ -27,7 +27,11 @@
|
|
27
27
|
"com.facebook.drawee.backends.pipeline.info:ImagePerfData",
|
28
28
|
"com.facebook.drawee.controller:ControllerListener",
|
29
29
|
"com.nativescript.image:DraweeView",
|
30
|
+
"com.nativescript.image:OkHttpNetworkFetcher",
|
30
31
|
"com.nativescript.image:ScalingBlurPostprocessor",
|
32
|
+
"com.facebook.imagepipeline.producers:NetworkFetcher",
|
33
|
+
"com.facebook.imagepipeline.backends.okhttp3:OkHttpImagePipelineConfigFactory",
|
34
|
+
"okhttp3:OkHttpClient",
|
31
35
|
"android.graphics.drawable:Animatable",
|
32
36
|
"com.facebook.imagepipeline.image:ImageInfo",
|
33
37
|
"com.facebook.common.util:UriUtil",
|
Binary file
|
package/typings/android.d.ts
CHANGED
@@ -20,6 +20,9 @@ declare namespace com {
|
|
20
20
|
class BaseDataSubscriber extends facebook.datasource.BaseDataSubscriber<any> {
|
21
21
|
public constructor(listener: BaseDataSubscriberListener);
|
22
22
|
}
|
23
|
+
class OkHttpNetworkFetcher extends facebook.imagepipeline.backends.okhttp3.OkHttpNetworkFetcher {
|
24
|
+
|
25
|
+
}
|
23
26
|
}
|
24
27
|
}
|
25
28
|
}
|
package/typings/ios.d.ts
CHANGED
@@ -6,6 +6,8 @@ declare namespace NSURL {
|
|
6
6
|
export function sd_URLWithAssetLocalIdentifier(identifier: string): NSURL;
|
7
7
|
}
|
8
8
|
declare interface UIImageView {
|
9
|
+
sd_imageIndicator: SDWebImageIndicator;
|
10
|
+
|
9
11
|
sd_setHighlightedImageWithURL(url: NSURL): void;
|
10
12
|
|
11
13
|
sd_setHighlightedImageWithURLCompleted(url: NSURL, completedBlock: (p1: UIImage, p2: NSError, p3: SDImageCacheType, p4: NSURL) => void): void;
|