如何在触摸 ListItem 时导航到新屏幕?我的 ListItems 与 Chevrons 朝右,给人的印象是触摸 ListItem 会进入详细屏幕。然后,一个详细的屏幕将返回到原始的 ListItem 屏幕。
我的 ListItem 在 Menu.js 中,我有一个屏幕 Home.js,导入到 Menu.js 我然后将主屏幕放入
const ListitemDetail = createStackNavigator({
Home: Home
});
然后我在我的 ListItem 中使用了 ListitemDetail 反应元素
<ListItem
key={i}
title={item.title}
leftIcon={{ name: item.icon }}
bottomDivider={true}
chevron
onPress={() => this.props.navigation.navigate("ListitemDetail")}
/>
它没有导航到 ListitemDetial 的主页。
但是当我直接使用“主页”时,它会将我带到主屏幕,这样做的缺点是,我无法返回(显然,返回箭头不会出现在标题上)
onPress={() => this.props.navigation.navigate("Home")}
这是我的 Menu.js
import React, { Component } from "react";
import {
Text,
StyleSheet,
View,
Animated,
ScrollView,
SectionList,
SafeAreaView,
FlatList
} from "react-native";
import { createStackNavigator } from "react-navigation";
import Home from "./Home";
import { ListItem } from "react-native-elements";
const ListitemDetail = createStackNavigator({
Home: Home
});
const list2 = [
{
title: "Appointments",
icon: "av-timer"
},
{
title: "Trips",
icon: "flight-takeoff"
}
];
export default class Menu extends Component {
render() {
return (
<SafeAreaView>
<ScrollView>
<View>
{list2.map((item, i) => (
<ListItem
key={i}
title={item.title}
leftIcon={{ name: item.icon }}
bottomDivider={true}
chevron
onPress={() => this.props.navigation.navigate("ListitemDetail")}
/>
))}
</View>
</ScrollView>
</SafeAreaView>
);
}
}
理想情况下,我想要实现的是whatsapp上的“设置”屏幕或Facebook上的“菜单”屏幕。有没有更好的方法来做到这一点?