import React, { Component } from "react"; import { Animated, View, StyleSheet, PanResponder, Text, Modal, Image, TouchableOpacity } from "react-native"; import { height, px2dp, width } from "../../utils/base"; export interface Props { } export interface State { visable: boolean url: string | any } export default class DrawImagePreView extends Component { pan = new Animated.ValueXY(); panResponder = PanResponder.create({ onMoveShouldSetPanResponder: () => true, onPanResponderGrant: (event, gestureState) => { console.log("手势;", gestureState) // if(gestureState.x0<=width*2/3){ // this.maxX:width // } // width this.pan.setOffset({ x: this.pan.x._value, y: this.pan.y._value }); }, onPanResponderMove: Animated.event([ null, { dx: this.pan.x, dy: this.pan.y } ]), onPanResponderRelease: () => { this.pan.flattenOffset(); } }); public readonly state: Readonly = { visable: false, url: "https://" } public maxX = 0 public maxY = 0 show = (item) => { this.setState({ visable: true, url: item }) } hide = () => { this.setState({ visable: false }) } render() { let { visable, url } = this.state; return ( <> { visable ? Drag this box! {/* */} {/* */} : null } ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: "center", justifyContent: "center", position: "absolute", // padding: px2dp(100) }, titleText: { fontSize: 14, lineHeight: 24, fontWeight: "bold" }, box: { height: height / 2, width: width * 2 / 3, backgroundColor: "blue", borderRadius: 5 } });