Native Base双按按钮触发功能本机反应

问题描述 投票:1回答:1

我正在尝试触发函数onPress {()=> someFunction()}但我需要点击两次才能触发函数。在这种情况下,有人可以帮助我吗?我在本机中使用Native Base Framework for UI组件。这是一个错误吗?

function react-native button double-click native-base
1个回答
0
投票

按压方法可以是这样的:

onPressFunction () {
    if (this.state.wasPressedOnce) {
        // do here what you want to do in double press <---
    } else {
      this.setState({ wasPressedOnce: true });
      setTimeout(
          () => {
              this.setState({ wasPressedOnce: false });
          }, 1000); // 1000 is the time the user have to double press the button
    }
}

如果在最后1秒之前按下按钮,则按下按钮时基本计算。

© www.soinside.com 2019 - 2024. All rights reserved.