# Tap event

The user is defined as a tap event after pressing the finger on the mobile side, or lifting the mouse on the tool / PC side. The tap event is basically an encapsulation of the web standard touch event.

# Click gesture

To prevent misuse of sensitive interfaces, some APIs check and consume click states (e.g. wx.openSetting, wx.requestSubscribeMessage) when triggered, and when the click state fails, the corresponding function is affected (call failure or downgrade).

Whenever the user clicks, the event response function of the corresponding tap event gets a click state. In addition, the following API callbacks also have a click state:

The clicking state is only valid within the macro task where the current event response function is located. Therefore, the function wrapped in setTimeout / setInterval does not have a click state, but is valid within Promise / async / await.

Due to problems with the iOS Promise implementation, Weixin Mini Program uses polyfill's Promise.So using Promise / async / await under iOS will lose the click state:

//  <button bind:tap="handleTap">tap</button> 
handleTap: async () => {
  // 点击态有效
  setTimeout(() => {
    // 失去点击态
  }, 100);
  Promise.resolve().then(() => {
    // Android 上具备点击态,iOS 上失去点击态
  });
};

Making asynchronous requests in the tap event handler is a common behavior. When wx.request, wx.downloadFile, or wx.getSetting is called with a click state, the click state is continued to the success / complete / fail callback function:

//  <button bind:tap="handleTap">tap</button> 
handleTap: async () => {
  // 点击态有效
  wx.request({
    url: "https://www.thissitedoesnotexist.com/step1",
    complete: () => {
      // 点击态有效
      wx.request({
        url: "https://www.thissitedoesnotexist.com/step2",
        complete: () => {
          // 点击态有效
        },
      });
    },
  });
};

Once the tap state generated by a single tap is consumed, it can no longer be continued:

//  <button bind:tap="handleTap">tap</button> 
handleTap: async () => {
  // 点击态有效
  wx.openSettings({}); // 成功调用
  wx.request({
    url: "https://www.thissitedoesnotexist.com",
    complete: () => {
      // 失去点击态,因为点击态被 wx.openSettings 消耗掉了
    },
  });
  wx.openSettings({}); // 成功调用
};