如何在屏幕上导入默认导航选项属性



我正在尝试将 react-navigation 属性导入我的屏幕,问题是我总是为不同的堆栈导入相同的 defaultNavigationOptions 然后优化我想要创建的代码作为一种函数,所以我只在每个屏幕上导入一次它,而不必像我那样多次编写它, 然后我的代码,以便他们了解更多。

    const BloquesStack = createStackNavigator(
  {
    BLOQUES: {
      screen: ScreenBloquesRedux,
      navigationOptions: ({ navigation }) => {
        return {
          headerLeft: <ButtonMenu navigation={navigation} />,
          headerRight: <ButtonHome navigation={navigation} />
        };
      }
    },
    DetalleBloques: {
      screen: DetalleBloque
    },
    IntegrantesBloque: {
      screen: IntegrantesBloque
    }
  },
  {
    defaultNavigationOptions: {
      headerBackTitle: "Atras",
      headerTitleStyle: {
        fontFamily: "RobotoCondensed-Regular",
        fontWeight: "100",
        fontSize: 20,
        textAlign: "center",
        color: white,
        flex: 1
      },
      headerStyle: { backgroundColor: blue, height: 60 },
      headerTintColor: white
    }
  }
);
export { BloquesStack };
const ComisionesStack = createStackNavigator(
  {
    COMISIONES: {
      screen: ComisionesRedux,
      navigationOptions: ({ navigation }) => {
        return {
          headerLeft: <ButtonMenu navigation={navigation} />,
          headerRight: <ButtonHome navigation={navigation} />
        };
      }
    }
  },
  {
    defaultNavigationOptions: {
      headerBackTitle: "Atras",
      headerTitleStyle: {
        fontFamily: "RobotoCondensed-Regular",
        fontWeight: "100",
        fontSize: 20,
        textAlign: "center",
        color: white,
        flex: 1
      },
      headerStyle: { backgroundColor: blue, height: 60 },
      headerTintColor: white
    }
  }
export { ComisionesStack };
const DrawerNavigator = createDrawerNavigator(
  {
    Diputados: { screen: DiputadosStack },
    Bloques: { screen: BloquesStack },
    Interbloques: { screen: InterBloquesStack },
    Comisiones: { screen: ComisionesStack },
    Autoridades: { screen: AutoridadesStack },
    "Sesion En Vivo": { screen: SesionEnVivoStack },
    "Diputados TV": { screen: DiputadosTVStack },
    "Reglamentos HCDN": { screen: PDFReglamentosStack }
  },
  {
    contentComponent: CustomDrawerContentComponent,
    drawerWidth: width / 2,
    contentOptions: {
      activeTintColor: white,
      activeBackgroundColor: Gris_Drawer,
      inactiveTintColor: "rgb(105,105,104)",
      itemsContainerStyle: {
        textAlign: "center"
      },
      labelStyle: {
        fontFamily: "RobotoCondensed-Regular",
        fontWeight: "100",
        fontSize: 17,
        marginTop: 8,
        marginLeft: 10
      }
    },
    iconContainerStyle: {
      opacity: 1
    }
  }
);

只想导入默认导航选项,我不打算修改我的导航,我只想知道是否可以完成。已经非常感谢

使用defaultNavigationOptions创建一个单独的对象

const defaultNavigationOptions = {
  headerBackTitle: "Atras",
  headerTitleStyle: {
  fontFamily: "RobotoCondensed-Regular",
  fontWeight: "100",
  fontSize: 20,
  textAlign: "center",
  color: white,
  flex: 1
  },
  headerStyle: { backgroundColor: blue, height: 60 },
  headerTintColor: white
}
const BloquesStack = createStackNavigator(
  { /* routes */ },
  { defaultNavigationOptions }
)
const ComisionesStack = createStackNavigator(
 { /* routes */ },
 { defaultNavigationOptions }
)

最新更新