React Native · APIs and utilities
Native modules
The native module.
Import
requireNativeModule
functionThe native module. Throws a clear error if the module is not in the build; for optional use see requireOptionalNativeModule.
The returned object is lazy: the module is resolved on first property access. So writing export const X = requireNativeModule(...) at the top of a module file is safe (importing it does not throw on web or in tests).
NativeModuleError
classAn error coming from the native side.
requireOptionalNativeModule
functionThe native module; null if it is not in this build. The module is resolved once on first call and cached.
isNativeModuleAvailable
functionWhether the module is in this build.
nativeModuleNames
functionNames of all native modules in this build.
requireNativeView
functionTurns a module's native view into a React component. Props (non-function) go to the native view's setProps method as JSON; a native emit("ready", …) event calls the onReady prop.
Examples
EventSubscription
interfaceAn event subscription.
| Name | Type | Description |
|---|---|---|
remove | (): void | Removes the listener. |
ModuleEvents
typeEvent name → event data mapping.
NativeModuleBase
interfaceMembers shared by every module.
| Name | Type | Description |
|---|---|---|
moduleName | string | JS name of the module. |
NativeModule
typeA typed native module: the interface you defined + the shared members.
Extends: T
| Name | Type | Description |
|---|---|---|
moduleName | string | JS name of the module. |
NativeViewHandle
interfaceHandle of the view: this id is passed to module functions.
| Name | Type | Description |
|---|---|---|
instanceId | string | Id of the view instance (Camera.takePicture(ref.current.instanceId)). |
NativeViewProps
interfaceProps shared by every module view.
| Name | Type | Description |
|---|---|---|
style? | StyleProp<ViewStyle> | View style (do not forget to give a size; the content fills the whole area). |
testID? | string | Test id. |
onLayout? | (event: LayoutChangeEvent) => void | When the layout changes. |
ref? | Ref<NativeViewHandle> | Handle (instanceId). |