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文件中的斷點不會被執行,構造函數中的日誌也不會被打印。幾乎就像組件安裝失敗一樣。
有沒有人遇到過這個?任何可能的解一直試圖調試一天左右,現在沒有運氣。
此代碼是'index.android.js'因爲我們還在校對了這一點,導出類。但是,是的,在一個單獨的模塊中,我們必須導出它。話雖如此,我仍然不知道將'return null'改爲'return '會做任何事情。構造函數甚至沒有被調用,所以渲染方法不應該與它有很大關係。 –
amarkon