www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > > 充電吧
[導(dǎo)讀]先來看下效果:這里需要用到兩個第三方插件:react-native-router-flux?路由,https://github.com/aksonov/react-native-router-flux

先來看下效果:


這里需要用到兩個第三方插件:

react-native-router-flux?路由,https://github.com/aksonov/react-native-router-flux

react-native-scrollable-tab-view 選項卡,https://github.com/skv-headless/react-native-scrollable-tab-view

prop-types?類型檢測庫

閱讀官方文檔,安裝這三個插件

$?npm?install?react-native-router-flux?--save
$?npm?install?react-native-scrollable-tab-view?--save
$?npm?install?prop-types?--save

在App.js中引入插件

import?{?Router,?Scene?}?from?'react-native-router-flux';
import?ScrollableTabView?from?'react-native-scrollable-tab-view';

在工作目錄下創(chuàng)建components文件夾,并添加customTabBar.js文件作為tab欄,如下

import?React,?{Component}?from?'react';
import?{
????Platform,
????StyleSheet,
????StatusBar,
????View,
????TouchableOpacity,
????Image,
????Text,
}?from?'react-native';
//第三方插件
import?PropTypes?from?'prop-types';
//自定義組件
import?Common?from?'./common';?//公共類

const?tabIcons?=?[
????require('../resources/images/tabs/home_v.png'),
????require('../resources/images/tabs/home_x.png'),
????require('../resources/images/tabs/headset_v.png'),
????require('../resources/images/tabs/headset_x.png'),
????require('../resources/images/tabs/bought_v.png'),
????require('../resources/images/tabs/bought_x.png'),
????require('../resources/images/tabs/mine_v.png'),
????require('../resources/images/tabs/mine_x.png')
];

export?default?class?CustomTabBar?extends?Component?{
????constructor(props)?{
????????super(props);
????}

????static?setAnimationValue({value})?{
????????console.log(value);
????}

????componentDidMount()?{
????????//?Animated.Value監(jiān)聽范圍?[0,?tab數(shù)量-1]
????????this.props.scrollValue.addListener(CustomTabBar.setAnimationValue);
????}

????renderTabOption(tab,?i)?{
????????let?color?=?this.props.activeTab?===?i???"#1296db"?:?"#707070";?//?判斷i是否是當(dāng)前選中的tab,設(shè)置不同的顏色
????????let?tabName?=?this.props.tabNames[i];
????????return?(this.props.goToPage(i)}?style={[styles.tab]}?key={'tab'?+?i}>{tabName});
????}

????renderTabs()?{
????????if?(true?!==?this.props.placeMiddle?||?0?!==?this.props.tabs.length%2)?{
????????????return?this.props.tabs.map((tab,?i)?=>?this.renderTabOption(tab,?i));
????????}?else??{
????????????let?tabs?=?[];
????????????for?(let?i?=?0;?i?<?this.props.tabs.length;?i++)?{
????????????????let?tab?=?this.props.tabs[i];
????????????????if?(i?===?parseInt(this.props.tabs.length/2))?{
????????????????????let?middle?=?();
????????????????????tabs.push(middle);
????????????????}
????????????????tabs.push(this.renderTabOption(tab,?i));
????????????}
????????????return?tabs;
????????}
????}

????render()?{
????????let?tabBarHeight?=?Platform.select({
????????????ios:?Common.isIphoneX???68?:?49,
????????????android:?49,
????????});
????????return?({this.renderTabs()});
????}
}

CustomTabBar.propTypes?=?{
????goToPage:?PropTypes.func,?//?跳轉(zhuǎn)到對應(yīng)tab的方法
????activeTab:?PropTypes.number,?//?當(dāng)前被選中的tab下標(biāo)
????tabs:?PropTypes.array,?//?所有tabs集合
????tabNames:?PropTypes.array,?//?保存Tab名稱
????tabIconNames:?PropTypes.array,?//?保存Tab圖標(biāo)
};

