UNPKG

crn-cli

Version:

The Ctrip React Native CLI Tools

1 lines 3.69 kB
__d(function(g,r,i,a,m,e,d){'use strict';var t=r(d[0]),o=r(d[1]),n=r(d[2]),l=r(d[3]),s=r(d[4]),u=r(d[5]),h=r(d[6]),p=r(d[7]),c=p.CameraRoll,P=p.Image,f=p.ImageEditor,x=(p.Platform,p.StyleSheet),y=p.Text,v=p.TextInput,b=p.TouchableHighlight,E=p.View,T=r(d[8]),C=20,_=(function(p){function x(n){var u;return o(this,x),(u=l(this,s(x).call(this,n))).state={isUploading:!1,uploadProgress:null,randomPhoto:null,textParams:[]},u._isMounted=!0,u._fetchRandomPhoto=function(){c.getPhotos({first:C}).then(function(t){if(u._isMounted){var o=t.edges,n=o[Math.floor(Math.random()*o.length)],l=n&&n.node&&n.node.image;if(l){var s=l.width,h=l.height;s*=.25,h*=.25,f.cropImage(l.uri,{offset:{x:0,y:0},size:{width:s,height:h}},function(t){return u.setState({randomPhoto:{uri:t}})},function(t){})}}},function(t){})},u._addTextParam=function(){var t=u.state.textParams;t.push({name:'',value:''}),u.setState({textParams:t})},u._upload=function(){var o=new XMLHttpRequest;o.open('POST','http://posttestserver.com/post.php'),o.onload=function(){u.setState({isUploading:!1}),T.handlePostTestServerUpload(o)};var n=new FormData;u.state.randomPhoto&&n.append('image',t({},u.state.randomPhoto,{type:'image/jpg',name:'image.jpg'})),u.state.textParams.forEach(function(t){return n.append(t.name,t.value)}),o.upload.onprogress=function(t){t.lengthComputable&&u.setState({uploadProgress:t.loaded/t.total})},o.send(n),u.setState({isUploading:!0})},u._fetchRandomPhoto(),u}return u(x,p),n(x,[{key:"componentWillUnmount",value:function(){this._isMounted=!1}},{key:"_onTextParamNameChange",value:function(t,o){var n=this.state.textParams;n[t].name=o,this.setState({textParams:n})}},{key:"_onTextParamValueChange",value:function(t,o){var n=this.state.textParams;n[t].value=o,this.setState({textParams:n})}},{key:"render",value:function(){var t=this,o=null;this.state.randomPhoto&&(o=h.createElement(P,{source:this.state.randomPhoto,style:B.randomPhoto}));var n=this.state.textParams.map(function(o,n){return h.createElement(E,{style:B.paramRow},h.createElement(v,{autoCapitalize:"none",autoCorrect:!1,onChangeText:t._onTextParamNameChange.bind(t,n),placeholder:"name...",style:B.textInput}),h.createElement(y,{style:B.equalSign},"="),h.createElement(v,{autoCapitalize:"none",autoCorrect:!1,onChangeText:t._onTextParamValueChange.bind(t,n),placeholder:"value...",style:B.textInput}))}),l=this.state.isUploading?'Uploading...':'Upload',s=this.state.uploadProgress;null!==s&&(l+=' '+Math.round(100*s)+'%');var u=h.createElement(E,{style:B.uploadButtonBox},h.createElement(y,{style:B.uploadButtonLabel},l));return this.state.isUploading||(u=h.createElement(b,{onPress:this._upload},u)),h.createElement(E,null,h.createElement(E,{style:B.paramRow},h.createElement(y,{style:B.photoLabel},"Random photo from your library (",h.createElement(y,{style:B.textButton,onPress:this._fetchRandomPhoto},"update"),")"),o),n,h.createElement(E,null,h.createElement(y,{style:[B.textButton,B.addTextParamButton],onPress:this._addTextParam},"Add a text param")),h.createElement(E,{style:B.uploadButton},u))}}]),x})(h.Component),B=x.create({paramRow:{flexDirection:'row',paddingVertical:8,alignItems:'center',borderBottomWidth:x.hairlineWidth,borderBottomColor:'grey'},photoLabel:{flex:1},randomPhoto:{width:50,height:50},textButton:{color:'blue'},addTextParamButton:{marginTop:8},textInput:{flex:1,borderRadius:3,borderColor:'grey',borderWidth:1,height:30,paddingLeft:8},equalSign:{paddingHorizontal:4},uploadButton:{marginTop:16},uploadButtonBox:{flex:1,paddingVertical:12,alignItems:'center',backgroundColor:'blue',borderRadius:4},uploadButtonLabel:{color:'white',fontSize:16,fontWeight:'500'}});m.exports=_},666799,[51,3,4,5,8,9,11,15,666798]);