feat:android support ArrayBuffer Resource

This commit is contained in:
pengfei.zhou
2021-11-18 19:06:10 +08:00
committed by osborn
parent 3bedd8034c
commit e270b9c520
21 changed files with 481 additions and 59 deletions

View File

@@ -1,9 +1,10 @@
import { Resource } from "../util/resource";
import { BridgeContext } from "../runtime/global";
export declare function imageDecoder(context: BridgeContext): {
decode: (resource: Resource) => Promise<{
getImageInfo: (resource: Resource) => Promise<{
width: number;
height: number;
format: string;
mimeType: string;
}>;
decodeToPixels: (resource: Resource) => Promise<ArrayBuffer>;
};

View File

@@ -24,12 +24,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
export function imageDecoder(context) {
return {
decode: (resource) => __awaiter(this, void 0, void 0, function* () {
yield context.callNative('imageDecoder', 'loadResource', resource);
const imageInfo = yield context.callNative('imageDecoder', 'getImageInfo', resource.resId);
const pixels = yield context.callNative('imageDecoder', 'decodeToPixels', resource.resId);
yield context.callNative('imageDecoder', 'releaseResource', resource.resId);
return Object.assign(Object.assign({}, imageInfo), { pixels });
getImageInfo: (resource) => {
return context.callNative('imageDecoder', 'getImageInfo', resource);
},
decodeToPixels: (resource) => __awaiter(this, void 0, void 0, function* () {
return context.callNative('imageDecoder', 'decodeToPixels', resource);
}),
};
}

View File

@@ -11,3 +11,4 @@ export * from './coordinator';
export * from './notch';
export * from './keyboard';
export * from './resourceLoader';
export * from './imageDecoder';

View File

@@ -26,3 +26,4 @@ export * from './coordinator';
export * from './notch';
export * from './keyboard';
export * from './resourceLoader';
export * from './imageDecoder';

View File

@@ -50,3 +50,6 @@ export declare class MainBundleResource extends iOSResource {
export declare class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string);
}
export declare class ArrayBufferResource extends Resource {
constructor(data: ArrayBuffer);
}

View File

@@ -71,3 +71,8 @@ export class BundleResource extends iOSResource {
super("bundle", `${bundleName}://${fileName}`);
}
}
export class ArrayBufferResource extends Resource {
constructor(data) {
super("arrayBuffer", "");
}
}