English 中文(简体)
• 如何在(冻结的)StackNavigator内实施习俗头脑??
原标题:How to implement custom header icons within a (nested) StackNavigator?

这可能是一个不明确的问题,但尽管我阅读了文件和其他资料来源,但我还是没有像照片一样,在StackNavigator的头盔中执行两个或两个以上可点击的漫画。 如果 st夫想要显示后方,他就被允许 over笑。

This is how the (root) home-screen could look like. Once the user starts clicking on the content, the menu-item should be replaced with the back-button from the stackNavigator (ideally on any platform). Mockup of what I want to achieve.

www.un.org/Depts/DGACM/index_spanish.htm 我迄今为止所做的工作:。 我从一个品牌新模板开始,选择了<代码>-tabs>在上运行expo。 我在文件MainTabNavigator.js上做了一些小改动。

import React from  react ;
import { Platform } from  react-native ;
import { createStackNavigator, createBottomTabNavigator } from  react-navigation ;
import CustomHeader from  ../components/CustomHeader ;
import HomeScreen from  ../screens/HomeScreen ;    

const HomeStack = createStackNavigator( { Home: HomeScreen }, {
   // default config for screens in the stack, so `Home` will use this title 
  navigationOptions: { 
    title:  Protype Prompter: Browse ,
    header: props => <CustomHeader {...props} />,
    }}
);
// All other code stays like provided by expo init.
export default createBottomTabNavigator({
  HomeStack,
});

其次,我确信在HomeScreen.js内。 负责人不是手写的:

export default class HomeScreen extends React.Component {
  /* static navigationOptions = {
    header: null,
  }; */

请与我接洽Custom Header.js。 迄今为止,我的所有努力都没有导致家庭屏幕上的任何明显变化。

import React from "react";
import { Header } from "react-navigation";
import { View, Platform, Image, StyleSheet } from "react-native";
import { SimpleLineIcons } from  @expo/vector-icons ; 
const CustomHeader = props => {
  return (
    <View>
        <SimpleLineIcons name="menu" size={24} color={tintColor} />
         <Header headerLeft={<SimpleLineIcons name="menu" size={24} color= #6a1b9a  />} {...props} />
    </View>
  );
};
export default CustomHeader;

除其他来源外,我还咨询了以下网站:

  1. The documentation on headers and header buttons
  2. A github discussion on a react-navitation issue
  3. A howto on modifying headers and another one on customer headers with react-navigation. The latter seemed to be a good starting point.
最佳回答

This is pretty easy actually. Considered you are using React Navigation V2 or V3, take a look at the createStackNavigator docs.

这里有<条码>head/条码>和<条码>head/条码>,两者均可兼具习惯成分。 因此,你可以很容易地把你的榜样放在首位。

Edit

因此,我很快树立了一个榜样:

在<代码>App.js:

import React, { Component } from "react";
import Navigator from "./navigation/navigation";

export default class App extends Component {
  render() {
    return <Navigator />;
  }
}

navigation.js:

import { createStackNavigator } from "react-navigation";
import HomeScreen from "../screens/HomeScreen";

const RootStack = createStackNavigator({ HomeScreen });

export default RootStack;

现在你可以像现在这样通过屏幕设计你的头盔:

import React, { Component } from "react";
import { Platform, StyleSheet, Text, View } from "react-native";
import { SafeAreaView } from "react-navigation";
import { Icon } from "react-native-elements";

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  icon: {
    paddingLeft: 10
  },
  iconContainer: {
    flexDirection: "row",
    justifyContent: "space-evenly",
    width: 120
  }
});

export class HomeScreen extends Component {
  static navigationOptions = {
    title: "Title",
    headerLeft: (
      <Icon
        containerStyle={styles.icon}
        type="ionicon"
        name={Platform.OS === "ios" ? "ios-menu" : "md-menu"}
      />
    ),
    headerRight: (
      <View style={styles.iconContainer}>
        <Icon type="ionicon" name={Platform.OS === "ios" ? "ios-search" : "md-search"} />
        <Icon type="ionicon" name={Platform.OS === "ios" ? "ios-heart" : "md-heart"} />
        <Icon type="ionicon" name={Platform.OS === "ios" ? "ios-more" : "md-more"} />
      </View>
    )
  };

