小编use*_*224的帖子

React Native - 导航问题"undefined不是对象(this.props.navigation.navigate)"

我遵循本教程https://reactnavigation.org/docs/intro/ ,我遇到了一些问题.

我使用Expo Client应用程序每次渲染我的应用程序而不是模拟器/模拟器.

我的代码在下面看到.

我最初在"ChatScreen"组件上面定义了"SimpleApp"const但是这给了我以下错误:

路线'聊天'应该声明一个屏幕.例如:......等

所以我将SimpleApp的decleration移到了"AppRegistry"之上,并标记了一个新的错误

元素类型无效:期望字符串.....您可能忘记导出组件..等等

教程没有将关键词"export default"添加到任何组件中,我认为它可能与我在Expo应用程序上运行它的事实有关吗?所以我将"export default"添加到"HomeScreen",错误就消失了.

我似乎无法摆脱的新错误(基于下面的代码)如下:

undefined不是对象(评估'this.props.navigation.navigate')

我无法摆脱它,除非我删除"const {navigate}"周围的"{}"但是当我从主屏幕按下按钮时会破坏导航

import React from 'react';
import {AppRegistry,Text,Button} from 'react-native';
import { StackNavigator } from 'react-navigation';

export default class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };
  render() {
    const { navigate } = this.props.navigation;
    return (
      <View>
        <Text>Hello, Chat App!</Text>
        <Button
          onPress={() => navigate('Chat')}
          title="Chat with Lucy"
        />
      </View>
    );
  }
}



class ChatScreen extends React.Component {
  static navigationOptions = { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native expo

13
推荐指数
3
解决办法
2万
查看次数

React Native 0.48 - `scrollview没有本机的proptype

我升级到反应原生0.48后,我遇到了以下错误,它在渲染应用程序(仅在IOS中)显示

scrollview没有原生类型BOOL的RCTScrollView.onScrollAnimationEnd的proptype.如果你自己没有改变这个prop,这通常意味着你的本机代码版本和javascript代码不同步.更新oth应该使这个错误消失.

不知道为什么,但我尽可能缩小我的代码库.我尝试使用ListView时生成此错误.这是代码库:

import React from 'react';
import {AppRegistry,View,Text,StyleSheet,ListView} from 'react-native';

const styles = StyleSheet.create({
  fullView:{
    flex:1
  },
  statusBar: {
    backgroundColor:"#de3c3c",
    padding:5
  },
});



class MyComponent extends React.Component {
  constructor() {
    super();
    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(['row 1', 'row 2']),
    };
  }

  render() {
    return (
      <ListView
        dataSource={this.state.dataSource}
        renderRow={(rowData) => <Text>{rowData}</Text>}
      />
    );
  }
}

export default MyComponent;
Run Code Online (Sandbox Code Playgroud)

这是我的依赖:

  "dependencies": {
    "expo": "^20.0.0",
    "react": "^16.0.0-alpha.12",
    "react-native": "^0.48.1", …
Run Code Online (Sandbox Code Playgroud)

javascript ios react-native

9
推荐指数
1
解决办法
929
查看次数

反应原生-nativeEvent属性?

因此,即时通讯试图把我的头缠住本机,这看起来并不困难。

我的问题很简单,“ e”对象是什么,如何使用它的属性,例如“ e.nativeEvent”和“ e.nativeEvent.text”,在什么情况下?

在测试TextInput的 onChangeTextonBlur道具时,我偶然发现了这个对象。

如下所示,我可以将onChangeText属性中名为“ value”的参数传递给回调处理程序。但是,当我尝试对onBlur进行同样的操作时,我遇到了一些问题(并且检查了文档,该文档未提及有关传递给回调函数处理程序的参数的任何内容,与onChangeText不同)。

因此,我找到了这个问题,它帮助我弄清楚了如何使用e.eventNative.text属性访问TextInput中的数据。

  render(){
return(
  <View>
  <Text>indent</Text>
  <Text>indent</Text>

    <TextInput
      style={{height:60, backgroundColor: "#ededed"}} // must define a height for T.I in iOS
      placeholder="Enter Text"
      value={this.state.textValue}
      onChangeText={(value) => this.onChangeText(value)}
    />
    <Text>{this.state.textValue}</Text>

    {/* on submit editing, will find the callback function to transfer text
     when submitting button is pressed */}
    <TextInput
    style={{height:60, backgroundColor: "skyblue"}}
    placeholder="Enter Text"
    onBlur={(value) => this.onSubmit(value.nativeEvent.text)}

    /> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

5
推荐指数
1
解决办法
7309
查看次数

当前平台不支持系统托盘吗?

我正在尝试使用Java在Ubuntu 18.04上制作系统托盘应用程序。

这是我正在执行的代码:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class App {
    static{
        System.setProperty("java.awt.headless", "false");
    }
    public static void main(String[] args) {

//       if(!SystemTray.isSupported()){
//           System.out.println("System Tray is not supported.");
//           return;
//       }
       final PopupMenu popup = new PopupMenu();
       Image img = Toolkit.getDefaultToolkit().createImage("/path/img.png");
       final TrayIcon trayIcon = new TrayIcon(img);
       final SystemTray systemTray = SystemTray.getSystemTray();

       //create components of system tray
        trayIcon.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                System.out.println("In here!");
                trayIcon.displayMessage("Test","Some action happened",TrayIcon.MessageType.INFO);
            }
        });

        try{
            systemTray.add(trayIcon);
        }catch(AWTException …
Run Code Online (Sandbox Code Playgroud)

java ubuntu trayicon system-tray ubuntu-18.04

3
推荐指数
1
解决办法
1818
查看次数