iOS: implement Image Pixel

This commit is contained in:
pengfei.zhou
2021-11-22 11:54:47 +08:00
committed by osborn
parent 190eb4afd7
commit b29f2d6a4e
20 changed files with 365 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ export declare abstract class View implements Modeling {
onClick?: Function;
superview?: Superview;
callbacks: Map<String, Function>;
private callback2Id;
callback2Id(f: Function): string;
private id2Callback;
findViewByTag(tag: string): View | undefined;
constructor();

View File

@@ -1,4 +1,4 @@
import { View } from "../ui/view";
import { View, NativeViewModel } from "../ui/view";
import { Color } from "../util/color";
import { BridgeContext } from "../runtime/global";
import { Resource } from "../util/resource";
@@ -95,5 +95,11 @@ export declare class Image extends View {
mimeType: string;
}>;
getImagePixels(context: BridgeContext): Promise<ArrayBuffer>;
setImagePixels(context: BridgeContext, imagePixels: {
width: number;
height: number;
pixels: ArrayBuffer;
}): Promise<void>;
toModel(): NativeViewModel;
}
export declare function image(config: Partial<Image>): Image;

View File

@@ -48,6 +48,25 @@ export class Image extends View {
getImagePixels(context) {
return this.nativeChannel(context, "getImagePixels")();
}
setImagePixels(context, imagePixels) {
if (Environment.platform === 'iOS') {
imagePixels.pixels = context.function2Id(() => {
return imagePixels.pixels;
});
}
return this.nativeChannel(context, "setImagePixels")(imagePixels);
}
toModel() {
const ret = super.toModel();
if (Environment.platform === 'iOS') {
if (Reflect.has(ret.props, "imagePixels")) {
const imagePixels = Reflect.get(ret.props, "imagePixels");
const pixels = imagePixels.pixels;
imagePixels.pixels = this.callback2Id(() => pixels);
}
}
return ret;
}
}
__decorate([
Property,