我正在学习使用ViroAR(建立在本机上的反应)导入模块并尝试调用它后,我收到错误:
"undefined is not an object(evaluating '(0, format: "jpg", quality: 0.8)}.then')"
此错误源于尝试在react-native-view-shot模块上使用captureScreen方法。有谁能指出我正确的方向?我只是想在init上捕获截图作为测试。
'use strict';
import React, { Component } from 'react';
import { StyleSheet } from 'react-native';
import captureScreen from "react-native-view-shot";
import {
ViroARScene,
ViroText,
ViroMaterials,
ViroBox,
Viro3DObject,
ViroAmbientLight,
ViroSpotLight,
ViroARPlaneSelector,
ViroAnimations,
ViroNode
} from 'react-viro';
export default class HelloWorldSceneAR extends Component {
constructor() {
super();
// Set initial state here
this.state = {
text: "Initializing AR..."
};
// bind 'this' to functions
this._onInitialized = this._onInitialized.bind(this);
this._onPlaneSelected = this._onPlaneSelected.bind(this);
}
render() {
return (
<ViroARScene onTrackingUpdated={this._onInitialized}>
<ViroText text={this.state.text} scale={[.5, .5, .5]} position={[0, 0, -1]} style={styles.helloWorldTextStyle} />
<ViroARPlaneSelector minHeight={.5} minWidth={.5} onPlaneSelected={this._onPlaneSelected}>
<ViroBox position={[0, -.25, -1]} scale={[.5, .5, .5]} />
</ViroARPlaneSelector>
</ViroARScene>
);
}
_onInitialized() {
this.setState({
text: "Hello World!"
});
captureScreen({
format: "jpg",
quality: 0.8
})
.then(
uri => console.log("Image saved to", uri),
error => console.error("Oops, snapshot failed", error)
);
}
_onPlaneSelected() {
this.setState({
text: "Selected!"
});
}
}
var styles = StyleSheet.create({
helloWorldTextStyle: {
fontFamily: 'Arial',
fontSize: 30,
color: '#ffffff',
textAlignVertical: 'center',
textAlign: 'center',
},
});
ViroMaterials.createMaterials({
grid: {
diffuseTexture: require('./res/grid_bg.jpg'),
},
});
ViroAnimations.registerAnimations({
rotate: {
properties: {
rotateY: "+=90"
},
duration: 250, //.25 seconds
},
});
module.exports = HelloWorldSceneAR;
答案 0 :(得分:0)
您输入captureScreen
错误。它应该如下所示。
import { captureScreen } from "react-native-view-shot";