React Native学习-将 'screen', 'window' or a view生成图片

https://github.com/facebook/react-native/commit/ac12f986899d8520527684438f76299675dc0daa

这是react-native自带的生成图片的属性,所以使用之前只需要引用UIManager属性即可;

View生成图片:

state = {
    uri: null
};

takeToImage() {
    UIManager.takeSnapshot(this.refs.location, {format: 'png', quality: 0.8}).then(
        (uri) => this.setState({uri})
    ).catch(
        (error) => alert(error)
    );
}

render() {
    return (<View>
            <View ref='location'>
                <Text>东经</Text>
                <Text>东经</Text>
                <Text>西经</Text>
                <Text>东经</Text>
            </View>

            <Text onPress={()=>this.takeToImage()}>生成图片</Text>

            <Image source={{uri: this.state.uri}} style={{borderWidth:1,height:50,width:300}}/>
        </View>
    )
}