|
1 | 1 | /// <reference path="../types/ios/index.d.ts" /> |
2 | 2 |
|
| 3 | +import type { |
| 4 | + ForwardRefExoticComponent, |
| 5 | + PropsWithoutRef, |
| 6 | + RefAttributes, |
| 7 | +} from 'react'; |
| 8 | +import type {ViewProps} from 'react-native'; |
| 9 | + |
3 | 10 | export type NativeApiHost = { |
4 | 11 | runtime?: string; |
5 | 12 | backend?: string; |
@@ -30,20 +37,49 @@ export type InstallOptions = { |
30 | 37 | globals?: boolean; |
31 | 38 | }; |
32 | 39 |
|
| 40 | +export type UIKitViewDefinition<Props extends object, NativeView = unknown> = { |
| 41 | + displayName?: string; |
| 42 | + create: (props: Readonly<Props & ViewProps>) => NativeView; |
| 43 | + update?: ( |
| 44 | + view: NativeView, |
| 45 | + props: Readonly<Props & ViewProps>, |
| 46 | + previousProps?: Readonly<Props & ViewProps>, |
| 47 | + ) => void; |
| 48 | + mounted?: (view: NativeView, props: Readonly<Props & ViewProps>) => void; |
| 49 | + dispose?: (view: NativeView, props: Readonly<Props & ViewProps>) => void; |
| 50 | + nativeProps?: ( |
| 51 | + props: Readonly<Props & ViewProps>, |
| 52 | + ) => Partial<ViewProps> | undefined; |
| 53 | +}; |
| 54 | + |
| 55 | +export type UIKitViewRef<NativeView = unknown> = { |
| 56 | + readonly nativeView: NativeView | null; |
| 57 | + runOnUI: (callback: (view: NativeView) => void) => Promise<void>; |
| 58 | +}; |
| 59 | + |
| 60 | +export type UIKitViewComponent<Props extends object, NativeView = unknown> = |
| 61 | + ForwardRefExoticComponent< |
| 62 | + PropsWithoutRef<Props & ViewProps> & RefAttributes<UIKitViewRef<NativeView>> |
| 63 | + >; |
| 64 | + |
33 | 65 | export function init(metadataPath?: string, options?: InstallOptions): boolean; |
34 | 66 | export const install: typeof init; |
35 | 67 | export function installGlobals(): boolean; |
36 | 68 | export function isInstalled(): boolean; |
37 | 69 | export function defaultMetadataPath(): string; |
38 | 70 | export function getRuntimeBackend(): string; |
39 | 71 | export function runOnUI(callback?: () => void): Promise<void>; |
| 72 | +export function defineUIKitView<Props extends object, NativeView = unknown>( |
| 73 | + definition: UIKitViewDefinition<Props, NativeView>, |
| 74 | +): UIKitViewComponent<Props, NativeView>; |
40 | 75 |
|
41 | 76 | declare const NativeScript: { |
42 | 77 | init: typeof init; |
43 | 78 | install: typeof install; |
44 | 79 | installGlobals: typeof installGlobals; |
45 | 80 | isInstalled: typeof isInstalled; |
46 | 81 | defaultMetadataPath: typeof defaultMetadataPath; |
| 82 | + defineUIKitView: typeof defineUIKitView; |
47 | 83 | getRuntimeBackend: typeof getRuntimeBackend; |
48 | 84 | runOnUI: typeof runOnUI; |
49 | 85 | }; |
|
0 commit comments