const?styles?=?StyleSheet.create({
????tabs:?{
????????flexDirection:?'row',
????????backgroundColor:'#ffffff',
????????borderTopWidth:?0.5,
????????borderTopColor:?'#cdcdcd',
????},
????tab:?{
????????flex:?1,
????????flexDirection:?'column',
????????justifyContent:?'center',
????????alignItems:?'center',
????},
????tabBox:?{
????????flexDirection:?'column',
????????justifyContent:?'center',
????????alignItems:?'center',
????????width:?48,
????????height:?48,
????},
????tabMiddleBox:?{
????????flex:?1,
????????flexDirection:?'column',
????????justifyContent:?'center',
????????alignItems:?'center',
????????width:?48,
????????height:?48,
????},
????tabBoxIcon:?{
????????width:?22,
????????height:?22,
????},
????tabBoxName:?{
????????fontSize:?10,
????????marginTop:?3,
????},
});

這里用到了一個公共類common.js

import?{
????Dimensions,
????PixelRatio,
????Platform
}?from?'react-native';


export?let?screenWidth?=?Dimensions.get('window').width;
export?let?screenHeight?=?Dimensions.get('window').height;
export?let?fontScale?=?PixelRatio.getFontScale();
export?let?pixelRatio?=?PixelRatio.get();


//像素密度
export?const?DEFAULT_DENSITY?=?2;
//px轉(zhuǎn)換成dp
//以iphone6為基準(zhǔn),如果以其他尺寸為基準(zhǔn)的話,請修改下面的750和1334為對應(yīng)尺寸即可.
const?width2x?=?750?/?DEFAULT_DENSITY;
//px轉(zhuǎn)換成dp
const?height2x?=?1334?/?DEFAULT_DENSITY;
//?iPhoneX
const?X_WIDTH?=?375;
const?X_HEIGHT?=?812;


/**
?*?設(shè)置字體的size(單位px)
?*?@param?size?傳入設(shè)計稿上的px
?*?@returns?{Number}?返回實際sp
?*/
export?function?autoFontSize(size)?{
????let?scaleWidth?=?screenWidth?/?width2x;
????let?scaleHeight?=?screenHeight?/?height2x;
????let?scale?=?Math.min(scaleWidth,?scaleHeight);
????size?=?Math.round((size?*?scale?+?0.5));
????return?size?/?DEFAULT_DENSITY;
}


/**
?*?屏幕適配,縮放size
?*?@param?size
?*?@returns?{Number}
?*/
export?function?autoScaleSize(size)?{
????let?scaleWidth?=?screenWidth?/?width2x;
????let?scaleHeight?=?screenHeight?/?height2x;
????let?scale?=?Math.min(scaleWidth,?scaleHeight);
????size?=?Math.round((size?*?scale?+?0.5));
????return?size?/?DEFAULT_DENSITY;
}


/**
?*?判斷是否為iphoneX
?*?@returns?{boolean}
?*/
export?function?isIphoneX()?{
????return?(
????????Platform.OS?===?'ios'?&&
????????((screenHeight?===?X_HEIGHT?&&?screenWidth?===?X_WIDTH)?||
????????(screenHeight?===?X_WIDTH?&&?screenWidth?===?X_HEIGHT))
????)
}


Date.prototype.format=function(fmt)?{
????let?o?=?{
????????"M+"?:?this.getMonth()+1,?//月份
????????"d+"?:?this.getDate(),?//日
????????"h+"?:?this.getHours()%12?===?0???12?:?this.getHours()%12,?//小時
????????"H+"?:?this.getHours(),?//小時
????????"m+"?:?this.getMinutes(),?//分
????????"s+"?:?this.getSeconds(),?//秒
????????"q+"?:?Math.floor((this.getMonth()+3)/3),?//季度
????????"S"?:?this.getMilliseconds()?//毫秒
????};
????let?weekday?=?{
????????"0"?:?"/u65e5",
????????"1"?:?"/u4e00",
????????"2"?:?"/u4e8c",
????????"3"?:?"/u4e09",
????????"4"?:?"/u56db",
????????"5"?:?"/u4e94",
????????"6"?:?"/u516d"
????};
????if(/(y+)/.test(fmt)){
????????fmt=fmt.replace(RegExp.$1,?(this.getFullYear()+"").substr(4?-?RegExp.$1.length));
????}
????if(/(E+)/.test(fmt)){
????????fmt=fmt.replace(RegExp.$1,?((RegExp.$1.length>1)???(RegExp.$1.length>2???"/u661f/u671f"?:?"/u5468")?:?"")+weekday[this.getDay()+""]);
????}
????for(let?k?in?o){
????????if(new?RegExp("("+?k?+")").test(fmt)){
????????????fmt?=?fmt.replace(RegExp.$1,?(RegExp.$1.length===1)???(o[k])?:?(("00"+?o[k]).substr((""+?o[k]).length)));
????????}
????}
????return?fmt;
};


