2017-06-01 41 views
0

如何檢測longPress何時發佈(而不是通過拖走)。 onPressOut確實會在釋放它時發出提示,但是當手指從按鈕上被拖走時它也會觸發。檢測TouchableWithoutFeedback長時間的新聞稿

<TouchableWithoutFeedback 
    onLongPress={() => this.onLongPress()} 
    onPressOut={() => this.onCancel()} 
    onPressIn={() => this.onHover()} 
    onPress={() => this.onPress()} 
    > 

回答

0

你確定你應該那樣做嗎?

取消-ability-做一個動作時,用戶應該能夠從Facebook的最佳實踐部分拖動他們的手指離開

中止它中間的觸摸: https://facebook.github.io/react-native/docs/gesture-responder-system.html#best-practices

如果您仍然需要這樣做,您可能需要使用View.props.onResponderMoveView.props.onResponderRelease

實現自定義可觸摸請參閱文檔: https://facebook.github.io/react-native/docs/gesture-responder-system.html#responder-lifecycle

+0

那正是我爲什麼要這麼做的原因。用戶不能通過拖動手指來取消longpress。 –

0

如何添加一個巨大的(比屏幕大)pressRetentionOffset?這應該可以防止觸摸取消,除非您釋放。

<TouchableWithoutFeedback 
    ... 
    pressRetentionOffset={{ top: 1000, left: 1000, bottom: 1000, right: 1000 }} 
>