我正在为我的React Native应用程序使用React Navigation5.x。我有一个带有多个屏幕的堆栈导航器,例如仪表板和发票。我的屏幕发票具有自定义标题,因此我不使用React Navigation标题选项。因此,我无法像使用React Navigation的标题那样在后退按钮中显示上一个屏幕的标题。
我当然可以在自定义标题中放置一个自定义的GoBack按钮,但我希望使用上一个屏幕的标题。
是否可以获取用户来自哪个屏幕/路线的标题?尝试了几件事,例如使用dragonallyGetParent(),但那没有用。
答案 0 :(得分:0)
您可以将当前屏幕名称作为参数发送
props.navigation.navigate("invoices", { previous_screen: "dashboard" } )
并在下一个屏幕中读取该参数
props.navigation.state.params.previous_screen
答案 1 :(得分:0)
您可以从传递到自定义标头的function Header({ scene, previous }) {
const { options } = scene.descriptor;
let previousTitle;
// The label for the back button shows the title of the previous screen
// If a custom label is specified, we use it, otherwise use previous screen's title
if (options.headerBackTitle !== undefined) {
previousTitle = options.headerBackTitle;
} else if (previous) {
const o = previous.descriptor.options;
previousTitle =
typeof o.headerTitle !== 'function' && o.headerTitle !== undefined
? o.headerTitle
: o.title !== undefined
? o.title
: previous.route.routeName;
}
// Rest of the header content
}
道具中获取它。
示例:
# Initialize your separator and filename
sep = '|'
filename = 'some.csv'
# Read the first line and remove the double quote
with open(filename, newline='') as f:
reader = csv.reader(f)
row1 = next(reader)
cols = row1.replace('"','').split(sep)