创建要共享的列表?

我有一个应用程序,可将数据保存在下载文件夹中的.csv文件中。

我正在尝试创建此数据列表(来自csv文件),可以共享(通过从用户选择的任何选项)。

componentDidmount(){
        this.readingValue()
    }
    async readingValue() {
    // get a list of files and directories in the main bundle  :ExternalStorageDirectoryPath 
    const elementiDirectory = await RNFS.readDir(RNFS.ExternalStorageDirectoryPath + '/Download/') 
    const pathElementi = elementiDirectory.map(e => e.path);
    //console.log("filter " + pathElementi)
    const pathCSV = pathElementi.filter(path => {
      const reg = /sd\d+\.csv/;
      return reg.test(path);
    });
    console.log("risultati " + pathCSV)
    this.setState({risultati : pathCSV});
  }

  onShare = async () => {
    console.log("Dentro OnShare")
    try {
      const result = await Share.share({
        message:
          'React Native | A framework for building native apps using React',url: this.state.risultati
      });

      if (result.action === Share.sharedaction) {
        if (result.activityType) {
          // shared with activity type of result.activityType
          console.log("Condivisione OK.")
        } else {
          // shared
        }
      } else if (result.action === Share.dismissedaction) {
        // dismissed
      }
    } catch (error) {
      alert(error.message);
    }
  };
    render() {
        return (
            <View>
              <Text>{this.state.risultati}</Text>
              <Button onPress={this.onShare} title="Share" />
            </View>
        );
    }

使用功能async readingValue(),我找到了数据路径。 例如,this.state.risultati将显示

/storage/emulated/0/Download/nameofthefile.csv

使用onShare函数时,我创建了共享选项。

现在,它可以使用“下载”文件夹中的一个文件。

如何创建可共享的值列表?

赞:

文件1 |共享按钮

文件2 |共享按钮

g109007 回答:创建要共享的列表?

我以这种方式下定决心:

render() {
  const RisultatoDaCondividere = this.state.risultati.map(singoloRisultato => {
    return(
      <View>
      <Text>
        {singoloRisultato} 
      </Text>
      <Button onPress={this.onShare} title="Share" />
      </View>
    )
  })

    return (
            <View>
              {RisultatoDaCondividere}              
            </View>
        );
    }
本文链接:https://www.f2er.com/3168031.html

大家都在问