fix(android-images): set decodeHeight/decodeWidth default values to dip (#5490)

BREAKING CHANGE: change decodeHeight/decodeWidth properties to accept device independent pixels by default
This commit is contained in:
Alexander Djenkov
2018-03-07 15:56:28 +02:00
committed by GitHub
parent 92148833d3
commit 6509efa430
2 changed files with 15 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import { Image as ImageDefinition, Stretch } from ".";
import { View, Property, InheritedCssProperty, Style, Color, isIOS, booleanConverter } from "../core/view";
import { View, Property, InheritedCssProperty, Length, Style, Color, isIOS, booleanConverter } from "../core/view";
import { ImageAsset } from "../../image-asset";
import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source";
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils";
@ -13,6 +13,8 @@ export abstract class ImageBase extends View implements ImageDefinition {
public isLoading: boolean;
public stretch: Stretch;
public loadMode: "sync" | "async";
public decodeWidth: Length;
public decodeHeight: Length;
get tintColor(): Color {
return this.style.tintColor;
@ -118,4 +120,10 @@ export const stretchProperty = new Property<ImageBase, Stretch>({ name: "stretch
stretchProperty.register(ImageBase);
export const tintColorProperty = new InheritedCssProperty<Style, Color>({ name: "tintColor", cssName: "tint-color", equalityComparer: Color.equals, valueConverter: (value) => new Color(value) });
tintColorProperty.register(Style);
tintColorProperty.register(Style);
export const decodeHeightProperty = new Property<ImageBase, Length>({ name: "decodeHeight", defaultValue: { value: 0, unit: "dip" }, valueConverter: Length.parse });
decodeHeightProperty.register(ImageBase);
export const decodeWidthProperty = new Property<ImageBase, Length>({ name: "decodeWidth", defaultValue: { value: 0, unit: "dip" }, valueConverter: Length.parse });
decodeWidthProperty.register(ImageBase);

View File

@ -1,6 +1,6 @@
import {
ImageSource, ImageAsset, ImageBase, stretchProperty, imageSourceProperty, srcProperty, tintColorProperty, Color,
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX, Length
} from "./image-common";
import { knownFolders } from "../../file-system";
@ -43,8 +43,6 @@ function initializeImageLoadedListener() {
export class Image extends ImageBase {
nativeViewProtected: org.nativescript.widgets.ImageView;
public decodeWidth = 0;
public decodeHeight = 0;
public useCache = true;
public createNativeView() {
@ -52,7 +50,7 @@ export class Image extends ImageBase {
AndroidImageView = org.nativescript.widgets.ImageView;
}
initializeImageLoadedListener();
const imageView = new AndroidImageView(this._context);
const listener = new ImageLoadedListener(this);
imageView.setImageLoadedListener(listener);
@ -73,7 +71,7 @@ export class Image extends ImageBase {
public resetNativeView(): void {
super.resetNativeView();
this.nativeViewProtected.setImageMatrix(new android.graphics.Matrix());
this.nativeViewProtected.setImageMatrix(new android.graphics.Matrix());
}
public _createImageSourceFromSrc(value: string | ImageSource | ImageAsset) {
@ -89,8 +87,8 @@ export class Image extends ImageBase {
let screen = platform.screen.mainScreen;
let decodeWidth = Math.min(this.decodeWidth, screen.widthPixels);
let decodeHeight = Math.min(this.decodeHeight, screen.heightPixels);
let decodeWidth = Math.min(Length.toDevicePixels(this.decodeWidth, 0), screen.widthPixels);
let decodeHeight = Math.min(Length.toDevicePixels(this.decodeHeight, 0), screen.heightPixels);
let keepAspectRatio = this._calculateKeepAspectRatio();
if (value instanceof ImageAsset) {
if (value.options) {