Skip to content

Commit 6509efa

Browse files
authored
fix(android-images): set decodeHeight/decodeWidth default values to dip (NativeScript#5490)
BREAKING CHANGE: change decodeHeight/decodeWidth properties to accept device independent pixels by default
1 parent 9214883 commit 6509efa

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

tns-core-modules/ui/image/image-common.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Image as ImageDefinition, Stretch } from ".";
2-
import { View, Property, InheritedCssProperty, Style, Color, isIOS, booleanConverter } from "../core/view";
2+
import { View, Property, InheritedCssProperty, Length, Style, Color, isIOS, booleanConverter } from "../core/view";
33
import { ImageAsset } from "../../image-asset";
44
import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source";
55
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils";
@@ -13,6 +13,8 @@ export abstract class ImageBase extends View implements ImageDefinition {
1313
public isLoading: boolean;
1414
public stretch: Stretch;
1515
public loadMode: "sync" | "async";
16+
public decodeWidth: Length;
17+
public decodeHeight: Length;
1618

1719
get tintColor(): Color {
1820
return this.style.tintColor;
@@ -118,4 +120,10 @@ export const stretchProperty = new Property<ImageBase, Stretch>({ name: "stretch
118120
stretchProperty.register(ImageBase);
119121

120122
export const tintColorProperty = new InheritedCssProperty<Style, Color>({ name: "tintColor", cssName: "tint-color", equalityComparer: Color.equals, valueConverter: (value) => new Color(value) });
121-
tintColorProperty.register(Style);
123+
tintColorProperty.register(Style);
124+
125+
export const decodeHeightProperty = new Property<ImageBase, Length>({ name: "decodeHeight", defaultValue: { value: 0, unit: "dip" }, valueConverter: Length.parse });
126+
decodeHeightProperty.register(ImageBase);
127+
128+
export const decodeWidthProperty = new Property<ImageBase, Length>({ name: "decodeWidth", defaultValue: { value: 0, unit: "dip" }, valueConverter: Length.parse });
129+
decodeWidthProperty.register(ImageBase);

tns-core-modules/ui/image/image.android.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
ImageSource, ImageAsset, ImageBase, stretchProperty, imageSourceProperty, srcProperty, tintColorProperty, Color,
3-
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX
3+
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX, Length
44
} from "./image-common";
55
import { knownFolders } from "../../file-system";
66

@@ -43,16 +43,14 @@ function initializeImageLoadedListener() {
4343
export class Image extends ImageBase {
4444
nativeViewProtected: org.nativescript.widgets.ImageView;
4545

46-
public decodeWidth = 0;
47-
public decodeHeight = 0;
4846
public useCache = true;
4947

5048
public createNativeView() {
5149
if (!AndroidImageView) {
5250
AndroidImageView = org.nativescript.widgets.ImageView;
5351
}
5452
initializeImageLoadedListener();
55-
53+
5654
const imageView = new AndroidImageView(this._context);
5755
const listener = new ImageLoadedListener(this);
5856
imageView.setImageLoadedListener(listener);
@@ -73,7 +71,7 @@ export class Image extends ImageBase {
7371

7472
public resetNativeView(): void {
7573
super.resetNativeView();
76-
this.nativeViewProtected.setImageMatrix(new android.graphics.Matrix());
74+
this.nativeViewProtected.setImageMatrix(new android.graphics.Matrix());
7775
}
7876

7977
public _createImageSourceFromSrc(value: string | ImageSource | ImageAsset) {
@@ -89,8 +87,8 @@ export class Image extends ImageBase {
8987

9088
let screen = platform.screen.mainScreen;
9189

92-
let decodeWidth = Math.min(this.decodeWidth, screen.widthPixels);
93-
let decodeHeight = Math.min(this.decodeHeight, screen.heightPixels);
90+
let decodeWidth = Math.min(Length.toDevicePixels(this.decodeWidth, 0), screen.widthPixels);
91+
let decodeHeight = Math.min(Length.toDevicePixels(this.decodeHeight, 0), screen.heightPixels);
9492
let keepAspectRatio = this._calculateKeepAspectRatio();
9593
if (value instanceof ImageAsset) {
9694
if (value.options) {

0 commit comments

Comments
 (0)