iOS: implement Image Pixel
This commit is contained in:
@@ -2316,7 +2316,30 @@ var Image = /** @class */ (function (_super) {
|
||||
Image.prototype.getImagePixels = function (context) {
|
||||
return this.nativeChannel(context, "getImagePixels")();
|
||||
};
|
||||
<<<<<<< HEAD
|
||||
__decorate$b([
|
||||
=======
|
||||
Image.prototype.setImagePixels = function (context, imagePixels) {
|
||||
if (Environment.platform === 'iOS') {
|
||||
imagePixels.pixels = context.function2Id(function () {
|
||||
return imagePixels.pixels;
|
||||
});
|
||||
}
|
||||
return this.nativeChannel(context, "setImagePixels")(imagePixels);
|
||||
};
|
||||
Image.prototype.toModel = function () {
|
||||
var ret = _super.prototype.toModel.call(this);
|
||||
if (Environment.platform === 'iOS') {
|
||||
if (Reflect.has(ret.props, "imagePixels")) {
|
||||
var imagePixels = Reflect.get(ret.props, "imagePixels");
|
||||
var pixels_1 = imagePixels.pixels;
|
||||
imagePixels.pixels = this.callback2Id(function () { return pixels_1; });
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
__decorate$a([
|
||||
>>>>>>> 60c3fff0... iOS: implement Image Pixel
|
||||
Property,
|
||||
__metadata$b("design:type", Object)
|
||||
], Image.prototype, "imagePixels", void 0);
|
||||
|
@@ -1726,6 +1726,25 @@ 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$b([
|
||||
Property,
|
||||
|
@@ -3254,6 +3254,25 @@ 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$b([
|
||||
Property,
|
||||
|
9
doric-js/index.d.ts
vendored
9
doric-js/index.d.ts
vendored
@@ -248,6 +248,7 @@ declare module 'doric/lib/src/ui/view' {
|
||||
onClick?: Function;
|
||||
superview?: Superview;
|
||||
callbacks: Map<String, Function>;
|
||||
callback2Id(f: Function): string;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
constructor();
|
||||
/** Anchor start*/
|
||||
@@ -616,7 +617,7 @@ declare module 'doric/lib/src/widget/text' {
|
||||
}
|
||||
|
||||
declare module 'doric/lib/src/widget/image' {
|
||||
import { View } from "doric/lib/src/ui/view";
|
||||
import { View, NativeViewModel } from "doric/lib/src/ui/view";
|
||||
import { Color } from "doric/lib/src/util/color";
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
import { Resource } from "doric/lib/src/util/resource";
|
||||
@@ -713,6 +714,12 @@ declare module 'doric/lib/src/widget/image' {
|
||||
mimeType: string;
|
||||
}>;
|
||||
getImagePixels(context: BridgeContext): Promise<ArrayBuffer>;
|
||||
setImagePixels(context: BridgeContext, imagePixels: {
|
||||
width: number;
|
||||
height: number;
|
||||
pixels: ArrayBuffer;
|
||||
}): Promise<void>;
|
||||
toModel(): NativeViewModel;
|
||||
}
|
||||
export function image(config: Partial<Image>): Image;
|
||||
}
|
||||
|
2
doric-js/lib/src/ui/view.d.ts
vendored
2
doric-js/lib/src/ui/view.d.ts
vendored
@@ -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();
|
||||
|
8
doric-js/lib/src/widget/image.d.ts
vendored
8
doric-js/lib/src/widget/image.d.ts
vendored
@@ -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;
|
||||
|
@@ -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,
|
||||
|
@@ -144,7 +144,8 @@ export abstract class View implements Modeling {
|
||||
superview?: Superview
|
||||
|
||||
callbacks!: Map<String, Function>
|
||||
private callback2Id(f: Function) {
|
||||
|
||||
callback2Id(f: Function) {
|
||||
if (this.callbacks === undefined) {
|
||||
this.callbacks = new Map
|
||||
}
|
||||
|
@@ -129,7 +129,7 @@ export abstract class View implements Modeling {
|
||||
|
||||
callbacks: Map<String, Function> = new Map
|
||||
|
||||
private callback2Id(f: Function) {
|
||||
callback2Id(f: Function) {
|
||||
const id = uniqueId('Function')
|
||||
this.callbacks.set(id, f)
|
||||
return id
|
||||
|
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { View, Property } from "../ui/view"
|
||||
import { View, Property, NativeViewModel } from "../ui/view"
|
||||
import { layoutConfig } from "../util/layoutconfig"
|
||||
import { Color } from "../util/color"
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
@@ -149,6 +149,34 @@ export class Image extends View {
|
||||
getImagePixels(context: BridgeContext): Promise<ArrayBuffer> {
|
||||
return this.nativeChannel(context, "getImagePixels")()
|
||||
}
|
||||
|
||||
setImagePixels(
|
||||
context: BridgeContext,
|
||||
imagePixels: {
|
||||
width: number,
|
||||
height: number,
|
||||
pixels: ArrayBuffer
|
||||
}): Promise<void> {
|
||||
if (Environment.platform === 'iOS') {
|
||||
(imagePixels.pixels as unknown as any) = 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
|
||||
}
|
||||
}
|
||||
|
||||
export function image(config: Partial<Image>) {
|
||||
|
Reference in New Issue
Block a user