Skip to content

Commit 50910b9

Browse files
committed
feat(image-colorfilter): works with N Image component
1 parent e9a53b8 commit 50910b9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/image-colorfilter/index.android.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { Img } from '@nativescript-community/ui-image';
2+
import { Image } from '@nativescript/core';
23
import { applyMixins, colorMatrixProperty, cssProperty } from './index-common';
34

45
class ImgExtended {
56
nativeImageViewProtected: com.nativescript.image.DraweeView;
7+
nativeViewProtected: com.nativescript.image.DraweeView;
68
@cssProperty colorMatrix: number[];
79
[colorMatrixProperty.setNative](value: number[]) {
10+
const nativeView = this.nativeImageViewProtected || this.nativeViewProtected;
811
if (!value) {
9-
this.nativeImageViewProtected.setColorFilter(null);
12+
nativeView.setColorFilter(null);
1013
return;
1114
}
1215
let arr = value;
@@ -16,12 +19,13 @@ class ImgExtended {
1619
arr[index] = value[index];
1720
}
1821
}
19-
this.nativeImageViewProtected.setColorFilter(new android.graphics.ColorMatrixColorFilter(arr));
22+
nativeView.setColorFilter(new android.graphics.ColorMatrixColorFilter(arr));
2023
}
2124
}
2225
let mixinInstalled = false;
2326
export function overrideImgBase() {
2427
applyMixins(Img, [ImgExtended], { override: true });
28+
applyMixins(Image, [ImgExtended], { override: true });
2529
}
2630

2731
export function installMixins() {

src/image-colorfilter/index.ios.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Img } from '@nativescript-community/ui-image';
22
import { applyMixins, colorMatrixProperty, cssProperty } from './index-common';
3+
import { Image } from '@nativescript/core';
34

45
declare module '@nativescript-community/ui-image' {
56
interface Img {}
@@ -40,6 +41,7 @@ class ImgExtended2 {
4041
}
4142
class ImgExtended3 {
4243
nativeImageViewProtected: SDAnimatedImageView | UIImageView;
44+
nativeViewProtected: SDAnimatedImageView | UIImageView;
4345
_oldImage: UIImage;
4446
_filter: CIFilter;
4547

@@ -67,7 +69,8 @@ class ImgExtended3 {
6769
return null;
6870
}
6971
applyColorFilter() {
70-
this.nativeImageViewProtected.image = this._applyColorFilter(this.nativeImageViewProtected.image);
72+
const nativeView = this.nativeImageViewProtected || this.nativeViewProtected;
73+
nativeView.image = this._applyColorFilter(nativeView.image);
7174
}
7275
public _setNativeImage(superCall, ...args) {
7376
this._oldImage = args[0];
@@ -83,6 +86,9 @@ export function overrideImgBase() {
8386
applyMixins(Img, [ImgExtended], { override: true });
8487
applyMixins(Img, [ImgExtended2]);
8588
applyMixins(Img, [ImgExtended3], { callWithSuper: true });
89+
applyMixins(Image, [ImgExtended], { override: true });
90+
applyMixins(Image, [ImgExtended2]);
91+
applyMixins(Image, [ImgExtended3], { callWithSuper: true });
8692
}
8793

8894
export function installMixins() {

0 commit comments

Comments
 (0)