react-native - 如何在 react native 中使用 react-native-animated-tabbar 库
问题描述
我正在尝试学习如何使用这个库。 https://github.com/gorhom/react-native-animated-tabbar
在使用部分中,我正在关注独立组件 AnimatedTabBarView,这是我在遵循使用部分之后所做的。示例代码似乎使用了打字稿,在我的应用程序中我没有使用打字稿,所以我修改了 const tabs 行,这可能会导致问题。我的主要目的只是尝试在屏幕上显示一个标签栏。
import React, { useEffect, useState } from "react";
import { StyleSheet, View, ScrollView, Text } from "react-native";
import AnimatedTabBar, {
TabsConfig,
AnimatedTabBarView,
BubbleTabBarItemConfig,
} from "@gorhom/animated-tabbar";
import { AntDesign } from "@expo/vector-icons";
const tabs = {
Home: {
labelStyle: {
color: "#5B37B7",
},
icon: {
component: AntDesign,
activeColor: "rgba(91,55,183,1)",
inactiveColor: "rgba(0,0,0,1)",
},
background: {
activeColor: "rgba(223,215,243,1)",
inactiveColor: "rgba(223,215,243,0)",
},
},
Profile: {
labelStyle: {
color: "#1194AA",
},
icon: {
component: AntDesign,
activeColor: "rgba(17,148,170,1)",
inactiveColor: "rgba(0,0,0,1)",
},
background: {
activeColor: "rgba(207,235,239,1)",
inactiveColor: "rgba(207,235,239,0)",
},
},
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#999",
},
tabBarContainer: {
borderRadius: 25,
},
});
const test = () => {
const [index, setIndex] = useState(0);
return (
<View style={styles.container}>
<Text>{index}</Text>
<AnimatedTabBarView
tabs={tabs}
itemOuterSpace={{
horizontal: 6,
vertical: 12,
}}
itemInnerSpace={12}
iconSize={20}
style={styles.tabBarContainer}
index={index}
onIndexChange={setIndex}
/>
</View>
);
};
export default test;
谢谢你的帮助!
解决方案
图标组件错误。你可以检查这个例子。
要使用 react-native-vector-icons,请在组件中尝试这样的操作
icon: {
component: () => <FeatherIcon name="user" size={20} />,
activeColor: 'rgba(91,55,183,1)',
inactiveColor: 'rgba(0,0,0,1)',
}
推荐阅读
- javascript - 如何使用json在amcharts折线图中绘制多条线?
- angular - 如何组合订阅值
- mongodb - 在嵌套对象猫鼬中按用户分组
- c++ - 对象具有不兼容的类型限定符,可能是继承/多态错误?
- android - 如何在android的提示文本中设置字母间距
- linux - 建立单独的匹配和不匹配文件列表
- javascript - 循环遍历 div 的所有子项
- ios - 存在 UIToolbarContentView 时无法同时满足约束
- python - How can I calculate the distance between two cameras (opencv-python)?
- python - Compare files in two directories with python to look for files that are in one directory but not the other -agnostic to subdirectory structure