export?default?class?Common?{
????static?SCREEN_WIDTH?=?screenWidth;
????static?SCREEN_HEIGHT?=?screenHeight;
????static?PIXEL_RATIO?=?pixelRatio;
????static?DEFAULT_DENSITY?=?DEFAULT_DENSITY;


????//是否為iphoneX
????static?isIphoneX?=?isIphoneX();


????//字體自適應(yīng)大小
????static?autoFontSize(size)?{
????????return?autoFontSize(size);
????}


????//尺寸自適應(yīng)大小
????static?autoScaleSize(size)?{
????????return?autoScaleSize(size);
????}


????//獲取指定格式時間字符串
????static?getDateFormat(date,?format?=?false)?{
????????if?(false?!==?format)?{
????????????format?=?"yyyy-MM-dd?HH:mm:ss";
????????}
????????return?date.format(format);
????}
}

然后在App.js內(nèi)渲染路由和tab,注意在路由外層要包一個View,以便后面我們使用全局的toast和loading,同時tab作為路由中的一個頁整體呈現(xiàn)。

//自定義組件
import?CustomTabBar?from?'./components/customTabBar';?//自定義選項卡
//選項卡Tab頁
import?HomeTabScreen?from?'./views/home';?//首頁
import?HeadsetTabScreen?from?'./views/headset';?//試聽
import?BoughtTabScreen?from?'./views/bought';?//已購
import?MineTabScreen?from?'./views/mine';?//我的
//頁面
import?SignInOrUpScreen?from?'./views/signIns/signInOrUp';?//免注冊登錄
import?SignInScreen?from?'./views/signIns/signIn';?//登錄

//?const?instructions?=?Platform.select({
//???ios:?'Press?Cmd+R?to?reload,n'?+
//?????'Cmd+D?or?shake?for?dev?menu',
//???android:?'Double?tap?R?on?your?keyboard?to?reload,n'?+
//?????'Shake?or?press?menu?button?for?dev?menu',
//?});

export?class?Tabs?extends?Component?{
????constructor(props)?{
????????super(props);
????}

????componentWillMount()?{
????????//?Disable?back?button?by?just?returning?true?instead?of?Action.pop()
????????BackHandler.addEventListener('hardwareBackPress',?()?=>?{return?true});
????}

????render()?{
????????let?tabNames?=?['首頁',?'試聽',?'已購',?'我的'];
????????return?(}
????????????????tabBarPosition='bottom'
????????????>);
????}
}

export?default?class?App?extends?Component?{
????render()?{
????????return?({/*首頁(tab)*/}{/*登錄*/});
????}
}

const?styles?=?StyleSheet.create({
????router:?{
????????backgroundColor:?'#e6e6e6',
????},
????root:?{
????????backgroundColor:?'#e6e6e6',
????},
????title:?{
????????color:?'#ffffff',
????},
});

這樣就把路由和tab集成到一起了,關(guān)于路由的使用這里有個詳解《react-native-router-flux使用技巧(API篇)》,我這里就說一些簡單的跳轉(zhuǎn)。

Actions.pop()

返回上一頁。

Actions.key()

不帶參跳轉(zhuǎn)到鍵為key的頁,Actions.key()中的key即為Scene的key屬性值,如代碼中的home和signInOrUp。


Actions.key(param)

帶參數(shù)跳轉(zhuǎn)到鍵為key的頁,Actions.key()中的key即為Scene的key屬性值,如代碼中的home和signInOrUp。

