javascript - 看起来您正在为屏幕“添加”的“组件”道具传递一个内联函数(例如 component={() =>})
问题描述
我面临的问题是 react-navigation 给了我警告,我正在为组件 prop 传递一个内联函数。按照代码:
const Tab = createBottomTabNavigator();
export default function TabNavigator ({navigation, route}) {
return (
<Tab.Navigator
initialRouteName="Home"
tabBarOptions={{activeTintColor: "#6b6b6b", inactiveTintColor: "#d3d3d3", labelStyle: {fontSize: RFValue(8), top: -5, fontFamily: 'Montserrat-Regular'}, style:{borderTopColor: 'transparent'}}}>
<Tab.Screen
name="Home"
component={Home}
options={{tabBarIcon:({color})=> (<Icon_Home name="home" size={RFValue(20)} color={color}/>)}}/>
<Tab.Screen
name="Kategorien"
component={Categories}
options={{tabBarIcon:({color})=> (<Icon_Categories name="list" size={RFValue(18)} color={color}/>)}}/>
<Tab.Screen
name="Add"
component={() => null}
options={{
tabBarIcon: (props) => (
<View style={{flex: 1, width: "100%"}}>
<TouchableOpacity
style={{flex: 1, justifyContent: "center", alignItems: "center"}}
onPress={async () => {
ActionSheetIOS.showActionSheetWithOptions (
{
options: ["Cancel", "Fotos", "Kamera"],
cameraButtonIndex: 2,
galleryButtonIndex: 1,
cancelButtonIndex: 0
},
async buttonIndex => {
if (buttonIndex === 0) {
} else if (buttonIndex === 1) {
// const {status} = await Permissions.askAsync(Permissions.CAMERA_ROLL)
// if (status == "granted") {
// let result = await ImagePicker.launchImageLibraryAsync();
// if (!result.cancelled) {
// navigation.navigate("AddReceiptScreen", {image: result});
// console.log(result);
// }
// }
console.log("Index 1 pressed.")
} else if (buttonIndex === 2) {
// const {status} = await Permissions.askAsync(Permissions.CAMERA)
// if (status == "granted") {
// // let result = await ImagePicker.launchCameraAsync();
// let result = await imageScanner;
// if (!result.cancelled) {
// navigation.navigate("AddReceiptScreen", {image: result});
// console.log(result);
// }
// }
console.log("Index 2 pressed.")
}
}
)
}}>
<Image
source={Icon_Add}
style={{width: RFValue(35), height: RFValue(35)}}/>
</TouchableOpacity>
</View>
),
tabBarLabel: () => null,
}}/>
<Tab.Screen
name="Detail"
component={Detail}
options={{tabBarIcon:({color})=> (<Icon_Detail name="bar-graph" size={RFValue(18)} color={color}/>)}}/>
<Tab.Screen
name="Profil"
component={Profile}
options={{tabBarIcon:({color})=> (<Icon_Profile name="user-alt" size={RFValue(18)} color={color}/>)}}/>
</Tab.Navigator>
)
}
如何解决警告?
解决方案
我找到了解决办法。我没有使用 component = {() => null},而是创建了另一个组件
const AddScreen = () => { return null }
并将这个用于组件。
推荐阅读
- splunk - 从 linux cli 更改 splunk 管理员密码
- firebase - Unity 编辑器中的 Firebase 初始化失败
- regex - 如何在特定单词之后匹配单个出现的字符?
- javascript - 如何使用代码使lightgallery进入全屏模式?
- reactjs - 将道具从组件传递给它的兄弟组件的子组件?
- amazon-web-services - 在 Chalice 中的 S3 存储桶对象创建事件上未触发 AWS Lambda 函数
- c++ - 如何获得 CImg 像素的位深度?
- python - 熊猫面板数据 - 考虑到年份差距,将值移动两个
- python - 在 Python 中遍历类的实例
- git - 修复合并冲突后如何绕过预提交挂钩?