# Tap event

Lift the user up after the mobile end finger is pressed, or in the tool/The PC side is defined as a time to lift after pressing the mouse Tap event. The tap event is basically based on the web Standard touch Event to do the encapsulation.

# Click state

To prevent the misuse of sensitive interfaces, part API When triggered, the click state is checked and consumed (e.g. wx.openSetting, wx.requestSubscribeMessage), and when the click state fails, the corresponding function is affected (call failure or degradation).

Each time the user clicks, the corresponding tap The event response function for the event gets the click state. In addition, the following API There are also click-states within the callback:

Click states are only valid within the macro task in which the current event response function is located. Therefore, setTimeout/setInterval The wrapped function does not have click-state, but Promise/async/await Inside effective.

Because iOS of Promise Implementation is problematic, the Mini Program uses polyfill of Promise。so iOS Under Use Promise/async/await Will lose the click state:

// <button bind:tap="handleTap" >tap</button>
handleTap:  async () => {
  // Clickable state
  setTimeout (() => {
    // Loss of click-state
  }, 100)
  Promise.resolve().then(() => {
    // Android With a click state, iOS Loss of click-state on
  })
}

in tap Making asynchronous requests in event handlers is a common behavior. when wx.request、wx.downloadFile or wx.getSetting Has a click state when called, it will continue the click state to success/complete/fail Callback function:

// <button bind:tap="handleTap" >tap</button>
handleTap:  async () => {
  // Clickable state
  wx.request({
    url: "https://www.thissitedoesnotexist.com /step1",
    complete: () => {
      // Clickable state
      wx.request({
        url: "https://www.thissitedoesnotexist.com /step2",
        complete: () => {
          // Clickable state
        },
      })
    },
  })
}

Single tap After the generated click state is consumed, the click state cannot be continued:

// <button bind:tap="handleTap" >tap</button>
handleTap:  async () => {
  // Clickable state
  wx.openSettings({}) // Successful call
  wx.request({
    url: "https://www.thissitedoesnotexist.com , 
    complete: () => {
      // Loss of the click-state, because the click state is wx.openSettings Consumed.
    },
  })
  wx.openSettings({}) // Successful call
}