mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
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:

committed by
GitHub

parent
92148833d3
commit
6509efa430
@ -1,5 +1,5 @@
|
|||||||
import { Image as ImageDefinition, Stretch } from ".";
|
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 { ImageAsset } from "../../image-asset";
|
||||||
import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source";
|
import { ImageSource, fromAsset, fromNativeSource, fromUrl } from "../../image-source";
|
||||||
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils";
|
import { isDataURI, isFileOrResourcePath, RESOURCE_PREFIX } from "../../utils/utils";
|
||||||
@ -13,6 +13,8 @@ export abstract class ImageBase extends View implements ImageDefinition {
|
|||||||
public isLoading: boolean;
|
public isLoading: boolean;
|
||||||
public stretch: Stretch;
|
public stretch: Stretch;
|
||||||
public loadMode: "sync" | "async";
|
public loadMode: "sync" | "async";
|
||||||
|
public decodeWidth: Length;
|
||||||
|
public decodeHeight: Length;
|
||||||
|
|
||||||
get tintColor(): Color {
|
get tintColor(): Color {
|
||||||
return this.style.tintColor;
|
return this.style.tintColor;
|
||||||
@ -119,3 +121,9 @@ stretchProperty.register(ImageBase);
|
|||||||
|
|
||||||
export const tintColorProperty = new InheritedCssProperty<Style, Color>({ name: "tintColor", cssName: "tint-color", equalityComparer: Color.equals, valueConverter: (value) => new Color(value) });
|
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);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ImageSource, ImageAsset, ImageBase, stretchProperty, imageSourceProperty, srcProperty, tintColorProperty, Color,
|
ImageSource, ImageAsset, ImageBase, stretchProperty, imageSourceProperty, srcProperty, tintColorProperty, Color,
|
||||||
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX
|
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX, Length
|
||||||
} from "./image-common";
|
} from "./image-common";
|
||||||
import { knownFolders } from "../../file-system";
|
import { knownFolders } from "../../file-system";
|
||||||
|
|
||||||
@ -43,8 +43,6 @@ function initializeImageLoadedListener() {
|
|||||||
export class Image extends ImageBase {
|
export class Image extends ImageBase {
|
||||||
nativeViewProtected: org.nativescript.widgets.ImageView;
|
nativeViewProtected: org.nativescript.widgets.ImageView;
|
||||||
|
|
||||||
public decodeWidth = 0;
|
|
||||||
public decodeHeight = 0;
|
|
||||||
public useCache = true;
|
public useCache = true;
|
||||||
|
|
||||||
public createNativeView() {
|
public createNativeView() {
|
||||||
@ -89,8 +87,8 @@ export class Image extends ImageBase {
|
|||||||
|
|
||||||
let screen = platform.screen.mainScreen;
|
let screen = platform.screen.mainScreen;
|
||||||
|
|
||||||
let decodeWidth = Math.min(this.decodeWidth, screen.widthPixels);
|
let decodeWidth = Math.min(Length.toDevicePixels(this.decodeWidth, 0), screen.widthPixels);
|
||||||
let decodeHeight = Math.min(this.decodeHeight, screen.heightPixels);
|
let decodeHeight = Math.min(Length.toDevicePixels(this.decodeHeight, 0), screen.heightPixels);
|
||||||
let keepAspectRatio = this._calculateKeepAspectRatio();
|
let keepAspectRatio = this._calculateKeepAspectRatio();
|
||||||
if (value instanceof ImageAsset) {
|
if (value instanceof ImageAsset) {
|
||||||
if (value.options) {
|
if (value.options) {
|
||||||
|
Reference in New Issue
Block a user