【问题标题】:How to set header title after navigatiing to a page in react native导航到反应本机页面后如何设置标题标题
【发布时间】:2020-01-15 05:53:43
【问题描述】:

我在我的项目中使用了堆栈导航器,我想在导航到屏幕后设置标题标题。看到示例后我就是这样做的。ProductListView 是一个功能组件。但它没有改变。

import React, { useState, useLayoutEffect, useRef, useContext } from "react";
import {
  StyleSheet,
  Dimensions,
  ScrollView,
  ImageBackground,
  Platform,
  ActivityIndicator,
  FlatList,
  AsyncStorage,
View
} from "react-native";

const { width, height } = Dimensions.get("screen");

const ProductDetails = ({ navigation }) => {

  return (
    <View flex={1}>

        <Text>Details</Text>

    </View>
  );
};

const styles = StyleSheet.create({

});


ProductDetails.navigationOptions = () => {
  title: "test";
};

export default ProductDetails;

更新完整代码

谢谢 乌特帕尔梅蒂

【问题讨论】:

  • 这段代码你在哪里写的?
  • 在导出组件之前 Like this ProductListView.navigationOptions = { title: "Home Product" };导出默认 ProductListView;
  • 实际问题是什么,你想要什么不清楚
  • 实际问题是我想根据我在屏幕 useEffect 函数中获得的值设置标题标题
  • 嗨,我已经更新了完整代码

标签: react-native react-native-navigation


【解决方案1】:

你需要这样设置标题。

ProductDetails.navigationOptions = () => ({
   topBar: {
        title: {
            text: 'My Title'
        }
    }
});

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多