Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

mobile - Create a gridlayout without using flatlist with React

What I'm trying to do is a dashboard screen with fixed cardviews, that is, I won't have to pull data from an api all the time and they would redirect to other screens, using touchableopacity. I found several references on the internet but none made it clear how to do this without using a flatlist and they always pulled data from some api. Here below is a reference that I found, but instead of pulling an api I would like something static, I thought about using a scrollview but I didn't understand how I can do it leaving it similar to a flatlist (the advantage of the flatlist is that it has the numColumns parameter).

renderItem = ({ item, index }) => {
    let url = item.url;
    const idPokemon = url.split('https://pokeapi.co/api/v2/pokemon/');
    const link = urlImage + idPokemon[1].substring(0, idPokemon[1].length - 1) + ".png";
    console.log('link', link)
    return <View style={styles.item}>
      <Image
        style={styles.image}
        resizeMode="contain"
        source={{ uri: link }}
      />
      <Text style={styles.text}>{item.name}</Text>
    </View>
  }

  render() {
    const { data } = this.state;
    return (
      <SafeAreaView style={styles.container}>
        <FlatList
          numColumns={2}
          style={styles.container}
          data={data}
          renderItem={this.renderItem}
          keyExtractor={item => `key-${item.name}`}
        />
      </SafeAreaView>
    );
  }

enter image description here

question from:https://stackoverflow.com/questions/65898664/create-a-gridlayout-without-using-flatlist-with-react

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...