0

我正在尝试预览在下一个场景中获得的图像,但是当我单击相机按钮时不会发生过渡。

import { Actions } from 'react-native-router-flux';
import Camera from 'react-native-camera';

export default class PageTwo extends Component {
  render() {
    return (
      <View style={styles.container} >
         <Camera ref={(cam) => { this.camera = cam; }}
            style={styles.preview}
            aspect={Camera.constants.Aspect.fill}>
                <Text style={styles.capture} 
                      onPress={this.takePicture.bind(this)}> 
                         <Icon name="ios-camera"/>
                </Text>
         </Camera>
      </View>
    )
 }

 takePicture() {
     this.camera.capture()
       .then((data) => {Actions.previewimg});
 }
}
4

2 回答 2

0

martinarroyo 的答案是正确的方法。您必须正确调用它并传递数据,您必须将其作为参数传递。

应用程序崩溃主要在 Android 设备上。您必须检查您的本机 Java 代码并将其与权限一起正确插入(许多人忘记了权限)。有时由于经常崩溃,您的相机通常会停止工作。因此,给它一些时间并打开您设备的默认相机应用程序,然后再次打开您的应用程序。它会起作用的。

于 2017-06-13T17:03:35.547 回答
0

I think that the problem is that you are not calling the router transition properly. Actions holds a function that makes a transition to a certain screen, with the same name given in the key prop of each <Scene>. These are functions, and so you have to call them. Change your code to do:

takePicture() {
     this.camera.capture()
       .then((data) => {Actions.previewimg()});
}

Also, the data will not be passed to the next screen unless you explicitely do so. So your code should look like this:

takePicture() {
     this.camera.capture()
       .then((data) => {Actions.previewimg({data: data}});
}

And then your previewimg scene will have an extra prop called data that will hold your image.

于 2016-12-17T09:19:49.487 回答