UNPKG

@react-native-webview-rpc/web

Version:

A type-safe RPC between React Native function and JavaScript inside WebView, powered by Comlink

44 lines (35 loc) 1.56 kB
import * as Comlink from 'comlink'; import { RefObject } from 'react'; import WebView from 'react-native-webview'; import { WebViewMessageEvent } from 'react-native-webview'; /** * An endpoint of communicating with WebView */ declare function createWebViewRpcEndpoint(ref: RefObject<WebView | null>): WebViewEndpoint; export { createWebViewRpcEndpoint } export { createWebViewRpcEndpoint as createWebViewRpcEndpoint_alias_1 } declare function safeWrap<Rpcs>(): Comlink.Remote<Rpcs> | null; export { safeWrap } export { safeWrap as safeWrap_alias_1 } declare const SYMBOL_IGNORING_RPC_RESPONSE_ERROR: symbol; export { SYMBOL_IGNORING_RPC_RESPONSE_ERROR } export { SYMBOL_IGNORING_RPC_RESPONSE_ERROR as SYMBOL_IGNORING_RPC_RESPONSE_ERROR_alias_1 } /** * Returns a handler of RPC message from WebView. */ declare function useWebViewRpcHandler<Rpcs>(webViewRef: RefObject<WebView | null>, rpcs: Rpcs): (event: WebViewMessageEvent) => void; export { useWebViewRpcHandler } export { useWebViewRpcHandler as useWebViewRpcHandler_alias_1 } export declare type WebViewEndpoint = Comlink.Endpoint & { /** * Manually distribute events to listeners as an alternative to `document.addEventHandler` which is unavailable in React Native. */ onMessage: (e: WebViewMessageEvent) => void; }; declare const webViewRpcEndpoint: Comlink.Endpoint; export { webViewRpcEndpoint } export { webViewRpcEndpoint as webViewRpcEndpoint_alias_1 } declare function wrap<Rpcs>(): Comlink.Remote<Rpcs>; export { wrap } export { wrap as wrap_alias_1 } export { }