Prettier React Native Libraries

Reviewed By: sahrens

Differential Revision: D7961488

fbshipit-source-id: 05f9b8b0b91ae77f9040a5321ccc18f7c3c1ce9a
This commit is contained in:
Eli White
2018-05-10 19:06:46 -07:00
committed by Facebook Github Bot
parent 1e2de71290
commit d01ab66b47
301 changed files with 6259 additions and 3781 deletions

View File

@@ -4,8 +4,10 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @noflow
*/
'use strict';
const ActivityIndicator = require('ActivityIndicator');
@@ -55,7 +57,7 @@ type ErrorEvent = {
domain: any,
code: any,
description: any,
}
};
type Event = Object;
@@ -75,18 +77,10 @@ const defaultRenderLoading = () => (
);
const defaultRenderError = (errorDomain, errorCode, errorDesc) => (
<View style={styles.errorContainer}>
<Text style={styles.errorTextTitle}>
Error loading page
</Text>
<Text style={styles.errorText}>
{'Domain: ' + errorDomain}
</Text>
<Text style={styles.errorText}>
{'Error Code: ' + errorCode}
</Text>
<Text style={styles.errorText}>
{'Description: ' + errorDesc}
</Text>
<Text style={styles.errorTextTitle}>Error loading page</Text>
<Text style={styles.errorText}>{'Domain: ' + errorDomain}</Text>
<Text style={styles.errorText}>{'Error Code: ' + errorCode}</Text>
<Text style={styles.errorText}>{'Description: ' + errorDesc}</Text>
</View>
);
@@ -132,13 +126,10 @@ class WebView extends React.Component {
html: deprecatedPropType(
PropTypes.string,
'Use the `source` prop instead.'
'Use the `source` prop instead.',
),
url: deprecatedPropType(
PropTypes.string,
'Use the `source` prop instead.'
),
url: deprecatedPropType(PropTypes.string, 'Use the `source` prop instead.'),
/**
* Loads static html or a uri (with optional headers) in the WebView.
@@ -380,11 +371,7 @@ class WebView extends React.Component {
* - `'compatibility'` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
* @platform android
*/
mixedContentMode: PropTypes.oneOf([
'never',
'always',
'compatibility'
]),
mixedContentMode: PropTypes.oneOf(['never', 'always', 'compatibility']),
/**
* Override the native component used to render the WebView. Enables a custom native
@@ -432,24 +419,23 @@ class WebView extends React.Component {
otherView = (this.props.renderLoading || defaultRenderLoading)();
} else if (this.state.viewState === WebViewState.ERROR) {
const errorEvent = this.state.lastErrorEvent;
invariant(
errorEvent != null,
'lastErrorEvent expected to be non-null'
);
invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
otherView = (this.props.renderError || defaultRenderError)(
errorEvent.domain,
errorEvent.code,
errorEvent.description
errorEvent.description,
);
} else if (this.state.viewState !== WebViewState.IDLE) {
console.error(
'RCTWebView invalid state encountered: ' + this.state.loading
'RCTWebView invalid state encountered: ' + this.state.loading,
);
}
const webViewStyles = [styles.container, styles.webView, this.props.style];
if (this.state.viewState === WebViewState.LOADING ||
this.state.viewState === WebViewState.ERROR) {
if (
this.state.viewState === WebViewState.LOADING ||
this.state.viewState === WebViewState.ERROR
) {
// if we're in either LOADING or ERROR states, don't show the webView
webViewStyles.push(styles.hidden);
}
@@ -458,23 +444,34 @@ class WebView extends React.Component {
const viewManager = nativeConfig.viewManager || RCTWebViewManager;
const compiledWhitelist = (this.props.originWhitelist || []).map(WebViewShared.originWhitelistToRegex);
const onShouldStartLoadWithRequest = ((event: Event) => {
const compiledWhitelist = (this.props.originWhitelist || []).map(
WebViewShared.originWhitelistToRegex,
);
const onShouldStartLoadWithRequest = (event: Event) => {
let shouldStart = true;
const {url} = event.nativeEvent;
const origin = WebViewShared.extractOrigin(url);
const passesWhitelist = compiledWhitelist.some(x => new RegExp(x).test(origin));
const passesWhitelist = compiledWhitelist.some(x =>
new RegExp(x).test(origin),
);
shouldStart = shouldStart && passesWhitelist;
if (!passesWhitelist) {
Linking.openURL(url);
}
if (this.props.onShouldStartLoadWithRequest) {
shouldStart = shouldStart && this.props.onShouldStartLoadWithRequest(event.nativeEvent);
shouldStart =
shouldStart &&
this.props.onShouldStartLoadWithRequest(event.nativeEvent);
}
viewManager.startLoadWithResult(!!shouldStart, event.nativeEvent.lockIdentifier);
});
viewManager.startLoadWithResult(
!!shouldStart,
event.nativeEvent.lockIdentifier,
);
};
const decelerationRate = processDecelerationRate(this.props.decelerationRate);
const decelerationRate = processDecelerationRate(
this.props.decelerationRate,
);
const source = this.props.source || {};
if (this.props.html) {
@@ -485,9 +482,9 @@ class WebView extends React.Component {
const messagingEnabled = typeof this.props.onMessage === 'function';
const NativeWebView = nativeConfig.component || RCTWebView;
const NativeWebView = nativeConfig.component || RCTWebView;
const webView =
const webView = (
<NativeWebView
ref={RCT_WEBVIEW_REF}
key="webViewKey"
@@ -498,7 +495,9 @@ class WebView extends React.Component {
scrollEnabled={this.props.scrollEnabled}
decelerationRate={decelerationRate}
contentInset={this.props.contentInset}
automaticallyAdjustContentInsets={this.props.automaticallyAdjustContentInsets}
automaticallyAdjustContentInsets={
this.props.automaticallyAdjustContentInsets
}
onLoadingStart={this._onLoadingStart}
onLoadingFinish={this._onLoadingFinish}
onLoadingError={this._onLoadingError}
@@ -507,10 +506,13 @@ class WebView extends React.Component {
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
scalesPageToFit={this.props.scalesPageToFit}
allowsInlineMediaPlayback={this.props.allowsInlineMediaPlayback}
mediaPlaybackRequiresUserAction={this.props.mediaPlaybackRequiresUserAction}
mediaPlaybackRequiresUserAction={
this.props.mediaPlaybackRequiresUserAction
}
dataDetectorTypes={this.props.dataDetectorTypes}
{...nativeConfig.props}
/>;
/>
);
return (
<View style={styles.container}>
@@ -527,7 +529,7 @@ class WebView extends React.Component {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.goForward,
null
null,
);
};
@@ -538,7 +540,7 @@ class WebView extends React.Component {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.goBack,
null
null,
);
};
@@ -550,7 +552,7 @@ class WebView extends React.Component {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.reload,
null
null,
);
};
@@ -561,7 +563,7 @@ class WebView extends React.Component {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.stopLoading,
null
null,
);
};
@@ -575,25 +577,25 @@ class WebView extends React.Component {
* document.addEventListener('message', e => { document.title = e.data; });
* ```
*/
postMessage = (data) => {
postMessage = data => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.postMessage,
[String(data)]
[String(data)],
);
};
/**
* Injects a javascript string into the referenced WebView. Deliberately does not
* return a response because using eval() to return a response breaks this method
* on pages with a Content Security Policy that disallows eval(). If you need that
* functionality, look into postMessage/onMessage.
*/
injectJavaScript = (data) => {
* Injects a javascript string into the referenced WebView. Deliberately does not
* return a response because using eval() to return a response breaks this method
* on pages with a Content Security Policy that disallows eval(). If you need that
* functionality, look into postMessage/onMessage.
*/
injectJavaScript = data => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RCTWebView.Commands.injectJavaScript,
[data]
[data],
);
};
@@ -629,7 +631,7 @@ class WebView extends React.Component {
this.setState({
lastErrorEvent: event.nativeEvent,
viewState: WebViewState.ERROR
viewState: WebViewState.ERROR,
});
};
@@ -646,10 +648,14 @@ class WebView extends React.Component {
_onMessage = (event: Event) => {
const {onMessage} = this.props;
onMessage && onMessage(event);
}
};
}
const RCTWebView = requireNativeComponent('RCTWebView', WebView, WebView.extraNativeComponentConfig);
const RCTWebView = requireNativeComponent(
'RCTWebView',
WebView,
WebView.extraNativeComponentConfig,
);
const styles = StyleSheet.create({
container: {
@@ -684,7 +690,7 @@ const styles = StyleSheet.create({
},
webView: {
backgroundColor: '#ffffff',
}
},
});
module.exports = WebView;