如何在本机中将状态传递给静态导航?

时间:2018-07-23 10:07:26

标签: react-native navigation

需要将状态传递给导航,但是 this.setState({ demo:"some title" }); ..... static navigationOptions = { headerRight:(<View> <Text>{this.state.demo}</Text> </View>), }; 不起作用,这是代码

  static void Main(string[] args)
        {
      byte[] data = new byte[1024];
            byte[] data1 = new byte[1024];

            IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
            UdpClient newsock = new UdpClient(ipep);

            IPEndPoint ipep1 = new IPEndPoint(IPAddress.Any, 1514);
            UdpClient newsock1 = new UdpClient(ipep1);

            Console.WriteLine("UDP Server is UP ! ***Waiting for a client...");

            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
            IPEndPoint sender1 = new IPEndPoint(IPAddress.Any, 0);


            data = newsock.Receive(ref sender);
            data1 = newsock1.Receive(ref sender1);

            Console.WriteLine("Message received from {0}:", sender.ToString());

            Console.WriteLine("Message received from {0}:", sender1.ToString());
            //   Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));

            //  string welcome = "Welcome to my test server";
            //  data = Encoding.ASCII.GetBytes(welcome);
            //  newsock.Send(data, data.Length, sender);

            while (true)
            {
                data = newsock.Receive(ref sender);

                data1 = newsock1.Receive(ref sender1);

                Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));
                Console.WriteLine(Encoding.ASCII.GetString(data1, 0, data1.Length));

                UpdateDB(data);
                UpdateDB1(data1);




            }



        }

2 个答案:

答案 0 :(得分:1)

尝试设置如下参数:

componentWillMount() {
     const {setParams} = this.props.navigation;
     setParams({demotxt:this.state.demo});
}

..

static navigationOptions = ({ navigation  }) => {

       const {state} = navigation;
           return {
               headerRight: (<View>
                 <Text>{state.params.demotxt}</Text>
                         </View>)
           }

};

答案 1 :(得分:0)

我修改了这一行,您应该这样称呼。

  public static boolean validateXMLSchema(String xsdPath, String xmlPath){
      try {
         SchemaFactory factory =
            SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = factory.newSchema(new File(xsdPath));
            Validator validator = schema.newValidator();
            validator.validate(new StreamSource(new File(xmlPath)));
      } catch (IOException e){
         System.out.println("Exception: "+e.getMessage());
         return false;
      }catch(SAXException e1){
         System.out.println("SAX Exception: "+e1.getMessage());
         return false;
      }

      return true;

   }

此外,您应该首先以常量声明状态,然后传递Const, 每当调用setState时。渲染函数将被调用。像这样的东西。

<Text>{this.state.demo}</Text>
                  </View>),