2015-03-14 08:22:25 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-03-23 18:36:57 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule WebViewExample
|
2015-03-14 08:22:25 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2015-03-14 08:22:25 +00:00
|
|
|
var {
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TextInput,
|
2016-02-19 14:27:31 +00:00
|
|
|
TouchableWithoutFeedback,
|
2015-03-14 08:22:25 +00:00
|
|
|
TouchableOpacity,
|
|
|
|
View,
|
|
|
|
WebView
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-03-14 08:22:25 +00:00
|
|
|
|
|
|
|
var HEADER = '#3b5998';
|
|
|
|
var BGWASH = 'rgba(255,255,255,0.8)';
|
|
|
|
var DISABLED_WASH = 'rgba(255,255,255,0.25)';
|
|
|
|
|
|
|
|
var TEXT_INPUT_REF = 'urlInput';
|
|
|
|
var WEBVIEW_REF = 'webview';
|
|
|
|
var DEFAULT_URL = 'https://m.facebook.com';
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class WebViewExample extends React.Component {
|
|
|
|
state = {
|
|
|
|
url: DEFAULT_URL,
|
|
|
|
status: 'No Page Loaded',
|
|
|
|
backButtonEnabled: false,
|
|
|
|
forwardButtonEnabled: false,
|
|
|
|
loading: true,
|
|
|
|
scalesPageToFit: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
inputText = '';
|
|
|
|
|
|
|
|
handleTextInputChange = (event) => {
|
2016-02-02 02:00:18 +00:00
|
|
|
var url = event.nativeEvent.text;
|
Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.
This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).
I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.
Reviewed By: martinbigio
Differential Revision: D2895619
fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-04 01:30:01 +00:00
|
|
|
if (!/^[a-zA-Z-_]+:/.test(url)) {
|
2016-02-02 02:00:18 +00:00
|
|
|
url = 'http://' + url;
|
|
|
|
}
|
|
|
|
this.inputText = url;
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-03-14 08:22:25 +00:00
|
|
|
this.inputText = this.state.url;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={[styles.container]}>
|
|
|
|
<View style={[styles.addressBarRow]}>
|
2015-07-20 23:29:40 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={this.goBack}
|
|
|
|
style={this.state.backButtonEnabled ? styles.navButton : styles.disabledButton}>
|
|
|
|
<Text>
|
|
|
|
{'<'}
|
|
|
|
</Text>
|
2015-03-14 08:22:25 +00:00
|
|
|
</TouchableOpacity>
|
2015-07-20 23:29:40 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={this.goForward}
|
|
|
|
style={this.state.forwardButtonEnabled ? styles.navButton : styles.disabledButton}>
|
|
|
|
<Text>
|
|
|
|
{'>'}
|
|
|
|
</Text>
|
2015-03-14 08:22:25 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
<TextInput
|
|
|
|
ref={TEXT_INPUT_REF}
|
|
|
|
autoCapitalize="none"
|
2015-08-27 21:04:59 +00:00
|
|
|
defaultValue={this.state.url}
|
2015-03-14 08:22:25 +00:00
|
|
|
onSubmitEditing={this.onSubmitEditing}
|
|
|
|
onChange={this.handleTextInputChange}
|
|
|
|
clearButtonMode="while-editing"
|
|
|
|
style={styles.addressBarTextInput}
|
|
|
|
/>
|
|
|
|
<TouchableOpacity onPress={this.pressGoButton}>
|
|
|
|
<View style={styles.goButton}>
|
|
|
|
<Text>
|
|
|
|
Go!
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
<WebView
|
|
|
|
ref={WEBVIEW_REF}
|
|
|
|
automaticallyAdjustContentInsets={false}
|
|
|
|
style={styles.webView}
|
2016-02-02 02:00:18 +00:00
|
|
|
source={{uri: this.state.url}}
|
2016-01-05 18:31:42 +00:00
|
|
|
javaScriptEnabled={true}
|
|
|
|
domStorageEnabled={true}
|
2016-01-28 13:35:14 +00:00
|
|
|
decelerationRate="normal"
|
2015-03-14 08:22:25 +00:00
|
|
|
onNavigationStateChange={this.onNavigationStateChange}
|
2015-11-04 16:42:28 +00:00
|
|
|
onShouldStartLoadWithRequest={this.onShouldStartLoadWithRequest}
|
2015-03-14 08:22:25 +00:00
|
|
|
startInLoadingState={true}
|
2015-06-17 20:56:14 +00:00
|
|
|
scalesPageToFit={this.state.scalesPageToFit}
|
2015-03-14 08:22:25 +00:00
|
|
|
/>
|
|
|
|
<View style={styles.statusBar}>
|
|
|
|
<Text style={styles.statusBarText}>{this.state.status}</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
goBack = () => {
|
2015-03-14 08:22:25 +00:00
|
|
|
this.refs[WEBVIEW_REF].goBack();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
goForward = () => {
|
2015-03-14 08:22:25 +00:00
|
|
|
this.refs[WEBVIEW_REF].goForward();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
reload = () => {
|
2015-03-14 08:22:25 +00:00
|
|
|
this.refs[WEBVIEW_REF].reload();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
onShouldStartLoadWithRequest = (event) => {
|
2015-11-04 16:42:28 +00:00
|
|
|
// Implement any custom loading logic here, don't forget to return!
|
|
|
|
return true;
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-11-04 16:42:28 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
onNavigationStateChange = (navState) => {
|
2015-03-14 08:22:25 +00:00
|
|
|
this.setState({
|
|
|
|
backButtonEnabled: navState.canGoBack,
|
|
|
|
forwardButtonEnabled: navState.canGoForward,
|
|
|
|
url: navState.url,
|
|
|
|
status: navState.title,
|
|
|
|
loading: navState.loading,
|
2015-06-17 20:56:14 +00:00
|
|
|
scalesPageToFit: true
|
2015-03-14 08:22:25 +00:00
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
onSubmitEditing = (event) => {
|
2015-03-14 08:22:25 +00:00
|
|
|
this.pressGoButton();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
pressGoButton = () => {
|
2015-03-14 08:22:25 +00:00
|
|
|
var url = this.inputText.toLowerCase();
|
|
|
|
if (url === this.state.url) {
|
|
|
|
this.reload();
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
url: url,
|
|
|
|
});
|
|
|
|
}
|
2015-12-15 17:08:39 +00:00
|
|
|
// dismiss keyboard
|
2015-03-14 08:22:25 +00:00
|
|
|
this.refs[TEXT_INPUT_REF].blur();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-03-14 08:22:25 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class Button extends React.Component {
|
|
|
|
_handlePress = () => {
|
2016-02-26 16:19:40 +00:00
|
|
|
if (this.props.enabled !== false && this.props.onPress) {
|
2016-02-19 14:27:31 +00:00
|
|
|
this.props.onPress();
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2016-02-19 14:27:31 +00:00
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback onPress={this._handlePress}>
|
2016-07-19 06:18:03 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>{this.props.text}</Text>
|
2016-02-19 14:27:31 +00:00
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2016-02-19 14:27:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class ScaledWebView extends React.Component {
|
|
|
|
state = {
|
|
|
|
scalingEnabled: true,
|
|
|
|
};
|
2016-02-19 14:27:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2016-02-19 14:27:31 +00:00
|
|
|
return (
|
2016-02-26 16:19:40 +00:00
|
|
|
<View>
|
2016-02-19 14:27:31 +00:00
|
|
|
<WebView
|
|
|
|
style={{
|
|
|
|
backgroundColor: BGWASH,
|
2016-02-26 16:19:40 +00:00
|
|
|
height: 200,
|
2016-02-19 14:27:31 +00:00
|
|
|
}}
|
2016-02-26 16:19:40 +00:00
|
|
|
source={{uri: 'https://facebook.github.io/react/'}}
|
2016-02-19 14:27:31 +00:00
|
|
|
scalesPageToFit={this.state.scalingEnabled}
|
|
|
|
/>
|
|
|
|
<View style={styles.buttons}>
|
|
|
|
{ this.state.scalingEnabled ?
|
|
|
|
<Button
|
|
|
|
text="Scaling:ON"
|
|
|
|
enabled={true}
|
|
|
|
onPress={() => this.setState({scalingEnabled: false})}
|
|
|
|
/> :
|
|
|
|
<Button
|
|
|
|
text="Scaling:OFF"
|
|
|
|
enabled={true}
|
|
|
|
onPress={() => this.setState({scalingEnabled: true})}
|
|
|
|
/> }
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-19 14:27:31 +00:00
|
|
|
|
2016-10-16 13:29:14 +00:00
|
|
|
class MessagingTest extends React.Component {
|
|
|
|
webview = null
|
|
|
|
|
|
|
|
state = {
|
|
|
|
messagesReceivedFromWebView: 0,
|
|
|
|
message: '',
|
|
|
|
}
|
|
|
|
|
|
|
|
onMessage = e => this.setState({
|
|
|
|
messagesReceivedFromWebView: this.state.messagesReceivedFromWebView + 1,
|
|
|
|
message: e.nativeEvent.data,
|
|
|
|
})
|
|
|
|
|
|
|
|
postMessage = () => {
|
|
|
|
if (this.webview) {
|
|
|
|
this.webview.postMessage('"Hello" from React Native!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): ReactElement<any> {
|
|
|
|
const {messagesReceivedFromWebView, message} = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={[styles.container, { height: 200 }]}>
|
|
|
|
<View style={styles.container}>
|
|
|
|
<Text>Messages received from web view: {messagesReceivedFromWebView}</Text>
|
|
|
|
<Text>{message || '(No message)'}</Text>
|
|
|
|
<View style={styles.buttons}>
|
|
|
|
<Button text="Send Message to Web View" enabled onPress={this.postMessage} />
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View style={styles.container}>
|
|
|
|
<WebView
|
|
|
|
ref={webview => { this.webview = webview; }}
|
|
|
|
style={{
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
height: 100,
|
|
|
|
}}
|
|
|
|
source={require('./messagingtest.html')}
|
|
|
|
onMessage={this.onMessage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-07 04:13:20 +00:00
|
|
|
class InjectJS extends React.Component {
|
|
|
|
webview = null;
|
|
|
|
injectJS = () => {
|
|
|
|
const script = 'document.write("Injected JS ")'; // eslint-disable-line quotes
|
|
|
|
if (this.webview) {
|
|
|
|
this.webview.injectJavaScript(script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<WebView
|
|
|
|
ref={webview => { this.webview = webview; }}
|
|
|
|
style={{
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
height: 300,
|
|
|
|
}}
|
|
|
|
source={{uri: 'https://www.facebook.com'}}
|
|
|
|
scalesPageToFit={true}
|
|
|
|
/>
|
|
|
|
<View style={styles.buttons}>
|
|
|
|
<Button text="Inject JS" enabled onPress={this.injectJS} />
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-14 08:22:25 +00:00
|
|
|
var styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: HEADER,
|
|
|
|
},
|
|
|
|
addressBarRow: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
padding: 8,
|
|
|
|
},
|
|
|
|
webView: {
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
height: 350,
|
|
|
|
},
|
|
|
|
addressBarTextInput: {
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
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: BGWASH,
|
|
|
|
borderColor: 'transparent',
|
|
|
|
borderRadius: 3,
|
|
|
|
},
|
|
|
|
disabledButton: {
|
|
|
|
width: 20,
|
|
|
|
padding: 3,
|
|
|
|
marginRight: 3,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: DISABLED_WASH,
|
|
|
|
borderColor: 'transparent',
|
|
|
|
borderRadius: 3,
|
|
|
|
},
|
|
|
|
goButton: {
|
|
|
|
height: 24,
|
|
|
|
padding: 3,
|
|
|
|
marginLeft: 8,
|
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
borderColor: 'transparent',
|
|
|
|
borderRadius: 3,
|
|
|
|
alignSelf: 'stretch',
|
|
|
|
},
|
|
|
|
statusBar: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingLeft: 5,
|
|
|
|
height: 22,
|
|
|
|
},
|
|
|
|
statusBarText: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 13,
|
|
|
|
},
|
|
|
|
spinner: {
|
|
|
|
width: 20,
|
|
|
|
marginRight: 6,
|
|
|
|
},
|
2016-02-19 14:27:31 +00:00
|
|
|
buttons: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
height: 30,
|
|
|
|
backgroundColor: 'black',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flex: 0.5,
|
|
|
|
width: 0,
|
|
|
|
margin: 5,
|
|
|
|
borderColor: 'gray',
|
|
|
|
borderWidth: 1,
|
|
|
|
backgroundColor: 'gray',
|
|
|
|
},
|
2015-03-14 08:22:25 +00:00
|
|
|
});
|
|
|
|
|
Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.
This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).
I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.
Reviewed By: martinbigio
Differential Revision: D2895619
fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-04 01:30:01 +00:00
|
|
|
const HTML = `
|
|
|
|
<!DOCTYPE html>\n
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Hello Static World</title>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
2016-02-26 16:19:40 +00:00
|
|
|
<meta name="viewport" content="width=320, user-scalable=no">
|
Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.
This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).
I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.
Reviewed By: martinbigio
Differential Revision: D2895619
fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-04 01:30:01 +00:00
|
|
|
<style type="text/css">
|
|
|
|
body {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
font: 62.5% arial, sans-serif;
|
|
|
|
background: #ccc;
|
|
|
|
}
|
|
|
|
h1 {
|
|
|
|
padding: 45px;
|
|
|
|
margin: 0;
|
|
|
|
text-align: center;
|
|
|
|
color: #33f;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Hello Static World</h1>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
2015-06-22 16:43:30 +00:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-03-14 08:22:25 +00:00
|
|
|
exports.title = '<WebView>';
|
|
|
|
exports.description = 'Base component to display web content';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
2016-02-02 02:00:18 +00:00
|
|
|
title: 'Simple Browser',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> { return <WebViewExample />; }
|
2016-02-02 02:00:18 +00:00
|
|
|
},
|
2016-02-26 16:19:40 +00:00
|
|
|
{
|
|
|
|
title: 'Scale Page to Fit',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> { return <ScaledWebView/>; }
|
2016-02-26 16:19:40 +00:00
|
|
|
},
|
Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.
This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).
I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.
Reviewed By: martinbigio
Differential Revision: D2895619
fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-04 01:30:01 +00:00
|
|
|
{
|
|
|
|
title: 'Bundled HTML',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.
This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).
I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.
Reviewed By: martinbigio
Differential Revision: D2895619
fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-04 01:30:01 +00:00
|
|
|
return (
|
|
|
|
<WebView
|
|
|
|
style={{
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
height: 100,
|
|
|
|
}}
|
|
|
|
source={require('./helloworld.html')}
|
|
|
|
scalesPageToFit={true}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Static HTML',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
Support non-image assets in packager
Summary:
public
The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image.
This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc).
I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app.
Reviewed By: martinbigio
Differential Revision: D2895619
fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
2016-02-04 01:30:01 +00:00
|
|
|
return (
|
|
|
|
<WebView
|
|
|
|
style={{
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
height: 100,
|
|
|
|
}}
|
|
|
|
source={{html: HTML}}
|
|
|
|
scalesPageToFit={true}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2016-02-02 02:00:18 +00:00
|
|
|
{
|
|
|
|
title: 'POST Test',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
2016-02-02 02:00:18 +00:00
|
|
|
return (
|
|
|
|
<WebView
|
|
|
|
style={{
|
|
|
|
backgroundColor: BGWASH,
|
|
|
|
height: 100,
|
|
|
|
}}
|
|
|
|
source={{
|
|
|
|
uri: 'http://www.posttestserver.com/post.php',
|
|
|
|
method: 'POST',
|
|
|
|
body: 'foo=bar&bar=foo'
|
|
|
|
}}
|
|
|
|
scalesPageToFit={false}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2016-10-16 13:29:14 +00:00
|
|
|
},
|
|
|
|
{
|
2017-01-20 21:44:22 +00:00
|
|
|
title: 'Messaging Test',
|
2016-10-16 13:29:14 +00:00
|
|
|
render(): ReactElement<any> { return <MessagingTest />; }
|
2017-01-07 04:13:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Inject JavaScript',
|
|
|
|
render(): React.Element<any> { return <InjectJS />; }
|
|
|
|
},
|
2015-03-14 08:22:25 +00:00
|
|
|
];
|