You can to make use of Animated.diffClamp or extrapolate
diffClamp logic -
const animtion = new Animated.ValueXY(0); // you need to update this while dragging
const translateX = Animated.diffClamp(animtion.x, 0, screenWidth - boxWidth);
const translateY = Animated.diffClamp(animtion.y, 0, screenHeight - boxHeight);
return(<View style={[styles.box,{transform:[{translateX},{translateY}]}]} />)
extrapolate logic -
const animtion = new Animated.ValueXY(0); // you need to update this while dragging
const translateX = animation.x.interpolate({inputRange:[0,screenWidth - boxWidth],outputRange:[0,screenWidth - boxWidth], extrapolate: 'clamp'})
const translateY = animation.y.interpolate({inputRange:[0,screenHeight - boxHeight],outputRange:[0,screenHeight - boxHeight], extrapolate: 'clamp'})
return(<View style={[styles.box,{transform:[{translateX},{translateY}]}]} />)