簡體   English   中英

react-native-swiper按鈕無法正常使用

[英]react-native-swiper button is not work properly

問題

如下所示,當react-native-swiper移動時,下面的藍色活動按鈕不會更新。

對於刷卡器,我正在使用map()函數創建一個視圖。

請注意,將鍵(索引)傳遞給子視圖組件不會更新藍色按鈕。

如果我不使用swiper中的map()函數對視圖進行硬編碼,則該按鈕將起作用。

有什么問題?

參考圖片

在此處輸入圖片說明

我的密碼

import React from 'react';
import { View, Platfrom, Text, StyleSheet, AsyncStorage, TouchableOpacity, Image, FlatList, ScrollView } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import { connect } from 'react-redux';
import moment from 'moment';
import Swiper from 'react-native-swiper';

import * as settings from '../../config/settings';


const styles = StyleSheet.create({
    headerRight: {
        padding: 10
    },
    body_txt: {
        marginTop: 5,
        padding: 8,
        borderWidth: 1,
        borderColor: '#EAEAEA',
    },
    slidmain: {
        borderColor: '#EAEAEA',
        borderWidth: 1,
    },
    slide1: {
        width: '100%',
        height: 300,
    },
    main: {
        flex: 1,
        backgroundColor: '#FFFFFF',
        padding: 10,
    },
    image: {
        height: 100,
        width: '98%',
        marginBottom: 70,
        marginLeft: '1%',
        resizeMode: 'contain',
    }
});


class RepairInquiryDetailScreen extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            created_date: '',
            photos: [],
            key: 0,
        }
    }

    static navigationOptions = ({ navigation }) => ({
        title: '수선 문의서',

        headerStyle: {
            backgroundColor: '#fff',
            borderBottomWidth: 0,
            elevation: 0,
        },
        headerTitleStyle: {
            color: '#000',
            fontSize: 20,
            textAlign: 'center',
            alignSelf: 'center',
        },
        headerRight: <Icon name="bars" size={30} color="#333" onPress={() => navigation.navigate('DrawerOpen')} style={styles.headerRight} />
    })

    RepairInquiryDetailService = async () => {
        let user_info = await AsyncStorage.getItem('user_info');
        user_token = JSON.parse(user_info).key;
        let inquiry_id = this.props.navigation.state.params.id
        const api_uri = settings.base_uri + 'inquiry/' + inquiry_id + '/'

        fetch(api_uri, {
            method: 'GET',
            headers: {
                'Authorization': 'Token ' + user_token,
            }
        })
            .then(res => res.json())
            .then(res => {

                let repair_type_tmp = ""
                for (i = 0; i < res.repair_type.length; i++) {
                    if (i == 0) {
                        repair_type_tmp += res.repair_type[i].type;
                    } else {
                        repair_type_tmp += ", " + res.repair_type[i].type;
                    }
                }

                let photos_tmp = [];
                for (i = 0; i < res.photos.length; i++) {
                    photos_tmp[i] = res.photos[i].thumbnail;
                }

                let logistics_tmp = "";
                if (res.logistics == "delivery") {
                    logistics_tmp = "택배";
                } else if (res.logistics == "quick") {
                    logistics_tmp = "퀵";
                } else if (res.logistics == "direct") {
                    logistics_tmp = "방문";
                } else {
                    logistics_tmp = res.logistics;
                }

                this.setState({
                    product_type: res.product_type.type,
                    repair_type: repair_type_tmp,
                    model: res.model,
                    content: res.content,
                    logistics: logistics_tmp,
                    created_date: res.created_date,
                    direct_partner: res.direct_partner,
                    photos: photos_tmp,
                })

                console.log(this.state.photos)
            })


            .catch((error) => {
                console.error(error);
            });
    }

    componentDidMount() {
        this.RepairInquiryDetailService();
    }

    render() {
        const parsedDate = moment(this.state.created_date).format("YYYY.MM.DD")

        return (
            <ScrollView style={styles.main}>
                <Swiper 
                    style={styles.slidmain} 
                    height={300} 
                    showsButtons={false}
                    loop={false}
                    >
                    {this.state.photos.map((item, key) => {
                        console.log(item, key);
                        return (
                            <Slide uri={item} key={key} i={key}/>
                        );
                    })}
                </Swiper>
                <View style={styles.body_txt}>
                    <Text>제품 카테고리: {this.state.product_type}</Text>
                    <Text>수선 카테고리: {this.state.repair_type}</Text>
                    <Text>모델명: {this.state.model}</Text>
                    <Text>배송유형: {this.state.logistics}</Text>
                    <Text>작성일: {parsedDate}</Text>
                    <Text>문의 상세내용: {this.state.content}</Text>
                </View>
            </ScrollView>
        )
    }
}

const Slide = props => {
    console.log('uri and key: ', props.uri, props.i);
    return (
        <View style={styles.slide1} key={props.i}>
            <Image
                source={{ uri: props.uri }}
                style={styles.slide1}
            />
        </View>
    );
}


const mapStateToProps = state => ({
    isLoggedIn: state.loginReducer.isLoggedIn
})

const RepairInquiryDetail = connect(mapStateToProps, null)(RepairInquiryDetailScreen);

export default RepairInquiryDetail;

謝謝!

一個建議的修復了這個問題,發現這里 ,是去除style從道具Swiper組件。

要獲得所需的邊框,您可以將刷卡器包裹在父視圖中。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM