Skip to content

Commit d43c9e8

Browse files
Ty3uKa7ul
authored andcommitted
Add transformationMode to RNView (#92)
* Add `transformationMode` to RNView * Fix applying resize props
1 parent ca76074 commit d43c9e8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/components/Image/RNImage.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
QPixmap,
44
AspectRatioMode,
55
NodeWidget,
6-
QSize
6+
QSize,
7+
TransformationMode
78
} from "@nodegui/nodegui";
89
import { TextProps, setTextProps } from "../Text/RNText";
910
import { RNWidget } from "../config";
@@ -13,6 +14,7 @@ import phin from "phin";
1314
export interface ImageProps extends TextProps {
1415
src?: string;
1516
aspectRatioMode?: AspectRatioMode;
17+
transformationMode?: TransformationMode;
1618
buffer?: Buffer;
1719
}
1820

@@ -37,6 +39,9 @@ const setImageProps = (
3739
},
3840
set aspectRatioMode(mode: AspectRatioMode) {
3941
widget.setAspectRatioMode(mode);
42+
},
43+
set transformationMode(mode: TransformationMode) {
44+
widget.setTransformationMode(mode);
4045
}
4146
};
4247
Object.assign(setter, newProps);
@@ -65,6 +70,7 @@ export class RNImage extends QLabel implements RNWidget {
6570
static tagName = "image";
6671
originalPixmap?: QPixmap;
6772
aspectRatioMode?: AspectRatioMode;
73+
transformationMode?: TransformationMode;
6874
setPixmap = (pixmap: QPixmap) => {
6975
// react:✓
7076
super.setPixmap(pixmap);
@@ -73,14 +79,21 @@ export class RNImage extends QLabel implements RNWidget {
7379
setAspectRatioMode(mode: AspectRatioMode) {
7480
// react:✓ TODO://getter
7581
this.aspectRatioMode = mode;
82+
this.scalePixmap(this.size());
83+
}
84+
setTransformationMode(mode: TransformationMode) {
85+
// react:✓ TODO://getter
86+
this.transformationMode = mode;
87+
this.scalePixmap(this.size());
7688
}
7789
scalePixmap(size: QSize) {
7890
if (this.originalPixmap) {
7991
return super.setPixmap(
8092
this.originalPixmap.scaled(
8193
size.width(),
8294
size.height(),
83-
this.aspectRatioMode
95+
this.aspectRatioMode,
96+
this.transformationMode
8497
)
8598
);
8699
}

0 commit comments

Comments
 (0)