1
的package.json的讀取屬性「getOrientation」反應母語方位用監聽器無法未定義
{
"name": "MakeItCluster",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "15.4.1",
"react-native": "0.39.2",
"react-native-orientation-listener": "0.0.4",
"react-native-vector-icons": "^3.0.0"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "18.1.0",
"react-test-renderer": "15.4.1"
},
"jest": {
"preset": "react-native"
}
}
組件:
'use strict';
import React from 'react';
var Orientation = require('react-native-orientation-listener');
var Item = React.createClass({
componentWillMount: function() {
this._maintainDimensions();
},
render: function() {
// ...
},
_maintainDimensions: function() {
console.log(Orientation);
Orientation.getOrientation(function(err, orientation) {
// doing something here
}.bind(this));
}
});
module.exports = Item;
當我打印到控制檯的「方向」的值我看到:
{
addListener:addListener(callback)
getOrientation: getOrientation(callback)
removeListener: removeListener(listener)
__proto__: Object
}
但是,當我打電話Orientation.getOrientation下一行(), 方向未定義!
您的代碼也不起作用。其實,和我的代碼相比有什麼不同? –
我想表明的是,這不是代碼 –
順便說一句,我正在使用RN 0.36.0 –