add resId to cache DoricResource on native
This commit is contained in:
7
doric-js/lib/src/native/imageDecoder.d.ts
vendored
7
doric-js/lib/src/native/imageDecoder.d.ts
vendored
@@ -1,6 +1,9 @@
|
||||
import { Resource } from "../util/resource";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function imageDecoder(context: BridgeContext): {
|
||||
getBitmapInfo: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
decodeToPixels: (resource: Resource) => Promise<ArrayBuffer>;
|
||||
decode: (resource: Resource) => Promise<{
|
||||
width: number;
|
||||
height: number;
|
||||
format: string;
|
||||
}>;
|
||||
};
|
||||
|
@@ -13,13 +13,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
export function imageDecoder(context) {
|
||||
return {
|
||||
getBitmapInfo: (resource) => {
|
||||
return context.callNative('imageDecoder', 'getBitmapInfo', resource);
|
||||
},
|
||||
decodeToPixels: (resource) => {
|
||||
return context.callNative('imageDecoder', 'decode', resource);
|
||||
},
|
||||
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 });
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
2
doric-js/lib/src/util/resource.d.ts
vendored
2
doric-js/lib/src/util/resource.d.ts
vendored
@@ -2,8 +2,10 @@ import { Modeling } from "./types";
|
||||
export declare abstract class Resource implements Modeling {
|
||||
type: string;
|
||||
identifier: string;
|
||||
resId: string;
|
||||
constructor(type: string, identifier: string);
|
||||
toModel(): {
|
||||
resId: string;
|
||||
type: string;
|
||||
identifier: string;
|
||||
};
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import { uniqueId } from "./uniqueId";
|
||||
export class Resource {
|
||||
constructor(type, identifier) {
|
||||
this.resId = uniqueId("resource");
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
toModel() {
|
||||
return {
|
||||
resId: this.resId,
|
||||
type: this.type,
|
||||
identifier: this.identifier,
|
||||
};
|
||||
|
Reference in New Issue
Block a user