feat: allow modifying image scale on iOS

This commit is contained in:
Eduardo Speroni
2023-02-15 12:24:56 -03:00
parent e0a4c887ef
commit 4d8705ad39
3 changed files with 32 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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;
}
/**

View File

@@ -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 {