代码之家  ›  专栏  ›  技术社区  ›  suman j

反应导航标题已包装

  •  4
  • suman j  · 技术社区  · 8 年前

    堆栈导航器

    版本:

    1. “react navigation”:“^1.0.0-beta.11”
    2. “react native”:“^0.47.2”

      };

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  12
  •   suman j    8 年前

    通过与设备宽度匹配的宽度指定headerTitleStyle来求解它。

    static navigationOptions = {
        title: "Personal Information",
        headerBackTitle : null,
        headerTitleStyle : {width : Dimensions.get('window').width}
    };
    
        2
  •  0
  •   Ben    4 年前

    如果您的标题根据您传递给的内容动态更改 route 作为参数,标题将不会被截断并溢出。为了避免这种情况,您可以这样做:

    function truncate(str: string, n: number) {
      return str.length > n ? str.substr(0, n - 1) + '...' : str;
    }
    
    <YourStack.Screen
      name="MyScreen"
      component={MyScreen}
      options={({ route }) => ({
        title: truncate(route.params.yourObject.title, 15),
      })}
    />
    

    truncate