亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

react native 如何根據條件在不同組件之間導航

react native 如何根據條件在不同組件之間導航

幕布斯6054654 2022-05-22 13:55:32
我正在構建一個原生反應的移動應用程序,其中我的視頻和音頻來自同一個數據數組。現在我將它們渲染成一個平面列表,音頻和視頻隨機組合在一起。現在我想要如果我點擊音頻文件,它應該導航到音頻組件,如果我點擊任何視頻,它應該導航到視頻組件。但我不知道如何過濾和導航到它們各自的組件。請幫助我。謝謝我的代碼主文件:它正在導航到音頻組件,我單擊音頻文件或視頻文件 <FlatList        horizontal        data={latestuploads}        keyExtractor={item => item.id}        renderItem={({item}) => {          return (            <ScrollView horizontal={true}>              <Card transparent style={{width: 170}}>                <TouchableOpacity                  onPress={() =>                    this.props.navigation.navigate('Audio', {id: item.id})                  }>                  <CardItem>                    <ImageBackground                      source={{uri: item.image_url}}                      style={styles.image}>                      <Image                        source={require('../assets/play-icon.png')}                        style={styles.icon}                      />                    </ImageBackground>                  </CardItem>                </TouchableOpacity>                <CardItem cardBody>                  <Text numberOfLines={1} style={styles.title}>                    {item.title}                  </Text>                </CardItem>                <CardItem cardBody>                  <Text style={styles.speaker}> {item.speaker} </Text>                </CardItem>              </Card>            </ScrollView>          );        }}      />
查看完整描述

2 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

我想您正在從數據數組中獲取文件擴展名示例.mp4/.mp3等或Audio/Video標志。


創建一個采用文件信息示例的函數:


navigateTo = (fileinfo) => {

 // const filetype = check for file type, Audio/Video or file extension


if (filetype === 'Audio'){

  this.props.navigation.navigate('Audio', {id: fileinfo.id})

} else {

  this.props.navigation.navigate('Video', {id: fileinfo.id})

}

將此傳遞給您的TouchableOpacity:


<TouchableOpacity

  onPress={() => navigateTo(item)}>

  // your code here

</TouchableOpacity>  


查看完整回答
反對 回復 2022-05-22
?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

constructor()

{

    super(props)

    this.state = {

        ItemindexChecked: "",

    }

    this.Dataarrayholder = latestuploads;

}

............................your code ............

DataFilter(p_value)

{


    const newData = this.Dataarrayholder.filter(function (item) {

        const itemData = item.value ? item.value.toUpperCase() : ''.toUpperCase();

        const textData = p_value.toUpperCase();

        return itemData.indexOf(textData) > -1;

        if (p_value != "")

        {

            if (newData == 0) {

                return


            }

            else

            {

                this.props.navigation.navigate('Audio', { id: newData[0].id }); 

            }

        }

    });


}

...........................................your code ..............

<FlatList

    horizontal

    data={latestuploads}

    keyExtractor={item => item.id}

    renderItem={({ item }) => {

        return (

            <ScrollView horizontal={true}>

                <Card transparent style={{ width: 170 }}>

                    <TouchableOpacity

                        //onPress={() =>

                        //   // this.props.navigation.navigate('Audio', { id: item.id })

                        //    }

                        onPress={() => { this.DataFilter(item.value), this.setState({ ItemindexChecked: item.key }) }}

                    >

                        <CardItem>

                            <ImageBackground

                                source={{ uri: item.image_url }}

                                style={styles.image}>

                                <Image

                                    source={require('../assets/play-icon.png')}

                                    style={styles.icon}

                                />

                            </ImageBackground>

                        </CardItem>

                    </TouchableOpacity>


                    <CardItem cardBody>

                        <Text numberOfLines={1} style={styles.title}>

                            {item.title}

                        </Text>

                    </CardItem>

                    <CardItem cardBody>

                        <Text style={styles.speaker}> {item.speaker} </Text>

                    </CardItem>

                </Card>

            </ScrollView>

        );

    }}

/>

也許對你有幫助


查看完整回答
反對 回復 2022-05-22
  • 2 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號