【问题标题】:react native flux router with react-native-camera用 react-native-camera 反应原生通量路由器
【发布时间】:2016-12-16 13:10:27
【问题描述】:

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

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});
 }
}

【问题讨论】:

  • 如何定义场景?
  • @AhmedAli 你是什么意思?

标签: react-native react-native-router-flux react-native-camera


【解决方案1】:

我认为问题在于您没有正确调用路由器转换。 Actions 拥有一个转换到某个屏幕的函数,每个 &lt;Scene&gt;key 属性中给出了相同的名称。这些是函数,所以你必须调用它们。更改您的代码:

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

此外,除非您明确这样做,否则数据不会传递到下一个屏幕。所以你的代码应该是这样的:

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

然后您的previewimg 场景将有一个名为data 的额外道具来保存您的图像。

【讨论】:

  • 没有在日志上得到任何东西,当我点击按钮时它现在崩溃了:/
  • 看起来组件的本机代码没有正确包含在代码中。你可能想检查一下。另外,您是否检查过本机应用程序日志(例如 adb logcat)?
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多