Home > front end >  onSwipeableOpen is called immediately without trigger or swipe action
onSwipeableOpen is called immediately without trigger or swipe action

Time:02-27

i have a problem: onSwipeableOpen is called immediately without doing the swipe actually. i mean, i did something like this: onSwipeableOpen={console.log(id)}

so when i enter the Swipeable List screen, the app print immediately the id of all rows...

here is my code:

const renderItems2 = ({index,item,section})=>{
    const {title,theaddress,id} = item;
    const swipeRight = (progress,dragX) =>{
        const scale = dragX.interpolate({
          inputRange:[-200,0],
          outputRange:[1,0.5],
          extrapolate:'clamp'
        })
        return(
          <Animated.View style={{backgroundColor:'red',width:"60%",justifyContent:'center'}}>
            <Animated.Text style={{marginLeft:'auto',marginRight:50, fontSize:15, fontWeight:'bold',transform:[{scale}]}}>Delete Item</Animated.Text>
          </Animated.View>
        )
      }
    return(
        <Swipeable
        renderRightActions={swipeRight} 
        rightThreshold={-200}
        onSwipeableOpen={console.log(id)}
        >
            <Animated.View>
                <WhiteAddressButton title={title} btnId={index} desc={theaddress} onPress={()=>alert("hey")} />
            </Animated.View>
        </Swipeable>
    );
}

when enter the screen, i get immediately without any trigger, without any swipe:

LOG 2 LOG 3 LOG 5

any help please?

CodePudding user response:

onSwipeableOpen wasn't called immediately, you need to pass the reference of a function instead of passing console.log, try this and you will see:

onSwipeableOpen={() => console.log(id)}
  • Related