Skip to content

Commit

Permalink
feat: Add types to getHostComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 15, 2025
1 parent 19b6b9a commit 2410f70
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import type { HostComponent } from 'react-native'
// @ts-expect-error this unfortunately isn't typed or default-exported.
import * as NativeComponentRegistry from 'react-native/Libraries/NativeComponent/NativeComponentRegistry'

interface ViewConfig<Props> {
uiViewClassName: string
supportsRawText?: boolean
bubblingEventTypes: Record<string, unknown>
directEventTypes: Record<string, unknown>
validAttributes: Record<keyof Props, true>
}

/**
* Finds and returns a native view (aka {@linkcode HostComponent}) via the given {@linkcode name}.
*/
export function getHostComponent<Props>(
name: string,
getViewConfig: () => object
getViewConfig: () => ViewConfig<Props>
): HostComponent<Props> {
return NativeComponentRegistry.get<Props>(name, getViewConfig)
}

0 comments on commit 2410f70

Please sign in to comment.