Toast: Mobile Native Toast Control

更新时间:
2024-07-05
下载文档

Toast: Mobile Native Toast Control

The toast module provides an interface for applications to access toast. Toast is a lightweight prompt method that does not interrupt user operations and can provide feedback information such as success, warnings, and errors.

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);
});

Functions

edger.toast.present(message[, option])

Display a toast.

  • message {String} The content of toast.
  • option {Object} The configuration of toast. Optional.
  • Returns: {Promise} Fulfill with undefined success.

The option is an object, it can contain the following members:

  • duration {Number} The time required to complete the toast animation once. Default: 3000. Unit: millisecond(ms). Optional.
  • position {String} The position of toast. Optional values: top | center | bottom. Default: top. Optional.
  • actions: {Object} Toast right functional action. Optional.

The actions is an object, it can contain the following members:

  • code {String} The code of action.
  • label {String} The label of action.

Example

var option = {
  duration: 5000,
  position: 'top'
};

edger.toast.present('Hello, EdgerOS!', option).then(() => {
  console.log("toast show successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function toastPresent() {
  try {
    const option = {
      duration: 5000,
      position: 'top'
    };
    await edger.toast.present('Hello, EdgerOS!', option);
    console.log("toast show successful");
  } catch (error) {
    console.error(error);
  }
}

Events

The unified event listener provided by Web-SDK:

const listener = (payload) => {
  // Event handling...
}

// add listener
edger.toast.addEventListener('some-event', listener);

// remove listener
edger.toast.removeEventListener('some-event', listener);

// remove all listeners
edger.toast.removeAllListeners();

action

This event will be called when the action's label is clicked.

  • Returns: {<{code: String}>} The code is the same as the passed in code.

Example

edger.toast.addEventListener('action', (payload) => {
  edger.notify.info(`toast code: ${payload.code}`);
})
文档内容是否对您有所帮助?
有帮助
没帮助