#reactjs #react-native
Вопрос:
Я застрял в своем коде, я хотел бы поднять предупреждение,как только мой пользователь переместит квадрат в центре экрана.квадрат позиции инициализации слева, вверху. кто-нибудь может мне помочь?
мое досье Animation.js
import React, {useState} from 'react';
import { StyleSheet, View, Dimensions, PanResponder } from 'react-native';
function pan_responde() {
const [topPosition, setTopPosition] = useState(0);
const [leftPosition, setLeftPosition] = useState(0);
var {height, width } = Dimensions.get('window');
const panResponder = PanResponder.create({
onStartShouldSetPanResponder: (evt, gestureState) => true,
onPanResponderMove: (evt, gestureState) => {
let touches = evt.nativeEvent.touches;
if(touches.length = 1){
setTopPosition(touches[0].pageY - height/2);
setLeftPosition(touches[0].pageX - width/2);
}
}
})
return (
<View style={styles.main_container}>
<View
{...panResponder.panHandlers}
style={[styles.animation_view, {top: topPosition, left: leftPosition}]}
>
</View>
</View>
)
}
const styles = StyleSheet.create({
main_container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center'
},
animation_view: {
backgroundColor: 'red',
width: 100,
height: 100
}
})
export default pan_responde;