2017-04-05 15 views
0

私は現在React "コンポーネント"(何も表示されておらず、ディスパッチャとして機能します)を使用して反応ネイティブアプリケーションを作成しています。 JavaScriptで。 JSコードは非常に簡単です:Reactネイティブコンポーネントがマウントされていません

import React from 'react' 
import { AppRegistry, DeviceEventEmitter } from 'react-native' 

class NativeEventDispatcher extends React.Component { 
    constructor() { 
    super() 
    console.log("anyone home?") 
    } 
    componentDidMount() { 
    DeviceEventEmitter.addListener('DoSomething',() => {}) 
    } 
    render() { 
    return null 
    } 
} 

AppRegistry.registerComponent('NativeEventDispatcher',() => NativeEventDispatcher); 

いくつかの理由が、何も起こりません

val rootView = ReactRootView(context) 
rootView.startReactApplication(reactInstanceManager, "NativeEventDispatcher", null) 
addContentView(rootView, ViewGroup.LayoutParams(0, 0)) 
reactInstanceManager.onHostResume(this, this) 

を呼び出した後。コンポーネントがマウントされず、JSファイルのブレークポイントが実行されず、コンストラクタのログは決して印刷されません。ほとんどの場合、コンポーネントのマウントが黙って失敗しているかのように。

誰もこれまでに遭遇したことはありますか?任意の潜在的なソリューションですか? 1日かそれ以上は運がないのにこれをデバッグしようとしていました。

答えて

0

私は2番目のものについてはわかりませんが、最初はこのように書いています。

import React, { Component } from 'react'; 
import { View, AppRegistry, DeviceEventEmitter } from 'react-native'; 

class NativeEventDispatcher extends Component { 
    constructor(props) { 
     super(props) 
     console.log("anyone home?") 
    } 
    componentDidMount() { 
     DeviceEventEmitter.addListener('DoSomething',() => {}) 
    } 
    render() { 
     return (
      <View></View> 
     ); 
    } 
} 

export default NativeEventDispatcher; 

AppRegistry.registerComponent('NativeEventDispatcher',() => NativeEventDispatcher); 

あなたは、私たちはまだこれを校正しているとして、このコードはindex.android.js` `にあった輸出のデフォルト

+0

であなたのクラスをエクスポートする必要があります。しかし、別のモジュールでは、エクスポートする必要があります。しかし、私はまだ 'return null'を' return 'に変更することは何もしないことを知っています。コンストラクタは呼び出されていないので、レンダリングメソッドはそれとはあまり関係がありません。 – amarkon