UNPKG

crn-cli

Version:

The Ctrip React Native CLI Tools

1 lines 8.21 kB
__d(function(g,r,i,a,m,e,d){'use strict';var t=r(d[0]),n=r(d[1]),o=r(d[2]),s=r(d[3]),l=r(d[4]),c=r(d[5]),u=r(d[6]),h=u.StyleSheet,b=u.Text,f=u.TextInput,p=u.TouchableWithoutFeedback,w=u.TouchableOpacity,E=u.View,y=u.WebView,v='rgba(255,255,255,0.8)',S='urlInput',C='webview',B='https://m.facebook.com',k=['file://*','http://*','https://*'],T=(function(u){function h(){var n,l;t(this,h);for(var c=arguments.length,u=new Array(c),b=0;b<c;b++)u[b]=arguments[b];return(l=o(this,(n=s(h)).call.apply(n,[this].concat(u)))).state={url:B,status:'No Page Loaded',backButtonEnabled:!1,forwardButtonEnabled:!1,loading:!0,scalesPageToFit:!0},l.inputText='',l.handleTextInputChange=function(t){var n=t.nativeEvent.text;/^[a-zA-Z-_]+:/.test(n)||(n='http://'+n),l.inputText=n},l.goBack=function(){l.refs[C].goBack()},l.goForward=function(){l.refs[C].goForward()},l.reload=function(){l.refs[C].reload()},l.onShouldStartLoadWithRequest=function(t){return!0},l.onNavigationStateChange=function(t){l.setState({backButtonEnabled:t.canGoBack,forwardButtonEnabled:t.canGoForward,url:t.url,status:t.title,loading:t.loading,scalesPageToFit:!0})},l.onSubmitEditing=function(t){l.pressGoButton()},l.pressGoButton=function(){var t=l.inputText.toLowerCase();t===l.state.url?l.reload():l.setState({url:t}),l.refs[S].blur()},l}return l(h,u),n(h,[{key:"render",value:function(){return this.inputText=this.state.url,c.createElement(E,{style:[W.container]},c.createElement(E,{style:[W.addressBarRow]},c.createElement(w,{onPress:this.goBack,style:this.state.backButtonEnabled?W.navButton:W.disabledButton},c.createElement(b,null,'<')),c.createElement(w,{onPress:this.goForward,style:this.state.forwardButtonEnabled?W.navButton:W.disabledButton},c.createElement(b,null,'>')),c.createElement(f,{ref:S,autoCapitalize:"none",defaultValue:this.state.url,onSubmitEditing:this.onSubmitEditing,onChange:this.handleTextInputChange,clearButtonMode:"while-editing",style:W.addressBarTextInput}),c.createElement(w,{onPress:this.pressGoButton},c.createElement(E,{style:W.goButton},c.createElement(b,null,"Go!")))),c.createElement(y,{ref:C,automaticallyAdjustContentInsets:!1,style:W.webView,source:{uri:this.state.url},javaScriptEnabled:!0,domStorageEnabled:!0,decelerationRate:"normal",onNavigationStateChange:this.onNavigationStateChange,onShouldStartLoadWithRequest:this.onShouldStartLoadWithRequest,startInLoadingState:!0,scalesPageToFit:this.state.scalesPageToFit}),c.createElement(E,{style:W.statusBar},c.createElement(b,{style:W.statusBarText},this.state.status)))}}]),h})(c.Component),x=(function(u){function h(){var n,l;t(this,h);for(var c=arguments.length,u=new Array(c),b=0;b<c;b++)u[b]=arguments[b];return(l=o(this,(n=s(h)).call.apply(n,[this].concat(u))))._handlePress=function(){!1!==l.props.enabled&&l.props.onPress&&l.props.onPress()},l}return l(h,u),n(h,[{key:"render",value:function(){return c.createElement(p,{onPress:this._handlePress},c.createElement(E,{style:W.button},c.createElement(b,null,this.props.text)))}}]),h})(c.Component),P=(function(u){function h(){var n,l;t(this,h);for(var c=arguments.length,u=new Array(c),b=0;b<c;b++)u[b]=arguments[b];return(l=o(this,(n=s(h)).call.apply(n,[this].concat(u)))).state={scalingEnabled:!0},l}return l(h,u),n(h,[{key:"render",value:function(){var t=this;return c.createElement(E,null,c.createElement(y,{style:{backgroundColor:v,height:200},source:{uri:'https://facebook.github.io/react/'},scalesPageToFit:this.state.scalingEnabled}),c.createElement(E,{style:W.buttons},this.state.scalingEnabled?c.createElement(x,{text:"Scaling:ON",enabled:!0,onPress:function(){return t.setState({scalingEnabled:!1})}}):c.createElement(x,{text:"Scaling:OFF",enabled:!0,onPress:function(){return t.setState({scalingEnabled:!0})}})))}}]),h})(c.Component),F=(function(u){function h(){var n,l;t(this,h);for(var c=arguments.length,u=new Array(c),b=0;b<c;b++)u[b]=arguments[b];return(l=o(this,(n=s(h)).call.apply(n,[this].concat(u)))).webview=null,l.state={messagesReceivedFromWebView:0,message:''},l.onMessage=function(t){return l.setState({messagesReceivedFromWebView:l.state.messagesReceivedFromWebView+1,message:t.nativeEvent.data})},l.postMessage=function(){l.webview&&l.webview.postMessage('"Hello" from React Native!')},l}return l(h,u),n(h,[{key:"render",value:function(){var t=this,n=this.state,o=n.messagesReceivedFromWebView,s=n.message;return c.createElement(E,{style:[W.container,{height:200}]},c.createElement(E,{style:W.container},c.createElement(b,null,"Messages received from web view: ",o),c.createElement(b,null,s||'(No message)'),c.createElement(E,{style:W.buttons},c.createElement(x,{text:"Send Message to Web View",enabled:!0,onPress:this.postMessage}))),c.createElement(E,{style:W.container},c.createElement(y,{ref:function(n){t.webview=n},style:{backgroundColor:v,height:100},originWhitelist:k,source:r(d[7]),onMessage:this.onMessage})))}}]),h})(c.Component),R=(function(u){function h(){var n,l;t(this,h);for(var c=arguments.length,u=new Array(c),b=0;b<c;b++)u[b]=arguments[b];return(l=o(this,(n=s(h)).call.apply(n,[this].concat(u)))).webview=null,l.injectJS=function(){l.webview&&l.webview.injectJavaScript('document.write("Injected JS ")')},l}return l(h,u),n(h,[{key:"render",value:function(){var t=this;return c.createElement(E,null,c.createElement(y,{ref:function(n){t.webview=n},style:{backgroundColor:v,height:300},source:{uri:'https://www.facebook.com'},scalesPageToFit:!0}),c.createElement(E,{style:W.buttons},c.createElement(x,{text:"Inject JS",enabled:!0,onPress:this.injectJS})))}}]),h})(c.Component),W=h.create({container:{flex:1,backgroundColor:'#3b5998'},addressBarRow:{flexDirection:'row',padding:8},webView:{backgroundColor:v,height:350},addressBarTextInput:{backgroundColor:v,borderColor:'transparent',borderRadius:3,borderWidth:1,height:24,paddingLeft:10,paddingTop:3,paddingBottom:3,flex:1,fontSize:14},navButton:{width:20,padding:3,marginRight:3,alignItems:'center',justifyContent:'center',backgroundColor:v,borderColor:'transparent',borderRadius:3},disabledButton:{width:20,padding:3,marginRight:3,alignItems:'center',justifyContent:'center',backgroundColor:'rgba(255,255,255,0.25)',borderColor:'transparent',borderRadius:3},goButton:{height:24,padding:3,marginLeft:8,alignItems:'center',backgroundColor:v,borderColor:'transparent',borderRadius:3,alignSelf:'stretch'},statusBar:{flexDirection:'row',alignItems:'center',paddingLeft:5,height:22},statusBarText:{color:'white',fontSize:13},buttons:{flexDirection:'row',height:30,backgroundColor:'black',alignItems:'center',justifyContent:'space-between'},button:{flex:.5,width:0,margin:5,borderColor:'gray',borderWidth:1,backgroundColor:'gray'}});e.displayName=void 0,e.title='<WebView>',e.description='Base component to display web content',e.examples=[{title:'Simple Browser',render:function(){return c.createElement(T,null)}},{title:'Scale Page to Fit',render:function(){return c.createElement(P,null)}},{title:'Bundled HTML',render:function(){return c.createElement(y,{style:{backgroundColor:v,height:100},allowFileAccess:!0,originWhitelist:k,source:r(d[8]),scalesPageToFit:!0})}},{title:'Static HTML',render:function(){return c.createElement(y,{style:{backgroundColor:v,height:100},source:{html:"\n<!DOCTYPE html>\n\n<html>\n <head>\n <title>Hello Static World</title>\n <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n <meta name=\"viewport\" content=\"width=320, user-scalable=no\">\n <style type=\"text/css\">\n body {\n margin: 0;\n padding: 0;\n font: 62.5% arial, sans-serif;\n background: #ccc;\n }\n h1 {\n padding: 45px;\n margin: 0;\n text-align: center;\n color: #33f;\n }\n </style>\n </head>\n <body>\n <h1>Hello Static World</h1>\n </body>\n</html>\n"},scalesPageToFit:!0})}},{title:'POST Test',render:function(){return c.createElement(y,{style:{backgroundColor:v,height:100},source:{uri:'http://www.posttestserver.com/post.php',method:'POST',body:'foo=bar&bar=foo'},scalesPageToFit:!1})}},{title:'Messaging Test',render:function(){return c.createElement(F,null)}},{title:'Inject JavaScript',render:function(){return c.createElement(R,null)}}]},666745,[3,4,5,8,9,11,15,666746,666747]);