Skip to content

Commit 9ed7c7f

Browse files
author
farfromrefug
committed
chore: improvements and cleanup
1 parent f7c4b99 commit 9ed7c7f

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/image/index-common.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { Color, CoreTypes, Length, Property, ShorthandProperty, Trace, View, booleanConverter } from '@nativescript/core';
22
import { EventData as IEventData } from '@nativescript/core/data/observable';
3+
// import { colorConverter } from '@nativescript/core/ui/styling/style-properties';
34
import { ImageAsset } from '@nativescript/core/image-asset';
45
import { ImageSource } from '@nativescript/core/image-source';
56
import { isAndroid } from '@nativescript/core/platform';
67

8+
export function colorConverter(v: string | Color): Color {
9+
if (!v || v instanceof Color) {
10+
return v as Color;
11+
}
12+
return new Color(v);
13+
}
714
function isNonNegativeFiniteNumber(value: number): boolean {
815
return isFinite(value) && !isNaN(value) && value >= 0;
916
}
@@ -163,8 +170,8 @@ export const stretchProperty = new Property<ImageBase, string>({ name: 'stretch'
163170
export const backgroundUriProperty = new Property<ImageBase, string>({ name: 'backgroundUri' });
164171
export const progressiveRenderingEnabledProperty = new Property<ImageBase, boolean>({ name: 'progressiveRenderingEnabled', valueConverter: booleanConverter });
165172
export const localThumbnailPreviewsEnabledProperty = new Property<ImageBase, boolean>({ name: 'localThumbnailPreviewsEnabled', valueConverter: booleanConverter });
166-
export const showProgressBarProperty = new Property<ImageBase, boolean>({ name: 'showProgressBar', valueConverter: booleanConverter });
167-
export const progressBarColorProperty = new Property<ImageBase, string>({ name: 'progressBarColor', defaultValue: undefined });
173+
export const showProgressBarProperty = new Property<ImageBase, boolean>({ name: 'showProgressBar', valueConverter: booleanConverter, defaultValue: false });
174+
export const progressBarColorProperty = new Property<ImageBase, Color>({ name: 'progressBarColor', valueConverter: colorConverter });
168175
export const roundAsCircleProperty = new Property<ImageBase, boolean>({ name: 'roundAsCircle', valueConverter: booleanConverter, affectsLayout: isAndroid });
169176
export const blurRadiusProperty = new Property<ImageBase, number>({ name: 'blurRadius', valueConverter: (v) => parseFloat(v) });
170177
export const blurDownSamplingProperty = new Property<ImageBase, number>({ name: 'blurDownSampling', valueConverter: (v) => parseFloat(v) });

src/image/index.ios.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,16 @@ export class Img extends ImageBase {
524524
}
525525
this.mCacheKey = SDWebImageManager.sharedManager.cacheKeyForURLContext(uri, context);
526526
if (this.showProgressBar) {
527-
try{
527+
try {
528528
if (this.progressBarColor && Color.isValid(this.progressBarColor)) {
529529
const indicator = new SDWebImageActivityIndicator();
530530
indicator.indicatorView.color = new Color(this.progressBarColor).ios;
531531
this.nativeImageViewProtected.sd_imageIndicator = indicator;
532532
} else {
533533
this.nativeImageViewProtected.sd_imageIndicator = SDWebImageActivityIndicator.grayIndicator;
534534
}
535-
}
536-
catch(ex) {
537-
console.error(ex)
535+
} catch (ex) {
536+
console.error(ex);
538537
}
539538
}
540539

@@ -563,23 +562,13 @@ export class Img extends ImageBase {
563562
}
564563
placeholderImage: UIImage;
565564
@needRequestImage
566-
[placeholderImageUriProperty.setNative]() {
567-
// this.placeholderImage = this.getUIImage(this.placeholderImageUri);
568-
// this.initImage();
569-
}
570-
571-
[showProgressBarProperty.getDefault](): boolean {
572-
return false;
573-
}
565+
[placeholderImageUriProperty.setNative]() {}
574566

567+
@needRequestImage
575568
[showProgressBarProperty.setNative](value) {
576569
this.showProgressBar = value;
577570
}
578571

579-
[progressBarColorProperty.getDefault](): string {
580-
return "";
581-
}
582-
583572
[progressBarColorProperty.setNative](value) {
584573
this.progressBarColor = value;
585574
}

0 commit comments

Comments
 (0)