美文网首页
React Native将 'screen',

React Native将 'screen',

作者: 冷洪林 | 来源:发表于2017-06-27 11:43 被阅读313次

开发中有市会遇到这种需求:把某个view生成图片进行分享。其实React Native有提供相应的API(目前仅适用iOS): https://github.com/facebook/react-native/commit/ac12f986899d8520527684438f76299675dc0daa.


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',

      本文链接:https://www.haomeiwen.com/subject/uqtecxtx.html