如何在不渲染组件的情况下获取引用

时间:2018-02-21 11:27:45

标签: react-native react-native-maps

我使用Airbnb的react-native-maps。我想拍摄快照而不渲染mapView。这是可能的。 我的代码是这样的:

componentDidMount(){
 const map = <MapView ref={map => this.mapRef = map} />
 const snapshot = this.mapRef.takeSnapshot({
        width: 300,
        height: 300,
        region: {
            latitude: 37.78825,
            longitude: -122.4324
        },
        format: 'png',
        quality: 0.8,
        result: 'file'
    });
    snapshot.then((uri) => {
        console.warn(uri);
    });

}

mapRef未定义。为什么???

0 个答案:

没有答案
相关问题