Tam*_*fer 6 icons frontend react-native react-native-ios react-navigation
我正在使用React Native for ios创建一个应用程序.我没有活动的tintColor,而是想要在选定的选项卡上显示两个小三角形(另一个图像/图标).重要的是,三角形的中心y轴=对于标签栏图像底部的y轴,并且标签图标位于三角形的中心,如下所示.目前我有标签栏,图标和导航工作 - 我只是不知道如何使三角形出现:
ICON TABS
import React, {Component} from 'react';
import {
Image,
TouchableOpacity,
View
} from 'react-native';
class IconTab extends Component {
render() {
let icon = require('./Assets/Settings.png');
const {press, focused, index} = this.props;
if (index === 0) {
icon = require('./Assets/Settings.png');
} else if (index === 1) {
icon = require('./Assets/Home.png');
} else if (index === 2) {
icon = require('./Assets/Search.png');
} else if (index === 3) {
icon = require('./Assets/Inbox.png');
} else {
icon = require ('./Assets/Profile.png');
}
return (
<TouchableOpacity onPress={press}>
<Image source={icon} resizeMode={'contain'}/>
</TouchableOpacity>
);
}
}
export default IconTab;
Run Code Online (Sandbox Code Playgroud)
TAB BAR
import React, { Component } from 'react';
import { View, Platform, StyleSheet, Image, TouchableOpacity } from 'react
native';
import {SafeAreaView} from 'react-navigation';
import IconTab from "./IconTab";
class TabBar extends Component {
render() {
const {
navigation,
jumpToIndex,
} = this.props;
const {
routes
} = navigation.state;
return (
<SafeAreaView forceInset={{ top: 'always' }}>
<View style={styles.tabbarcontainer}>
<Image
style={styles.bg}
source={require('./Assets/Header.png')}
resizeMode={'stretch'}/>
<View style={styles.tabbar}>
{routes && routes.map((route, index) => {
const focused = index === navigation.state.index;
const tabKey = route.key;
return <IconTab
press={() => jumpToIndex(index)}
key={route.key}
index={index}
focused={focused}
/>
})}
</View>
</View>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
tabbarcontainer: {
height: 50,
},
bg: {
position: 'absolute',
width: '100%',
height: 44,
alignSelf: 'center',
},
tabbar: {
margin: 5,
height: 34,
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
alignContent: 'center',
backgroundColor: 'transparent',
borderTopColor: 'transparent',
},
});
export default TabBar;
Run Code Online (Sandbox Code Playgroud)
TAB NAVIGATOR
import {TabNavigator} from 'react-navigation';
import TabBar from "./TabBar";
import Settings from "./Settings";
import Home from "./Home";
import Search from "./Search";
import Inbox from "./Inbox";
import Profile from "./Profile";
export const TabRouter = TabNavigator({
Settings: {
screen: Settings,
},
Home: {
screen: Home,
},
Search: {
screen: Search,
},
Inbox: {
screen: Inbox,
},
Profile: {
screen: Profile,
},
}, {
initialRouteName: 'Home',
tabBarComponent: TabBar,
tabBarPosition: 'top',
});
Run Code Online (Sandbox Code Playgroud)
App.js
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import {TabRouter} from "./Components/TabRouter";
export default class App extends Component {
render() {
return <TabRouter/>;
}
}
Run Code Online (Sandbox Code Playgroud)
SETTINGS,HOME,SEARCH,INBOX,MESSAGE,PROFILE屏幕是一个基本的模型,如下所示 - 这是主屏幕的一个例子:
import React, {Component} from 'react';
import { View, StyleSheet, Text, Image } from 'react-native';
export default class Home extends Component {
render () {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text style={{fontSize: 30}}>Home Screen</Text>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我用来构建它的引用是https://github.com/tuanson45/react-native-custom-tab
我非常感谢任何回复和帮助!谢谢
塔巴
import React, { Component } from 'react';
import { View, Platform, StyleSheet, Image, TouchableOpacity } from 'react-
native';
import {SafeAreaView} from 'react-navigation';
import IconTab from "./IconTab";
class TabBar extends Component {
render() {
const {
navigation,
jumpToIndex,
} = this.props;
const {
routes
} = navigation.state;
return (
<SafeAreaView style={{zIndex: 10}} forceInset={{ top: 'always' }}>
<View style={styles.tabbarcontainer}>
<Image
style={styles.bg}
source={require('./Assets/Header.png')}
resizeMode={'stretch'}/>
<View style={styles.tabbar}>
{routes && routes.map((route, index) => {
const focused = index === navigation.state.index;
const tabKey = route.key;
return <View key={route.key} style={{ alignItems: 'center' }}>
<IconTab
press={() => jumpToIndex(index)}
key={route.key}
index={index}
focused={focused}
/>
{focused && <Image source= {require('./Assets/Triangles.png')}
style={{ position: 'absolute', top: 38 }} />}
</View>;
})}
</View>
</View>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
tabbarcontainer: {
height: 44,
},
bg: {
position: 'absolute',
width: '100%',
height: 44,
alignSelf: 'center',
},
tabbar: {
margin: 5,
height: 34,
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
alignContent: 'center',
backgroundColor: 'transparent',
borderTopColor: 'transparent',
},
});
export default TabBar;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3467 次 |
| 最近记录: |