參數(shù)可以通過屬性獲取,如this.props.param。

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

納祥科技推出太陽能+Type-C雙充電自行車前燈方案,方案核心模塊包含太陽能板、單片機、三極管、3顆LED燈珠與1200mAh電池,通過低功耗單片機與三極管驅(qū)動,支持強光/弱光/爆閃3種模式,高流明遠(yuǎn)射程,適配多種車型

關(guān)鍵字: 方案開發(fā) 電子方案 自行車前燈方案 納祥科技

慕尼黑2025年9月11日 /美通社/ -- 當(dāng)?shù)貢r間9月9日,賽力斯動力在德國慕尼黑國際車展期間舉辦技術(shù)發(fā)布與交流會,正式在海外市場推出全新一代賽力斯超級增程、高效發(fā)動機和新一代分布式電驅(qū)動系統(tǒng),同時與來自全球的汽車產(chǎn)...

關(guān)鍵字: 慕尼黑 分布式 發(fā)動機 新能源汽車

慕尼黑2025年9月11日 /美通社/ -- 高端智能電動汽車品牌問界(AITO)在2025年德國國際汽車及智慧出行博覽會(IAA MOBILITY)上,正式發(fā)布了其最新全球產(chǎn)品陣容——專為中東市場深度本地化打造的AIT...

關(guān)鍵字: AI 智能駕駛 測試 生態(tài)系統(tǒng)

舍弗勒首次為中國頭部車企大規(guī)模生產(chǎn)高壓逆變磚 天津工廠一年內(nèi)完成量產(chǎn)準(zhǔn)備,逆變器模塊性能參數(shù)顯著提升 與合作伙伴羅姆半導(dǎo)體共研尖端碳化硅技術(shù),效率更高、性能更優(yōu) 模塊化可擴展設(shè)計使逆變磚易于集成,可廣泛...

關(guān)鍵字: 逆變 高壓 逆變器 集成

舍弗勒以"專注驅(qū)動技術(shù)的科技公司"為主題亮相IAA MOBILITY 2025(B3館B40展臺) 合并緯湃科技后首次亮相IAA MOBILITY,展示拓展后的汽車產(chǎn)品組合 憑借在軟件、...

關(guān)鍵字: 電氣 軟件 驅(qū)動技術(shù) BSP

拉斯維加斯2025年9月11日 /美通社/ -- 在9月8日至11日舉辦的RE+ 2025展會上,全球綜合儲能解決方案供應(yīng)商德賽電池(Desay Battery)全面展示了其創(chuàng)新成果,并宣布與深圳市華寶新能源股份有限公司...

關(guān)鍵字: 電池 電芯 人工智能 鋰電

香港2025年 9月12日 /美通社/ -- 全球領(lǐng)先的互聯(lián)網(wǎng)社區(qū)創(chuàng)建者 - 網(wǎng)龍網(wǎng)絡(luò)控股有限公司 ("網(wǎng)龍"或"本公司",香港交易所股票代碼:777)欣然宣布,其子公司My...

關(guān)鍵字: AI 遠(yuǎn)程控制 控制技術(shù) BSP

慕尼黑2025年9月12日 /美通社/ -- 慕尼黑當(dāng)?shù)貢r間9月10日,在2025德國國際汽車及智慧出行博覽會(IAA MOBILITY)上,國際獨立第三方檢測、檢驗和認(rèn)證機...

關(guān)鍵字: 測試 慕尼黑 模型 HUBER

上海2025年9月12日 /美通社/ -- 近日,國際獨立第三方檢測、檢驗和認(rèn)證機構(gòu)德國萊茵TÜV大中華區(qū)(簡稱"TÜV萊茵")為上海...

關(guān)鍵字: 測試 信息安全 安全管理 開關(guān)

廣州2025年9月12日 /美通社/ -- 9月11日,由國際獨立第三方檢測、檢驗和認(rèn)證機構(gòu)德國萊茵TÜV大中華區(qū)(簡稱"TÜV萊茵"...

關(guān)鍵字: 數(shù)字化 供應(yīng)鏈 控制 電子
關(guān)閉