Skip to content

Commit f91a432

Browse files
author
farfromrefug
committed
fix(android): correctly clean up android bitmaps
1 parent 5bcaaa2 commit f91a432

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/ui-carto/index.android.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-redeclare */
2-
import { Color, Font } from '@nativescript/core';
2+
import { Color, Font, ImageAsset, ImageSource } from '@nativescript/core';
33
import { NativePropertyOptions } from '.';
44
import { DefaultLatLonKeys, GenericMapPos, MapPos, MapPosVector, MapPosVectorVector, fromNativeMapVec, toNativeMapPos, toNativeMapVec } from './core';
55
import { Geometry } from './geometry';
@@ -9,6 +9,13 @@ import { BaseVectorElementStyleBuilder } from './vectorelements';
99
export { nativeProperty };
1010
export { BaseNative } from './BaseNative';
1111

12+
export function getCartoBitmap(src: string | ImageSource | ImageAsset) {
13+
const bitmap = _createImageSourceFromSrc(src);
14+
const result = com.carto.utils.BitmapUtils.createBitmapFromAndroidBitmap(bitmap.android as android.graphics.Bitmap);
15+
(bitmap.android as android.graphics.Bitmap).recycle();
16+
return result;
17+
}
18+
1219
export function nativeColorProperty(target: any, k?, desc?: PropertyDescriptor): any;
1320
export function nativeColorProperty(options: NativePropertyOptions): (target: any, k?, desc?: PropertyDescriptor) => any;
1421
export function nativeColorProperty(...args) {
@@ -96,8 +103,7 @@ export function nativeCartoImageProperty(...args) {
96103
return this.options[key];
97104
},
98105
toNative(value) {
99-
value = _createImageSourceFromSrc(value);
100-
return com.carto.utils.BitmapUtils.createBitmapFromAndroidBitmap(value.android as android.graphics.Bitmap);
106+
return getCartoBitmap(value);
101107
}
102108
}
103109
},

src/ui-carto/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable no-redeclare */
2-
import { Observable } from '@nativescript/core';
2+
import { ImageAsset, ImageSource, Observable } from '@nativescript/core';
33
import { DefaultLatLonKeys, GenericMapPos, MapPosVector, MapPosVectorVector } from './core';
44
import { Geometry } from './geometry';
55
import { FeatureCollection } from './geometry/feature';
66
import { BaseVectorElementStyleBuilder } from './vectorelements';
77

8+
export function getCartoBitmap(src: string | ImageSource | ImageAsset): any;
9+
810
// type BaseInterface<T> = {
911
// [K in keyof T]: T[K];
1012
// };

src/ui-carto/index.ios.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-redeclare */
2-
import { Color, Font } from '@nativescript/core';
2+
import { Color, Font, ImageAsset, ImageSource } from '@nativescript/core';
33
import { NativePropertyOptions } from '.';
44
import { DefaultLatLonKeys, MapPos, MapPosVector, MapPosVectorVector, fromNativeMapVec, toNativeMapPos, toNativeMapVec } from './core';
55
import { Geometry } from './geometry';
@@ -9,6 +9,11 @@ export { BaseNative } from './BaseNative';
99
import { BaseVectorElementStyleBuilder } from './vectorelements';
1010
export { nativeProperty };
1111

12+
export function getCartoBitmap(src: string | ImageSource | ImageAsset) {
13+
const bitmap = _createImageSourceFromSrc(src);
14+
return NTBitmapUtils.createBitmapFromUIImage(bitmap.ios as UIImage);
15+
}
16+
1217
export function nativeColorProperty(target: any, k?, desc?: PropertyDescriptor): any;
1318
export function nativeColorProperty(options: NativePropertyOptions): (target: any, k?, desc?: PropertyDescriptor) => any;
1419
export function nativeColorProperty(...args) {
@@ -93,8 +98,7 @@ export function nativeCartoImageProperty(...args) {
9398
return this.options[key];
9499
},
95100
toNative(value) {
96-
value = _createImageSourceFromSrc(value);
97-
return NTBitmapUtils.createBitmapFromUIImage(value.ios as UIImage);
101+
return getCartoBitmap(value);
98102
}
99103
}
100104
},

0 commit comments

Comments
 (0)