单击时如何为照片制作按钮并按住时录制视频

我正在尝试仅使一个按钮进行照片和视频录制:

  • 当我按下它会拍照
  • 当我拿着它,一段时间后录制视频

视图中的按钮:

<TouchableOpacity
    onPressIn={() => onPressInButton()}
    onPressOut={() => onPressOutButton()}
</TouchableOpacity>

按钮代码:

const insidePressInButton = async () => {
    if (!pressOut) {
        setRecordingVideo(true)
        console.log('START RECORDING VIDEO')
    }
    else {
        await takePicture()
        console.log('NOT STARTED RECORDING -> PICTURE')
    }
}

let pressOut = false
const onPressInButton = async () => {
    pressOut = false
    setTimeout(() => {
        insidePressInButton()
    }, 1)
}

const onPressOutButton = async () => {
    pressOut = true
    if (recordingVideo) {
        setRecordingVideo(false)
        console.log('STOP RECORDING VIDEO')
    }
}

In setTimeout() I set the time to only 1 (very little) and the wait is long (I think this is React's problem with re-rendering)

从理论上讲,此解决方案有效,但我有一个大问题

当我单击一次想要照片时,我必须等待一秒钟以上

他想这样做,以便立即拍摄照片,当我按住按钮并保持不放时,它正在录制视频

评论