github lynx-family/lynx-stack @lynx-js/web-core@0.7.0

latest releases: @lynx-js/offscreen-document@0.1.4, @lynx-js/cache-events-webpack-plugin@0.0.2, @lynx-js/web-constants@0.16.0...
6 months ago

Minor Changes

  • 1abf8f0: feat(web):

    This is a breaking change

    1. A new param for lynx-view: nativeModulesUrl, which allows you to pass an esm url to add a new module to NativeModules. And we bind the nativeModulesCall method to each function on the module, run this.nativeModulesCall() to trigger onNativeModulesCall.
    export type NativeModuleHandlerContext = {
      nativeModulesCall: (name: string, data: Cloneable) => Promise<Cloneable>;
    };

    a simple case:

    lynxView.nativeModules = URL.createObjectURL(
      new Blob(
        [
          `export default {
      myNativeModules: {
        async getColor(data, callback) {
          // trigger onNativeModulesCall and get the result
          const color = await this.nativeModulesCall('getColor', data);
          // return the result to caller
          callback(color);
        },
      }
    };`,
        ],
        { type: 'text/javascript' },
      ),
    );
    1. onNativeModulesCall is no longer the value handler of NativeModules.bridge.call, it will be the value handler of all NativeModules modules.

    Warning: This is a breaking change.

    Before this commit, you listen to NativeModules.bridge.call('getColor') like this:

    lynxView.onNativeModulesCall = (name, data, callback) => {
      if (name === 'getColor') {
        callback(data.color);
      }
    };

    Now you should use it like this:

    lynxView.onNativeModulesCall = (name, data, moduleName) => {
      if (name === 'getColor' && moduleName === 'bridge') {
        return data.color;
      }
    };

    You need to use moduleName to determine the NativeModules-module. And you don’t need to run callback, just return the result!

Patch Changes

  • Updated dependencies [1abf8f0]
    • @lynx-js/web-worker-runtime@0.7.0
    • @lynx-js/web-constants@0.7.0
    • @lynx-js/web-worker-rpc@0.7.0

Don't miss a new lynx-stack release

NewReleases is sending notifications on new releases.