Can’t RN do style changes using JS?
...
const PR = PanResponder.create({
onStartShouldSetPanResponder: (e, gestureState) => true,
onPanResponderStart: (e, gestureState) => {
console.log("start");
},
onPanResponderMove: (e, gestureState) => {
const dx = Math.abs(gestureState.dx);
**target.current.style.backgroundColor** = `rgba(${dx},${dx / 2},106,1)`;
},
onPanResponderEnd: (e, gestureState) => {
const dx = Math.abs(gestureState.dx);
if (!dx) {
target.current.style.backgroundColor = "green";
}
console.log("End");
},
});
...
As above, it is difficult to change the style on mobile.
Thank you for your reply.
The useState hook was not what I was expecting.
help me..
2
Answers
Look into this panResponder . It has some example of how to use
PanResponderGestureState
in
react-native
In the code above it looks like you were storing the style with
useRef
, which doesnt trigger component updates when its value changes. Here’s a useState exampleWhile it works, the best results would come from using Animated.View and some Animated values