React Native多圖層View,實(shí)現(xiàn)empty,content,error,loading等界面無(wú)縫跳轉(zhuǎn)

(1)概述

這是我在github上開源的第二個(gè)項(xiàng)目,接觸react native以來(lái),在使用的過(guò)程中,由于產(chǎn)品的需求,自己封裝了一個(gè)包含多圖層的View,避免重復(fù)代碼的產(chǎn)生。
react-native-multiview 點(diǎn)擊這里到github,先上圖

(2)用法

介紹一下用法:主要是提供一個(gè)狀態(tài),在state中管理這個(gè)狀態(tài),當(dāng)然用mobx或者redux也可以!

1、首先,引用該項(xiàng)目在命令行輸入

npm install -save react-native-multiview

2、在項(xiàng)目中添加引用

import {MultiView} from "react-native-multiview";
import {PageStatus} from "react-native-multiview";

其中MultiView的用法更React Native中View的用法一致,除此之外,還包含了其他的一些屬性,請(qǐng)參照屬性表,

Props

Prop Type Optional Default Description
status string Yes PageStatus.content status determines the current display of that page,
which includes{PageStatus.error,PageStatus.empty,
PageStatus.content,PageStatus.init,PageStatus.loading}
five status.
onEmptyPress func Yes Click event of empty page button
onErrorPress func Yes Click event of error page button
emptyImgSource source Yes Image of empty page show
errorImgSource source Yes Image of error page show
emptyText string Yes "" Text of empty page desc
errorText string Yes "" Text of error page desc
emptyBtnText string Yes "" Text of empty page button,Display when it is not empty,
Default does not display
errorBtnText string Yes "" Text of error page button,Display when it is not empty,
Default does not display
emptyTextStyle style Yes The style of empty page text
errorTextStyle style Yes The style of error page text
emptyButtonStyle style Yes The style of empty page button
errorButtonStyle style Yes The style of error page button
emptyBgColor color Yes The backgroundcolor of empty page
errorBgColor color Yes The backgroundcolor of error page
initHint string Yes Hint of init page ActivityIndicator
loadingHint string Yes Hint of loading page ActivityIndicator
initHintStyle style Yes The style of init page initHint
loadingHintStyle style Yes The style of loading page loadingHint
initIndicatorColor color Yes The color of init page ActivityIndicator
loadingIndicatorColor color Yes The color of loading page ActivityIndicator
initContainerBgColor color Yes The backgroundcolor of init page ActivityIndicator container
initContainerBgColor color Yes The backgroundcolor of loading page ActivityIndicator container

3、在項(xiàng)目中使用

render() {

        let that = this;
        return (
            <MultiView status={that.state.status} emptyBgColor="white" 
                        errorBgColor="white" emptyText="你還沒有添加商品呦"
                       errorText="網(wǎng)絡(luò)錯(cuò)誤">
                <View style={styles.container}>
                    ...
                </View>
            </MultiView>
        );
    }

PageStatus一共有5種狀態(tài),

PageStatus.init 一般是進(jìn)入頁(yè)面初始化的時(shí)候使用

PageStstus.content 就是顯示頁(yè)面的內(nèi)容

PageStatus.empty 當(dāng)頁(yè)面接在為空,比如收藏夾或者商品列表為空的時(shí)候使用

PageStatus.error 當(dāng)網(wǎng)絡(luò)錯(cuò)誤或者頁(yè)面加載失敗的時(shí)候使用

PageStatus.loading 當(dāng)頁(yè)面需要刷新的時(shí)候使用
當(dāng)然,多圖層中顏色,背景,icon和提示文字都可以進(jìn)行定制,有什么建議和意見歡迎@我

原創(chuàng)博客,歡迎轉(zhuǎn)載!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容