App.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. loadingLabelText:'请等待...'
  40. }).then(image => {
  41. list.push(image)
  42. this.setState({
  43. list
  44. })
  45. console.log(image);
  46. });
  47. }}>
  48. 点击
  49. </Text>
  50. <Text
  51. style={styles.margin}
  52. onPress={()=>{
  53. ImagePicker.openPicker({
  54. multiple: true,
  55. cropping:true,
  56. cropperChooseText:'确认',
  57. cropperCancelText:"取消",
  58. loadingLabelText:'请等待...'
  59. }).then(images => {
  60. list.push(images)
  61. this.setState({
  62. list
  63. })
  64. console.log(images);
  65. });
  66. }}>
  67. 点击
  68. </Text>
  69. <Text
  70. style={styles.margin}
  71. onPress={()=>{
  72. ImagePicker.openCamera({
  73. width: 300,
  74. height: 400,
  75. cropping: true,
  76. cropperChooseText:'确认',
  77. cropperCancelText:"取消",
  78. loadingLabelText:'请等待...'
  79. }).then(image => {
  80. list.push(image)
  81. this.setState({
  82. list
  83. })
  84. console.log(image);
  85. });
  86. }}>
  87. 点击
  88. </Text>
  89. <View style={{backgroundColor:'#333',width:375,height:400}}>
  90. {
  91. list.map((item,index)=>{
  92. console.log(item.path)
  93. let source = { uri: item.path };
  94. return (
  95. <Image
  96. style={{width:100,height:100}}
  97. key={index} source={source}></Image>
  98. )
  99. })
  100. }
  101. </View>
  102. </View>
  103. );
  104. }
  105. }
  106. const styles = StyleSheet.create({
  107. margin:{
  108. marginBottom:20
  109. },
  110. container: {
  111. flex: 1,
  112. justifyContent: 'center',
  113. alignItems: 'center',
  114. backgroundColor: '#F5FCFF',
  115. },
  116. welcome: {
  117. fontSize: 20,
  118. textAlign: 'center',
  119. margin: 10,
  120. },
  121. instructions: {
  122. textAlign: 'center',
  123. color: '#333333',
  124. marginBottom: 5,
  125. },
  126. });