Listener view position
Publicado por Victorio (11 intervenciones) el 02/06/2020 12:42:32
Quiero escuchar la posición de una vista que estoy moviendo con un respondedor panorámico. Estoy usando la propiedad onLayout para obtener el ancho, la altura, las posiciones x e y, pero solo se ejecuta cuando se monta el componente por primera vez. ¿Alguna idea?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { useState, useRef } from "react";
import {
View,
Animated,
PanResponder,
Dimensions,
StyleSheet,
} from "react-native";
const WINDOW_HEIGHT = Dimensions.get("window").height;
export default function Cropper({ photo }) {
const [height, setHeight] = useState(WINDOW_HEIGHT / 2); // Use in future
const pan = useRef(new Animated.ValueXY()).current;
const panResponder = useRef(
PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: Animated.event([null, { dy: pan.y }]),
onPanResponderRelease: () => {
pan.flattenOffset();
},
})
).current;
onLayout = (event) => {
const {
nativeEvent: { layout },
} = event;
// Recalculate top and buttom views' height (setNativeProps)
};
const panStyle = {
transform: pan.getTranslateTransform(),
};
return (
<View style={styles.container}>
<View style={styles.blurView} />
<Animated.View
onLayout={(event) => onLayout(event)}
{...panResponder.panHandlers}
style={[
styles.cropper,
panStyle,
{
height: height,
},
]}
/>
<View style={styles.blurView} />
<View style={styles.bottomButtonsContainer}></View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
blurView: {
flex: 1,
width: "100%",
backgroundColor: "rgba(0, 0, 0, .9)",
},
cropper: {
width: "100%",
backgroundColor: "red",
},
bottomButtonsContainer: {
position: "absolute",
bottom: 0,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
width: "100%",
height: 120,
},
});
Valora esta pregunta


0