@nativescript-community/ui-image 4.5.1 → 4.5.2

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 CHANGED
@@ -3,6 +3,10 @@
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.2](https://github.com/nativescript-community/ui-image/compare/v4.5.1...v4.5.2) (2024-05-14)
7
+
8
+ **Note:** Version bump only for package @nativescript-community/ui-image
9
+
6
10
  ## [4.5.1](https://github.com/nativescript-community/ui-image/compare/v4.5.0...v4.5.1) (2024-04-25)
7
11
 
8
12
  ### Bug Fixes
package/index-common.d.ts CHANGED
@@ -107,7 +107,7 @@ export declare abstract class ImageBase extends View {
107
107
  progressiveRenderingEnabled: boolean;
108
108
  localThumbnailPreviewsEnabled: boolean;
109
109
  showProgressBar: boolean;
110
- progressBarColor: Color;
110
+ progressBarColor: Color | string;
111
111
  roundAsCircle: boolean;
112
112
  roundBottomRightRadius: number;
113
113
  roundTopLeftRadius: number;
package/index.d.ts CHANGED
@@ -74,7 +74,7 @@ export class Img extends View {
74
74
  /**
75
75
  * String value used for the image URI.
76
76
  */
77
- src: string | ImageSource | ImageAsset | Promise<string | ImageSource | ImageAsset>;
77
+ src: SrcType;
78
78
 
79
79
  /**
80
80
  * String value used for the lower res image URI.
@@ -127,7 +127,7 @@ export class Img extends View {
127
127
  /**
128
128
  * String value used for setting the color of the progress bar. Can be set to hex values ("#FF0000"") and predefined colors ("green").
129
129
  */
130
- progressBarColor: string;
130
+ progressBarColor: Color | string;
131
131
 
132
132
  /**
133
133
  * Boolean value used for determining if the image should be rounded as a circle.
@@ -349,6 +349,12 @@ export interface AnimatedImage {
349
349
  * The entry point for the image pipeline..
350
350
  */
351
351
  export class ImagePipeline {
352
+ /**
353
+ * iOS: set this to true to enable complex cache handling
354
+ * this is necessary when you use colorMatrix, decodeWidth,...
355
+ * and when you change images on drive requiring cache image eviction
356
+ */
357
+ static iosComplexCacheEviction: boolean;
352
358
  /**
353
359
  * Returns whether the image is stored in the bitmap memory cache.
354
360
  */
@@ -454,3 +460,7 @@ export interface ImagePipelineConfigSetting {
454
460
  useOkhttp?: boolean; // Android only
455
461
  }
456
462
  export const ImageViewTraceCategory;
463
+
464
+ export type GetContextFromOptionsCallback = (context: NSDictionary<string, any>, transformers: any[], options: Partial<Img>) => void;
465
+
466
+ declare function registerPluginGetContextFromOptions(callback: GetContextFromOptionsCallback); // iOS only for plugins
package/index.ios.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './index-common';
2
2
  import { EventData, ImageBase, ImageInfo as ImageInfoBase, ImagePipelineConfigSetting, SrcType } from './index-common';
3
+ import { GetContextFromOptionsCallback } from '@nativescript-community/ui-image';
3
4
  export declare class ImageInfo implements ImageInfoBase {
4
5
  private width;
5
6
  private height;
@@ -13,15 +14,17 @@ export interface FinalEventData extends EventData {
13
14
  }
14
15
  export declare function initialize(config?: ImagePipelineConfigSetting): void;
15
16
  export declare function shutDown(): void;
17
+ export declare function registerPluginGetContextFromOptions(callback: GetContextFromOptionsCallback): void;
16
18
  export declare class ImagePipeline {
19
+ static iosComplexCacheEviction: boolean;
17
20
  private mIos;
18
21
  constructor();
19
22
  getCacheKey(uri: string, options: Partial<Img>): string;
20
23
  isInDiskCache(key: string): boolean;
21
24
  isInBitmapMemoryCache(key: string): boolean;
22
25
  evictFromMemoryCache(key: string): void;
23
- evictFromDiskCache(key: string): Promise<void>;
24
- evictFromCache(key: string): Promise<void>;
26
+ evictFromDiskCache(key: string): Promise<any[]>;
27
+ evictFromCache(key: string, type?: SDImageCacheType): Promise<any[]>;
25
28
  clearCaches(): void;
26
29
  clearMemoryCaches(): void;
27
30
  clearDiskCaches(): void;
@@ -40,7 +43,6 @@ export declare class Img extends ImageBase {
40
43
  contextOptions: any;
41
44
  get cacheKey(): string;
42
45
  protected mImageSourceAffectsLayout: boolean;
43
- mCIFilter: CIFilter;
44
46
  createNativeView(): UIImageView;
45
47
  _setNativeClipToBounds(): void;
46
48
  onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;
package/index.ios.js CHANGED
@@ -1,6 +1,7 @@
1
1
  var _a, _b, _c, _d, _e;
2
2
  export * from './index-common';
3
- import { ImageAsset, ImageSource, Screen, Trace, Utils, knownFolders, path } from '@nativescript/core';
3
+ import { ApplicationSettings, ImageAsset, ImageSource, Screen, Trace, Utils, knownFolders, path } from '@nativescript/core';
4
+ import { debounce } from '@nativescript/core/utils';
4
5
  import { layout } from '@nativescript/core/utils/layout-helper';
5
6
  import { isString } from '@nativescript/core/utils/types';
6
7
  import { CLog, CLogTypes, ImageBase, ScaleType, failureImageUriProperty, headersProperty, imageRotationProperty, placeholderImageUriProperty, progressBarColorProperty, showProgressBarProperty, srcProperty, stretchProperty, wrapNativeException } from './index-common';
@@ -73,6 +74,10 @@ export function initialize(config) {
73
74
  SDImageLoadersManager.sharedManager.loaders = NSArray.arrayWithArray([SDWebImageDownloader.sharedDownloader, SDImagePhotosLoader.sharedLoader]);
74
75
  }
75
76
  export function shutDown() { }
77
+ const pluginsGetContextFromOptions = new Set();
78
+ export function registerPluginGetContextFromOptions(callback) {
79
+ pluginsGetContextFromOptions.add(callback);
80
+ }
76
81
  function getContextFromOptions(options) {
77
82
  const context = NSMutableDictionary.dictionary();
78
83
  const transformers = [];
@@ -98,14 +103,25 @@ function getContextFromOptions(options) {
98
103
  //@ts-ignore
99
104
  NSImageRoundCornerTransformer.transformerWithTopLefRadiusTopRightRadiusBottomRightRadiusBottomLeftRadius(layout.toDeviceIndependentPixels(options.roundTopLeftRadius), layout.toDeviceIndependentPixels(options.roundTopRightRadius), layout.toDeviceIndependentPixels(options.roundBottomRightRadius), layout.toDeviceIndependentPixels(options.roundBottomLeftRadius)));
100
105
  }
101
- if (options.mCIFilter) {
102
- transformers.push(SDImageFilterTransformer.transformerWithFilter(options.mCIFilter));
103
- }
106
+ pluginsGetContextFromOptions.forEach((c) => c(context, transformers, options));
104
107
  if (transformers.length > 0) {
105
108
  context.setValueForKey(SDImagePipelineTransformer.transformerWithTransformers(transformers), SDWebImageContextImageTransformer);
106
109
  }
107
110
  return context;
108
111
  }
112
+ // This is not the best solution as their might be a lot of corner cases
113
+ // for example if an image is removed from cache without going through ImagePipeline
114
+ // we wont know it and the cacheKeyMap will grow
115
+ // but i dont see a better way right now
116
+ const CACHE_KEYS_SETTING_KEY = 'NS_ui_image_cache_keys';
117
+ let cacheKeyMap = JSON.parse(ApplicationSettings.getString(CACHE_KEYS_SETTING_KEY, '{}'));
118
+ const saveCacheKeys = debounce(() => ApplicationSettings.setString(CACHE_KEYS_SETTING_KEY, JSON.stringify(cacheKeyMap)), 500);
119
+ function registerCacheKey(cacheKey, uri) {
120
+ const set = new Set(cacheKeyMap[uri] || []);
121
+ set.add(cacheKey);
122
+ cacheKeyMap[uri] = [...set];
123
+ saveCacheKeys();
124
+ }
109
125
  export class ImagePipeline {
110
126
  constructor() {
111
127
  this.mIos = SDImageCache.sharedImageCache;
@@ -121,19 +137,24 @@ export class ImagePipeline {
121
137
  return this.mIos.imageFromMemoryCacheForKey(key) !== null;
122
138
  }
123
139
  evictFromMemoryCache(key) {
124
- this.mIos.removeImageFromMemoryForKey(key);
140
+ const cachekKeys = (cacheKeyMap[key] || []).concat([key]);
141
+ cachekKeys.forEach((k) => {
142
+ this.mIos.removeImageFromMemoryForKey(k);
143
+ });
125
144
  }
126
145
  async evictFromDiskCache(key) {
127
- return new Promise((resolve) => {
128
- this.mIos.removeImageForKeyCacheTypeCompletion(key, 1 /* SDImageCacheType.Disk */, resolve);
129
- });
146
+ return this.evictFromCache(key, 1 /* SDImageCacheType.Disk */);
130
147
  }
131
- async evictFromCache(key) {
132
- return new Promise((resolve) => {
133
- this.mIos.removeImageForKeyCacheTypeCompletion(key, 3 /* SDImageCacheType.All */, resolve);
134
- });
148
+ async evictFromCache(key, type = 3 /* SDImageCacheType.All */) {
149
+ const cachekKeys = (cacheKeyMap[key] || []).concat([key]);
150
+ delete cacheKeyMap[key];
151
+ return Promise.all(cachekKeys.map((k) => new Promise((resolve) => {
152
+ this.mIos.removeImageForKeyCacheTypeCompletion(k, type, resolve);
153
+ })));
135
154
  }
136
155
  clearCaches() {
156
+ cacheKeyMap = {};
157
+ ApplicationSettings.remove(CACHE_KEYS_SETTING_KEY);
137
158
  this.mIos.clearMemory();
138
159
  this.mIos.clearDiskOnCompletion(null);
139
160
  }
@@ -168,6 +189,7 @@ export class ImagePipeline {
168
189
  return this.mIos;
169
190
  }
170
191
  }
192
+ ImagePipeline.iosComplexCacheEviction = false;
171
193
  export const needRequestImage = function (target, propertyKey, descriptor) {
172
194
  const originalMethod = descriptor.value;
173
195
  descriptor.value = function (...args) {
@@ -319,10 +341,9 @@ export class Img extends ImageBase {
319
341
  const src = this.src;
320
342
  const srcType = typeof src;
321
343
  if (src && (srcType === 'string' || src instanceof ImageAsset)) {
322
- const cachekKey = this.mCacheKey || getUri(src).absoluteString;
323
344
  // const isInCache = imagePipeLine.isInBitmapMemoryCache(cachekKey);
324
345
  // if (isInCache) {
325
- await imagePipeLine.evictFromCache(cachekKey);
346
+ await imagePipeLine.evictFromCache(getUri(src).absoluteString);
326
347
  // }
327
348
  }
328
349
  // this.src = null;
@@ -467,6 +488,9 @@ export class Img extends ImageBase {
467
488
  context.setValueForKey(requestModifier, SDWebImageContextDownloadRequestModifier);
468
489
  }
469
490
  this.mCacheKey = SDWebImageManager.sharedManager.cacheKeyForURLContext(uri, context);
491
+ if (ImagePipeline.iosComplexCacheEviction) {
492
+ registerCacheKey(this.mCacheKey, uri);
493
+ }
470
494
  if (this.showProgressBar) {
471
495
  try {
472
496
  if (this.progressBarColor) {
@@ -505,8 +529,7 @@ export class Img extends ImageBase {
505
529
  [progressBarColorProperty.setNative](value) {
506
530
  this.progressBarColor = value;
507
531
  }
508
- [_e = headersProperty.setNative](value) {
509
- }
532
+ [_e = headersProperty.setNative](value) { }
510
533
  [failureImageUriProperty.setNative]() {
511
534
  // this.updateHierarchy();
512
535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript-community/ui-image",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
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": "7ea32ad1649b64b1c3eb35b906fea16f213e474a"
39
+ "gitHead": "d4462950b4a219a6afa848ba9306f9031b932ec3"
40
40
  }
Binary file
package/vue/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { Img } from '../image';
2
+ const ImagePlugin = {
3
+ install(Vue) {
4
+ Vue.registerElement('NSImg', () => Img);
5
+ }
6
+ };
7
+ export default ImagePlugin;
8
+ //# sourceMappingURL=index.mjs.map