Невозможно показать несколько изображений в реагировать родной - PullRequest
0 голосов
/ 24 сентября 2019

Я работаю над собственным приложением реагировать.Я должен показать несколько изображений.Мой код:

render() {
  if (!this.props.data) {
    return(<Text style={styles.noIMG}>Keine Bilder vorhanden</Text>)
  }
  return (
    <View>
      <View style={styles.view}>
        {
          (
            this.props.data == '' || 
            this.props.data == null || 
            this.props.data == undefined
          ) ? null :
          this.props.data.map(img => {
            console.log(img.image);
            console.log("Image displayed");
            return(
            <TouchableHighlight 
              key={this.uuidv4()} 
              onPress={()=>{
                this.setState({zoom: img.image})
              }}
            >
              <Image 
                style={styles.imagePreview} 
                source={{uri: img.image}} 
              />
            </TouchableHighlight>)
        })
        }
      </View>
      { this.state.zoom ? 
        <Card>
          <PinchZoomView scalable={false}>
            <FitImage resizeMode="contain" source={{uri: this.state.zoom}}/>
          </PinchZoomView>
          <TouchableOpacity 
            style={styles.btn} 
            onPress={() => this.deleteImage(this.state.zoom)}>
            <Text style={{color:'white'}}>Delete Image</Text>
          </TouchableOpacity>
        </Card> : 
        <View style={styles.container}><Text>Bild zum vergrößern antippen.</Text></View>
      }
    </View>
  );
}

Я получаю два изображения в «props.data», но на экране отображается только одно изображение.Код CSS:

const styles = StyleSheet.create({
    imagePreview:{
    width: 100,
    height: 100,
    margin: 5
    }
});

1 Ответ

0 голосов
/ 24 сентября 2019

Попробуйте использовать FlatList

<FlatList   
    data={this.props.data}
    extraData={this.state}
    renderItem={({ item }) => {
             return (
            <View>
                <TouchableOpacity onPress={() =>  this.setState({zoom: img.image})}>
                    <Image
                        source={{ uri: item.image }}
                        PlaceholderContent={<ActivityIndicator />}                     
                    />
                </TouchableOpacity>

            </View>
        )
    }}
    keyExtractor={(item, index) => index.toString()}
/>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...