App.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, {Component} from 'react';
  9. import {Platform, StyleSheet, Text, View ,Image} from 'react-native';
  10. import ImagePicker from 'react-native-image-crop-picker';
  11. const instructions = Platform.select({
  12. ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  13. android:
  14. 'Double tap R on your keyboard to reload,\n' +
  15. 'Shake or press menu Text for dev menu',
  16. });
  17. export default class App extends Component{
  18. constructor(props){
  19. super(props)
  20. this.state={
  21. list:[{}]
  22. }
  23. }
  24. componentWillMount(){
  25. }
  26. render() {
  27. const {list} = this.state
  28. return (
  29. <View style={styles.container}>
  30. <Text
  31. style={styles.margin}
  32. onPress={()=>{
  33. ImagePicker.openPicker({
  34. width: 300,
  35. height: 400,
  36. cropping: true,
  37. cropperChooseText:'确认',
  38. cropperCancelText:"取消"
  39. }).then(image => {
  40. list.push(image)
  41. this.setState({
  42. list
  43. })
  44. console.log(image);
  45. });
  46. }}>
  47. 点击
  48. </Text>
  49. <Text
  50. style={styles.margin}
  51. onPress={()=>{
  52. ImagePicker.openPicker({
  53. multiple: true,
  54. cropping:true,
  55. cropperChooseText:'确认',
  56. cropperCancelText:"取消"
  57. }).then(images => {
  58. list.push(images)
  59. this.setState({
  60. list
  61. })
  62. console.log(images);
  63. });
  64. }}>
  65. 点击
  66. </Text>
  67. <Text
  68. style={styles.margin}
  69. onPress={()=>{
  70. ImagePicker.openCamera({
  71. width: 300,
  72. height: 400,
  73. cropping: true,
  74. cropperChooseText:'确认',
  75. cropperCancelText:"取消"
  76. }).then(image => {
  77. list.push(image)
  78. this.setState({
  79. list
  80. })
  81. console.log(image);
  82. });
  83. }}>
  84. 点击
  85. </Text>
  86. <View style={{backgroundColor:'#333',width:375,height:400}}>
  87. {
  88. list.map((item,index)=>{
  89. console.log(item.path)
  90. let source = { uri: item.path };
  91. return (
  92. <Image
  93. style={{width:100,height:100}}
  94. key={index} source={source}></Image>
  95. )
  96. })
  97. }
  98. </View>
  99. </View>
  100. );
  101. }
  102. }
  103. const styles = StyleSheet.create({
  104. margin:{
  105. marginBottom:20
  106. },
  107. container: {
  108. flex: 1,
  109. justifyContent: 'center',
  110. alignItems: 'center',
  111. backgroundColor: '#F5FCFF',
  112. },
  113. welcome: {
  114. fontSize: 20,
  115. textAlign: 'center',
  116. margin: 10,
  117. },
  118. instructions: {
  119. textAlign: 'center',
  120. color: '#333333',
  121. marginBottom: 5,
  122. },
  123. });