Skip to content

Commit

Permalink
feat(loading): Changed loading/error rendering (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmusaraj authored and Titozzz committed Jun 2, 2019
1 parent 3f3bcfc commit d429e82
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
7 changes: 0 additions & 7 deletions src/WebView.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,6 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
}

const webViewStyles = [styles.container, styles.webView, style];
if (
this.state.viewState === 'LOADING'
|| this.state.viewState === 'ERROR'
) {
// if we're in either LOADING or ERROR states, don't show the webView
webViewStyles.push(styles.hidden);
}

if (source && 'method' in source) {
if (source.method === 'POST' && source.headers) {
Expand Down
7 changes: 0 additions & 7 deletions src/WebView.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,6 @@ class WebView extends React.Component<IOSWebViewProps, State> {
}

const webViewStyles = [styles.container, styles.webView, style];
if (
this.state.viewState === 'LOADING'
|| this.state.viewState === 'ERROR'
) {
// if we're in either LOADING or ERROR states, don't show the webView
webViewStyles.push(styles.hidden);
}

const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
this.onShouldStartLoadWithRequestCallback,
Expand Down
21 changes: 6 additions & 15 deletions src/WebView.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { StyleSheet, ViewStyle, TextStyle } from 'react-native';

interface Styles {
container: ViewStyle;
errorContainer: ViewStyle;
errorText: TextStyle;
errorTextTitle: TextStyle;
hidden: ViewStyle;
loadingView: ViewStyle;
loadingOrErrorView: ViewStyle;
webView: ViewStyle;
loadingProgressBar: ViewStyle;
}
Expand All @@ -16,21 +14,14 @@ const styles = StyleSheet.create<Styles>({
flex: 1,
overflow: 'hidden',
},
errorContainer: {
loadingOrErrorView: {
position: 'absolute',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
hidden: {
height: 0,
flex: 0, // disable 'flex:1' when hiding a View
},
loadingView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
height: '100%',
width: '100%',
backgroundColor: 'white'
},
loadingProgressBar: {
height: 20,
Expand Down
4 changes: 2 additions & 2 deletions src/WebViewShared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const getViewManagerConfig = (
};

const defaultRenderLoading = () => (
<View style={styles.loadingView}>
<View style={styles.loadingOrErrorView}>
<ActivityIndicator />
</View>
);
Expand All @@ -84,7 +84,7 @@ const defaultRenderError = (
errorCode: number,
errorDesc: string,
) => (
<View style={styles.errorContainer}>
<View style={styles.loadingOrErrorView}>
<Text style={styles.errorTextTitle}>Error loading page</Text>
<Text style={styles.errorText}>{`Domain: ${errorDomain}`}</Text>
<Text style={styles.errorText}>{`Error Code: ${errorCode}`}</Text>
Expand Down

0 comments on commit d429e82

Please sign in to comment.