【发布时间】:2019-09-18 21:22:35
【问题描述】:
【问题讨论】:
-
你搜索过 React Native 文档吗?到目前为止,您尝试过什么?
-
内嵌图片
标签: reactjs react-native react-redux navigation
【问题讨论】:
标签: reactjs react-native react-redux navigation
您可以找到许多创建自定义标签栏的教程。使用 createMaterialTopTabNavigator 创建顶栏。
import { createMaterialTopTabNavigator, createAppContainer } from "react-navigation"
import TabBar from './TabBar'
const TabNavigator = createMaterialTopTabNavigator({
feed: {
screen: () => null,
},
profile: {
screen: () => null,
},
inbox: {
screen: () => null,
}
}, {
tabBarComponent: TabBar,
})
export default createAppContainer(TabNavigator)
TabBar 组件
import * as React from "react"
import { View } from "react-native"
import Tab from './Tab'
const TabBar = (props) => {
const { navigationState, navigation, position } = props
return (
<View style={{
height: 80,
backgroundColor: 'seashell',
flexDirection: "row",
justifyContent: 'space-around',
alignItems: 'center',
}}>
{navigationState.routes.map((route, index) => {
const focusAnim = position.interpolate({
inputRange: [index - 1, index, index + 1],
outputRange: [0, 1, 0]
})
return (
<Tab
focusAnim={focusAnim}
title={route.routeName}
onPress={() => navigation.navigate(route.routeName)}
/>
)
})}
</View>
)
}
export default TabBar
标签组件
import * as React from "react"
import { Animated, TouchableOpacity } from "react-native"
const Tab = ({ focusAnim, title, onPress }) => {
return (
<TouchableOpacity onPress={onPress}>
<Animated.View
style={{
padding: 10,
borderRadius: 10,
backgroundColor: focusAnim.interpolate({
inputRange: [0, 1],
outputRange: ["transparent", "tomato"]
})
}}
>
<Animated.Text
style={{
color: focusAnim.interpolate({
inputRange: [0, 1],
outputRange: ["#444", "#fff"]
})
}}
>{title}</Animated.Text>
</Animated.View>
</TouchableOpacity>
)
}
export default Tab
您需要做的是根据您的需要设置样式。
【讨论】: