react-native-swiper 使用遇到的坑

首先是把react-native-swiper 引入到項目中,先cd到項目跟目錄下,再react

$ npm i react-native-swiper --save

完成後在項目中要使用的地方import 進來
import Swiper from 'react-native-swiper';

在return()中使用就OK,如:
return (
            <Swiper
                style={styles.wrapper}
                showsButtons={true}    //顯示左右點擊的按鈕
                loop = {true}
                autoplay = {true}
                height={200}    //沒有效果 >

                <View style={styles.slide1}>

                    <Image style={{width: 300, height: 190}}
                           resizeMethod='stretch'
                           source={{uri: 'https://www.baidu.com/img/bd_logo1.png'}}
                    />

                    <Text style={styles.text}>滑動試圖第一頁</Text>
                </View>
                <View style={styles.slide1}>
                    <Text style={styles.text}>滑動試圖第二頁</Text>
                </View>
                <View style={styles.slide1}>
                    <Text style={styles.text}>滑動試圖第三頁</Text>
                </View>
            </Swiper>

        )
可是這裏就遇到個坑,swiper打開一直是個全屏的,在屬性裏怎麼修改也無效。後來我把react-native-swiper封裝成一個組件,在引用時在外層的View定義height,發現是有效果的。 學習中,僅當本身學習筆記。不許確的地方不按期更新!!!
相關文章
相關標籤/搜索