Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

react native - Rendering Favourites icon to Flat list

Any ideas to render favourites button the one with a heart shape on Flatlists in React Native? This I have here works fine, I get the data from a REST api correctly without worries, but the primary challenge is , having to have the favourites button to it.

Flat List code looks like this

  render() {
        return (
            <View style={styles.MainContainer}>
            <FlatList
            data={ this.state.dataSource }
            ItemSeparatorComponent = {this.FlatListItemSeparator}
            renderItem={({item}) => 
                <View style={{flex:1, flexDirection: 'row'}}>
                    <Image source = {{ uri: item.url_image}} style={styles.imageView} />
                    <Text onPress={this.GetItem.bind(this, item.movie_description)} style={styles.textView} >{item.movie_description}</Text>
                </View>
                }
            keyExtractor={(item, index) => index.toString()}
            />
            </View>
        );
  }
}

Help would be very much appreciated!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

At the main View in renderItem

<View style={{flex:1, flexDirection: 'row'}}>
     <Image source = {{ uri: item.url_image}} style={styles.imageView} />
     <Text onPress={this.GetItem.bind(this, item.movie_description)} style={styles.textView} >{item.movie_description}</Text>
</View>

you can simply add png image or any favourite icon, but you have to give it position: 'absolute' if you want favourite icon to be float on the card, you can add image into main View in the renderItem like this

<Image 
   source={your png or jpg file's path} 
   style={{
       height: 25, 
       width: 25, 
       position: 'absolute',
       top: 15,
       right: 15
   }}/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...