UNPKG

@ohmi/react-native-image-capinsets-next

Version:
115 lines (92 loc) 3.51 kB
/** * This code was generated by "react-native codegen-lib-harmony" */ import { Descriptor as ComponentDescriptor, ViewBaseProps, ViewRawProps, ViewDescriptorWrapperBase, ColorValue, Color, RNInstance, Tag, RNComponentCommandReceiver, ViewPropsSelector, } from '@rnoh/react-native-openharmony/ts'; export namespace RNCImageCapInsets { export const NAME = "RNCImageCapInsets" as const export interface DirectRawProps { source: {uri?: string, bundle?: string, method?: string, headers?: {name: string, value: string}[], cache?: 'default' | 'reload' | 'force-cache' | 'only-if-cached', body?: string, width?: number, height?: number, scale?: number}; capInsets: {top?: number, left?: number, right?: number, bottom?: number}; } export interface Props extends ViewBaseProps {} export interface State {} export interface RawProps extends ViewRawProps, DirectRawProps {} export class PropsSelector extends ViewPropsSelector<Props, RawProps> { get source() { return this.rawProps.source; } get capInsets() { return this.rawProps.capInsets; } } export type Descriptor = ComponentDescriptor< typeof NAME, Props, State, RawProps >; export class DescriptorWrapper extends ViewDescriptorWrapperBase< typeof NAME, Props, State, RawProps, PropsSelector > { protected createPropsSelector() { return new PropsSelector(this.descriptor.props, this.descriptor.rawProps) } } export interface EventPayloadByName { } export class EventEmitter { constructor(private rnInstance: RNInstance, private tag: Tag) {} emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) { this.rnInstance.emitComponentEvent(this.tag, eventName, payload) } } export interface CommandArgvByName { } export class CommandReceiver { private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>() private cleanUp: (() => void) | undefined = undefined constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) { } subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) { if (!this.listenersByCommandName.has(commandName)) { this.listenersByCommandName.set(commandName, new Set()) } this.listenersByCommandName.get(commandName)!.add(listener) const hasRegisteredCommandReceiver = !!this.cleanUp if (!hasRegisteredCommandReceiver) { this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => { if (this.listenersByCommandName.has(commandName)) { const listeners = this.listenersByCommandName.get(commandName)! listeners.forEach(listener => { listener(argv) }) } }) } return () => { this.listenersByCommandName.get(commandName)?.delete(listener) if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) { this.listenersByCommandName.delete(commandName) } if (this.listenersByCommandName.size === 0) { this.cleanUp?.() } } } } }