2017-04-22 47 views
5

Doğal tepki veren yerel PanResponder'u kullanarak, ekran dokunma koordinatları belirli bir değerler aralığının dışında olduğunda hareketi nasıl engelleyebilirim? Örneğin, kullanıcıların bir bileşenin ekrandaki belirli bir y konumundan aşağı taşınmasını nasıl engelleyebilirim?Tepki doğal olarak tepki vererek PanResponder ile kilitleme hareketi

PanResponder, Gesture Responder System kullanır.

Dikkatlice belgeleri okuyordum, ancak cevabı bulamıyorum.

Her türlü yardım büyük beğeni topluyor.

+0

Hey AlexB! Görünüşe göre @jaws'ın cevabı işe yaradı. Cevabı uyguladıktan sonra nasıl göründüğünün bir örneğini paylaşır mısınız? Teşekkürler –

cevap

4

Sağladığınız PanResponder belge sayfasına (https://facebook.github.io/react-native/docs/panresponder.html) bakarak, ihtiyacınızı karşılamak için örneği değiştirebilirsiniz. gestureState nesne şöyle Nerede

_handlePanResponderMove: function(e: Object, gestureState: Object) { 
    this._circleStyles.style.left = this._previousLeft + gestureState.dx; 
    this._circleStyles.style.top = this._previousTop + gestureState.dy; 
    this._updateNativeStyles(); 
}, 

:

bir jest cevaben harekete sorumlu fonksiyon PanResponder bir özelliği gibi bu görünüyor belgelerinden örnek kodda, onPanResponderMove denilen olduğunu

stateID - ID of the gestureState- persisted as long as there at least one touch on screen 
moveX - the latest screen coordinates of the recently-moved touch 
moveY - the latest screen coordinates of the recently-moved touch 
x0 - the screen coordinates of the responder grant 
y0 - the screen coordinates of the responder grant 
dx - accumulated distance of the gesture since the touch started 
dy - accumulated distance of the gesture since the touch started 
vx - current velocity of the gesture 
vy - current velocity of the gesture 
numberActiveTouches - Number of touches currently on screen 

Sen gestureState.y0 bazı eşiğin altına olup olmadığını belirlemek için _handlePanResponderMove bir şartlı onay ekleyin ve sadece bir değişiklik geçerli olabilir eğer öyleyse