gronxb / webview-bridge

Fully Type-Safe Integration for React Native WebView and Web
https://gronxb.github.io/webview-bridge/
MIT License
197 stars 5 forks source link

Feature: bridge isReady event or callback #18

Closed codecomeon closed 7 months ago

codecomeon commented 7 months ago

A common scene is that:

When web page ready, app inject some data into web. Otherwise, app should prepare some async environment when web already done. For example lazy load modules in app, loading process will cost times.

Suggestion API Design:

codecomeon commented 7 months ago

Or app should show loading before bridge ready, and hide loading when bridge ready.

gronxb commented 7 months ago

Thank you!

https://gronxb.github.io/webview-bridge/using-a-native-method.html#checking-webview-bridge-availability

Something similar exists here, but it's not reactive. It sounds like what you want is to observe the ready state either event-driven or state-driven so that it can work reactively.

I'll try to prepare that suggestion as well.

gronxb commented 7 months ago

Releaesd in v1.2.0.

Simle Usage

const nativeMethod = linkNativeMethod<AppBridge>({
  onReady: async (method) => {
    console.log("nativeMethod is ready");
    const version = await method.getBridgeVersion();
    console.log("currentBridgerVersion", version);
  },
});

However, integration with the state of each framework is not yet ready. Since it will be further integrated into the shared state, the issue will not be closed.

gronxb commented 7 months ago

Shared state was released in v1.3.1. So you can use states like isReady to hide or show the UI. 🥰

https://gronxb.github.io/webview-bridge/shared-state/react-native.html