  render() {
    return (
      <SafeAreaView styles={styles.container}>
        <Text>Hi from the HomeScreen.</Text>
      </SafeAreaView>
    );
  }
}

export default HomeScreen;

I used the <Icon /> content fromactive-native-elements. 您可以通过向它们提供<代码>onPresspropp>来点击这些微粒。

这里是关于SOS成果的简介:

“enterhchr

Shameless plug: If you want to know more about React Navigation you might like my tutorial in which I guide you through building an application with production ready navigation settings.

问题回答

如今,可在React Navigation edition 6.x and Reactindigenous edition 0.68中直接通过headerLeftheaderRights/code>,载于Stack.Screen soptions propp>。

此处请参看<代码> 标题功能,作为<代码>Stack.Screen中的一些Icon:

      <Stack.Screen
    name="Home"
    component={HomePage}
    options={{
      headerLeft: (props) => (
        <Pressable
          android_ripple={{
            color:  #666666 ,
            foreground: true,
            borderless: true,
          }}
          onPress={() => {navigation.openDrawer()}}>
          <Ionicon
            style={{paddingLeft: 10}}
            name={Platform.OS ===  ios  ?  ios-menu  :  md-menu }
            size={25}
          />
        </Pressable>
      ),
    }}
  />

See the result in screenshot below: enter image description here

您可以像以下所述守则那样,在您的级别上使用。

static navigationOptions = {
    headerTitle:  Home Page ,
    headerRight: (
      <View style={{ flexDirection:  row  }}>
        <TouchableOpacity activeOpacity={0.7}
            onPress={() => { params.logoutClick() }}>
            <Text style={navItemTxt}> Logout</Text>
        </TouchableOpacity >
        <TouchableOpacity activeOpacity={0.7}
            onPress={() => { params.clearCartClick() }}>
            <Image source={require( ../images/search/ic_clear_cart.png )}
                style={navItemImg} />
        </TouchableOpacity >
        <ConnectedBadgeTitle navigation={navigation} badgeAction={() => { navigation.navigate( Cart ); }} />
    </View >
    ),
  };

请考虑<代码>route.js。 页: 1

import { StackNavigator } from "react-navigation";
import Home from "./home.js";
import Login from "./login.js";

export default Navigator = StackNavigator({
  Home: { screen: Home },
  Login: { screen: Login },
});

Using native-base can create custom header view

// CustomHeader.js
import { Header, Left, Right, Body, Thumbnail } from "native-base";
<Header
  style={{
    backgroundColor: "#f8f8f8",
    alignItems: "center",
    justifyContent: "center",
  }}
>
  <Left style={{ flexDirection: "row" }}>
    <Icon
      name="ios-menu-outline"
      color="#000"
      size={26}
      style={{ paddingLeft: 15, width: 40 }}
      onPress={}
    />
  </Left>
  <Body style={{}}>
    <Text style={{}}>Name</Text>
  </Body>
  <Right>
    <Icon
      name="ios-menu-outline"
      color="#000"
      size={26}
      style={{ paddingLeft: 15, width: 40 }}
      onPress={}
    />
  </Right>
</Header>

file

https://github.com/root-second/react-native-drawer”rel=“nofollow noreferer” 提要部分

static navigationOptions = {
    header: null,
};

under your drawer component can create custom header

render(){
  return(
    <Drawer> //Assumed you have some drawer component
        <CustomHeader data={"title"}/>
        <ScrollView>
        </ScrollView>
    </Drawer>
  )
}




相关问题
HandleClick not being recognized as a prop

I m trying to get my menu to show when I click the sidebar, but I m getting an error "react-dom.development.js:86 Warning: React does not recognize the handleClick prop on a DOM " import { ...

Is there an equivalent to localStorage in React Native?

I d like to implement the equivalent to the javascript localStorage in my React Native app. But I m unsure how to set. To function how I want it to, I would like the localStorage to be stored every ...

Video Calling in Expo React Native Application

I am building a React Native Application using Expo and I want to integrate a 1:1 video calling functionality in the app. From what I have researched so far on the topic is that I can use SDKs of ...

热门标签