add resId to cache DoricResource on native
This commit is contained in:
@@ -2145,11 +2145,13 @@ var __extends$f = (undefined && undefined.__extends) || (function () {
|
||||
})();
|
||||
var Resource = /** @class */ (function () {
|
||||
function Resource(type, identifier) {
|
||||
this.resId = uniqueId("resource");
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
Resource.prototype.toModel = function () {
|
||||
return {
|
||||
resId: this.resId,
|
||||
type: this.type,
|
||||
identifier: this.identifier,
|
||||
};
|
||||
|
@@ -1610,11 +1610,13 @@ function text(config) {
|
||||
|
||||
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,
|
||||
};
|
||||
|
@@ -3138,11 +3138,13 @@ function text(config) {
|
||||
|
||||
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,
|
||||
};
|
||||
|
2
doric-js/index.d.ts
vendored
2
doric-js/index.d.ts
vendored
@@ -1688,8 +1688,10 @@ declare module 'doric/lib/src/util/resource' {
|
||||
export abstract class Resource implements Modeling {
|
||||
type: string;
|
||||
identifier: string;
|
||||
resId: string;
|
||||
constructor(type: string, identifier: string);
|
||||
toModel(): {
|
||||
resId: string;
|
||||
type: string;
|
||||
identifier: string;
|
||||
};
|
||||
|
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,
|
||||
};
|
||||
|
@@ -19,11 +19,26 @@ import { BridgeContext } from "../runtime/global"
|
||||
|
||||
export function imageDecoder(context: BridgeContext) {
|
||||
return {
|
||||
getBitmapInfo: (resource: Resource) => {
|
||||
return context.callNative('imageDecoder', 'getBitmapInfo', resource) as Promise<ArrayBuffer>
|
||||
},
|
||||
decodeToPixels: (resource: Resource) => {
|
||||
return context.callNative('imageDecoder', 'decode', resource) as Promise<ArrayBuffer>
|
||||
decode: async (resource: Resource) => {
|
||||
await context.callNative('imageDecoder', 'loadResource', resource);
|
||||
const imageInfo = await context.callNative(
|
||||
'imageDecoder',
|
||||
'getImageInfo',
|
||||
resource.resId) as Promise<
|
||||
{
|
||||
width: number,
|
||||
height: number,
|
||||
format: string,
|
||||
}>;
|
||||
const pixels = await context.callNative(
|
||||
'imageDecoder',
|
||||
'decodeToPixels',
|
||||
resource.resId) as Promise<ArrayBuffer>;
|
||||
await context.callNative('imageDecoder', 'releaseResource', resource.resId);
|
||||
return {
|
||||
...imageInfo,
|
||||
pixels,
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
@@ -1,14 +1,17 @@
|
||||
import { Modeling } from "./types";
|
||||
import { uniqueId } from "./uniqueId";
|
||||
|
||||
export abstract class Resource implements Modeling {
|
||||
type: string;
|
||||
identifier: string;
|
||||
resId = uniqueId("resource");
|
||||
constructor(type: string, identifier: string) {
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
toModel() {
|
||||
return {
|
||||
resId: this.resId,
|
||||
type: this.type,
|
||||
identifier: this.identifier,
|
||||
}
|
||||
|
Reference in New Issue
Block a user