UNPKG

crn-cli

Version:

The Ctrip React Native CLI Tools

1 lines 3.88 kB
__d(function(g,r,i,a,m,e,d){'use strict';var t=r(d[0]),n=r(d[1]),s=r(d[2]),o=r(d[3]),l=r(d[4]),c=r(d[5]),u=r(d[6]),p=u.Alert,h=(u.Platform,u.ProgressBarAndroid,u.ProgressViewIOS),f=u.StyleSheet,y=u.Switch,E=u.Text,w=u.TouchableHighlight,b=u.View;function v(t){return Math.round(t/1e3)}var L=(function(u){function p(){return t(this,p),s(this,o(p).apply(this,arguments))}return l(p,u),n(p,[{key:"render",value:function(){return c.createElement(h,{progress:this.props.progress})}}]),p})(c.Component),H=(function(u){function h(){var n,l;t(this,h);for(var c=arguments.length,u=new Array(c),f=0;f<c;f++)u[f]=arguments[f];return(l=s(this,(n=o(h)).call.apply(n,[this].concat(u)))).state={downloading:!1,contentLength:1,responseLength:0,progressTotal:1,progressLoaded:0,readystateHandler:!1,progressHandler:!0,arraybuffer:!1},l.xhr=null,l.cancelled=!1,l._download=function(){var t;l.xhr?(t=l.xhr).abort():t=l.xhr=new XMLHttpRequest;l.state.readystateHandler&&(t.onreadystatechange=function(){if(t.readyState===t.HEADERS_RECEIVED){var n=parseInt(t.getResponseHeader('Content-Length'),10);l.setState({contentLength:n,responseLength:0})}else t.readyState===t.LOADING&&t.response&&l.setState({responseLength:t.response.length})}),l.state.progressHandler&&(t.onprogress=function(t){l.setState({progressTotal:t.total,progressLoaded:t.loaded})}),l.state.arraybuffer&&(t.responseType='arraybuffer'),t.onload=function(){if(l.setState({downloading:!1}),l.cancelled)l.cancelled=!1;else if(200===t.status){var n="Response is a string, "+t.response.length+" characters long.";t.response instanceof ArrayBuffer&&(n="Response is an ArrayBuffer, "+t.response.byteLength+" bytes long."),p.alert('Download complete!',n)}else 0!==t.status?p.alert('Error',"Server returned HTTP status of "+t.status+": "+t.responseText):p.alert('Error',t.responseText)},t.open('GET','http://aleph.gutenberg.org/cache/epub/100/pg100.txt.utf8'),t.setRequestHeader('Accept-Encoding',''),t.send(),l.setState({downloading:!0})},l}return l(h,u),n(h,[{key:"componentWillUnmount",value:function(){this.cancelled=!0,this.xhr&&this.xhr.abort()}},{key:"render",value:function(){var t=this,n=this.state.downloading?c.createElement(b,{style:S.wrapper},c.createElement(b,{style:S.button},c.createElement(E,null,"Downloading..."))):c.createElement(w,{style:S.wrapper,onPress:this._download},c.createElement(b,{style:S.button},c.createElement(E,null,"Download 5MB Text File"))),s=null,o=null;if(this.state.readystateHandler&&!this.state.arraybuffer){var l=this.state,u=l.responseLength,p=l.contentLength;s=c.createElement(b,null,c.createElement(E,{style:S.progressBarLabel},"responseText: ",v(u),"/",v(p),"k chars"),c.createElement(L,{progress:u/p}))}if(this.state.progressHandler){var h=this.state,f=h.progressLoaded,H=h.progressTotal;o=c.createElement(b,null,c.createElement(E,{style:S.progressBarLabel},"onprogress: ",v(f),"/",v(H),' ',"KB"),c.createElement(L,{progress:f/H}))}return c.createElement(b,null,c.createElement(b,{style:S.configRow},c.createElement(E,null,"onreadystatechange handler"),c.createElement(y,{value:this.state.readystateHandler,onValueChange:function(n){return t.setState({readystateHandler:n})}})),c.createElement(b,{style:S.configRow},c.createElement(E,null,"onprogress handler"),c.createElement(y,{value:this.state.progressHandler,onValueChange:function(n){return t.setState({progressHandler:n})}})),c.createElement(b,{style:S.configRow},c.createElement(E,null,"download as arraybuffer"),c.createElement(y,{value:this.state.arraybuffer,onValueChange:function(n){return t.setState({arraybuffer:n})}})),n,s,o)}}]),h})(c.Component),S=f.create({wrapper:{borderRadius:5,marginBottom:5},button:{backgroundColor:'#eeeeee',padding:8},progressBarLabel:{marginTop:12,marginBottom:8},configRow:{flexDirection:'row',paddingVertical:8,alignItems:'center',justifyContent:'space-between'}});m.exports=H},666797,[3,4,5,8,9,11,15]);