설명 없음

Viewshoot.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Sample How To Screenshot Screen inside of ScrollView
  3. * The original github from
  4. * https://github.com/gre/react-native-view-shot
  5. */
  6. import React, {Component} from 'react';
  7. import {ScrollView, StyleSheet, Text, View, Button, Image, } from 'react-native';
  8. import ViewShot from "react-native-view-shot";
  9. export default class App extends Component {
  10. constructor(props) {
  11. super(props)
  12. this.state={
  13. error: null,
  14. res: null,
  15. options: {
  16. format: "jpg",
  17. quality: 0.9
  18. }
  19. }
  20. }
  21. renderContent()
  22. {
  23. const data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
  24. return data.map((item,index) => {
  25. return (
  26. <View style={styles.item} key={index}>
  27. <Text>{item}</Text>
  28. </View>
  29. );
  30. })
  31. }
  32. renderResultSnapshot()
  33. {
  34. if(this.state.res!==null)
  35. {
  36. console.log('Result on return snapshot: ', this.state.res);
  37. return(
  38. <Image
  39. fadeDuration={0}
  40. resizeMode="contain"
  41. style={styles.previewImage}
  42. source={this.state.res}
  43. />
  44. );
  45. }
  46. return;
  47. }
  48. renderShootButton(){
  49. return(
  50. <Button
  51. onPress={ async () => await this.captureViewShoot()}
  52. title="Shoot Me"
  53. color="#841584"
  54. />
  55. )
  56. }
  57. captureViewShoot()
  58. {
  59. this.refs.full.capture().then(uri => {
  60. console.log("do something with ", uri);
  61. this.setState({res: {uri: uri}})
  62. });
  63. }
  64. renderViewShot()
  65. {
  66. return(
  67. <ScrollView style={styles.container}>
  68. <ViewShot
  69. ref="full"
  70. options={{ format: this.state.options.format, quality: this.state.options.quality }}
  71. style={styles.container}
  72. >
  73. {this.renderResultSnapshot()}
  74. {this.renderContent()}
  75. {this.renderShootButton()}
  76. </ViewShot>
  77. </ScrollView>
  78. )
  79. }
  80. render() {
  81. return this.renderViewShot();
  82. }
  83. }
  84. const styles = StyleSheet.create({
  85. container: {
  86. flex: 1,
  87. backgroundColor: '#fff'
  88. },
  89. content: {
  90. padding: 10,
  91. backgroundColor: '#fff'
  92. },
  93. item: {
  94. height: 50,
  95. },
  96. previewImage: {
  97. width: 375,
  98. height: 300
  99. },
  100. });