Loading: Native Loading Control

更新时间:
2024-06-19
下载文档

Loading: Native Loading Control

The loading module provides an interface for applications to creat a loading instance.

Developers can determine whether this interface work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error);
});

Every Loading application starts by creating a new loading instance with the create function:

edger.loading.create([duration])

The parameters of create method include:

  • duration {Number} Time required to load animation once. Default: 0(loading will be permanent and will not be closed). Unit: milliseconds(ms). Optional.
  • Returns: {Object} Loading instance object.

Now we can instantiate a loading object:

// Loading instance object
const loading = edger.loading.create(5000)

Once instantiated, we can call methods on the instance as follows:

loading.present()

Show the loading.

  • Returns: {Promise<{id: string}>} Promise object.

The returned object can contain the following member:

  • id {String} Loading ID, the unique identifier of loading.

Example

loading.present().then((payload) => {
  console.log("loading present successful, id:", payload.id);
}).catch((error) => {
  console.error(error);
});

async / await

async function present() {
  try {
    await loading.present();
  } catch (error) {
    console.error(error);
  }
}

loading.dismiss()

Close the loading.

  • Returns: {Promise<{id: string}>} Promise object.

The returned object can contain the following member:

  • id {String} Loading ID, the unique identifier of loading.

Example

loading.dismiss().then((payload) => {
  console.log("loading dismiss successful, id:", payload.id);
}).catch((error) => {
  console.error(error);
});

async / await

async function dismiss() {
  try {
    await loading.dismiss();
  } catch (error) {
    console.error(error);
  }
}
文档内容是否对您有所帮助?
有帮助
没帮助