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

Posted YZ-M

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>
    )
}

 

以上是关于React Native学习-将 'screen', 'window' or a view生成图片的主要内容,如果未能解决你的问题,请参考以下文章

react native 怎么设置键盘类型

react native通过组件props的navigation实现界面跳转

React native Util 常用工具类

[RN] React Native 使用 react-native-camera 过程中报错 Found react-native-camera 'mlkit' but wasn

如何将 react-native-flux 与 react-drawer 一起使用

编译依赖于React Native0.46.4的React Native IOS工程时,出现错误“fatal error: 'React/RCTEventEmitter.h' file