简体   繁体   中英

How can I reference the getNext props in react-native by javascript?

I have a cokebase like that, I wanna let callback render function in map reference the getNext props, how could I do it?

const render = ({ photoURL }) => {
  return(
    <Image key={photoURL} resizeMode="contain" style={{flex: 1}} source={{uri: photoURL}}>
      <View style={{ flex: 1, marginLeft: 10, marginBottom: 20, flexDirection: "row", alignItems: "flex-end", justifyContent: "center"}}>
        <Button icon={{ name: "heart", type: "evilicon", color: "#ff0000", size: 70 }} backgroundColor="transparent" onPress={getNext} />
        <Button icon={{ name: "close-o", type: "evilicon", color: "#ff0000", size: 70 }} backgroundColor="transparent" onPress={getNext} />
      </View>
    </Image>
  )
}
//const { image, view } = styles

const Picture = ({ PHOTO_URLS, getNext}) => {

  return(
    <View style={{flex: 1}}>
      <Carousel delay={2000} style={{ flex: 1, backgroundColor: "#ff1493" }} pageInfo autoplay={false} onAnimateNextPage={(p) => console.log(p)} >
        {PHOTO_URLS.map(render)}
      </Carousel> 
    </View>
  )
}

export { Picture } 

You can call another function that passes the required parameters down to it. Something like below

 { PHOTO_URLS.map((arg) => render(arg, getNext)) }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM