Skip to content

feat: allow modifying image scale on iOS #10214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/core/image-source/index.android.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/image-source/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion packages/core/image-source/index.ios.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down