首页 > 解决方案 > undefined 不是函数(评估 'RNViewShot.captureRef(view,options)')

问题描述

我正在尝试通过 react native 在 android 中保存视图。在 Expo 中拍摄 viewshot 时,React native viewshot 在 android 中引发以下错误。这是我的代码

import React from 'react';
import { View ,Image,Button} from 'react-native';
import ViewShot from "react-native-view-shot"
import { captureRef } from "react-native-view-shot";
export default class App extends React.Component {
  constructor(props){
super(props)
this.capture = this.capture.bind(this)
}
capture(){
 this.refs.viewShot.capture().then(uri => {
  console.log("do something with ", uri);
},(error)=>{console.log("error",error)})
}
render() {
return (
  <View  style={styles.container}>
  <ViewShot ref="viewShot" >
    <Image  source={require("./batman.jpg")}>
    </Image>
  </ViewShot>
  <Button
  title="save"
  onPress={this.capture}
  >
  </Button>
  </View>
);
}
}

在此处输入图像描述

标签: reactjsreact-nativereact-native-android

解决方案


推荐阅读