mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: allow modifying image scale on iOS
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Definitions.
|
||||
import { ImageSource as ImageSourceDefinition } from '.';
|
||||
import type { ImageSource as ImageSourceDefinition } from '.';
|
||||
import { ImageAsset } from '../image-asset';
|
||||
import * as httpModule from '../http';
|
||||
|
||||
@@ -69,6 +69,10 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
this._rotationAngle = value;
|
||||
}
|
||||
|
||||
get scale(): number {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
constructor(nativeSource?: any) {
|
||||
if (nativeSource) {
|
||||
this.setNativeSource(nativeSource);
|
||||
@@ -408,6 +412,10 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public withScaleFactor(newScale: number): ImageSource {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetFormat(format: 'png' | 'jpeg' | 'jpg'): android.graphics.Bitmap.CompressFormat {
|
||||
|
||||
11
packages/core/image-source/index.d.ts
vendored
11
packages/core/image-source/index.d.ts
vendored
@@ -20,6 +20,11 @@ export class ImageSource {
|
||||
*/
|
||||
rotationAngle: number;
|
||||
|
||||
/**
|
||||
* Gets the scale factor of the image (iOS only).
|
||||
*/
|
||||
readonly scale: number;
|
||||
|
||||
/**
|
||||
* The iOS-specific [UIImage](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/) instance. Will be undefined when running on Android.
|
||||
*/
|
||||
@@ -245,6 +250,12 @@ export class ImageSource {
|
||||
* bilinear filtering is typically minimal and the improved image quality is significant.
|
||||
*/
|
||||
resizeAsync(maxSize: number, options?: any): Promise<ImageSource>;
|
||||
|
||||
/**
|
||||
* iOS Only. Creates a new ImageSource from the original UIImage but with a different scale factor.
|
||||
* @param newScale The new scale of the image.
|
||||
*/
|
||||
withScaleFactor(newScale: number): ImageSource;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Definitions.
|
||||
import { ImageSource as ImageSourceDefinition } from '.';
|
||||
import type { ImageSource as ImageSourceDefinition } from '.';
|
||||
import { ImageAsset } from '../image-asset';
|
||||
import * as httpModule from '../http';
|
||||
import { Font } from '../ui/styling/font';
|
||||
@@ -49,6 +49,13 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
// compatibility with Android
|
||||
}
|
||||
|
||||
get scale(): number {
|
||||
if (this.ios) {
|
||||
return this.ios.scale;
|
||||
}
|
||||
return NaN;
|
||||
}
|
||||
|
||||
constructor(nativeSource?: any) {
|
||||
if (nativeSource) {
|
||||
this.setNativeSource(nativeSource);
|
||||
@@ -434,6 +441,10 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public withScaleFactor(newScale: number): ImageSource {
|
||||
return new ImageSource(UIImage.imageWithCGImageScaleOrientation(this.ios.CGImage, newScale, this.ios.imageOrientation));
|
||||
}
|
||||
}
|
||||
|
||||
function getFileName(path: string): string {
|
||||
|
||||
Reference in New Issue
Block a user