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

@@ -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
}

View File

@@ -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

View File

@@ -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>) {