feat(loading): Changed loading/error rendering (#612)

This commit is contained in:
Penar Musaraj 2019-06-02 14:32:22 -04:00 committed by Thibault Malbranche
parent 3f3bcfc0ba
commit d429e82c3a
4 changed files with 8 additions and 31 deletions

View File

@ -244,13 +244,6 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
} }
const webViewStyles = [styles.container, styles.webView, style]; 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' in source) {
if (source.method === 'POST' && source.headers) { if (source.method === 'POST' && source.headers) {

View File

@ -346,13 +346,6 @@ class WebView extends React.Component<IOSWebViewProps, State> {
} }
const webViewStyles = [styles.container, styles.webView, style]; 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( const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
this.onShouldStartLoadWithRequestCallback, this.onShouldStartLoadWithRequestCallback,

View File

@ -2,11 +2,9 @@ import { StyleSheet, ViewStyle, TextStyle } from 'react-native';
interface Styles { interface Styles {
container: ViewStyle; container: ViewStyle;
errorContainer: ViewStyle;
errorText: TextStyle; errorText: TextStyle;
errorTextTitle: TextStyle; errorTextTitle: TextStyle;
hidden: ViewStyle; loadingOrErrorView: ViewStyle;
loadingView: ViewStyle;
webView: ViewStyle; webView: ViewStyle;
loadingProgressBar: ViewStyle; loadingProgressBar: ViewStyle;
} }
@ -16,21 +14,14 @@ const styles = StyleSheet.create<Styles>({
flex: 1, flex: 1,
overflow: 'hidden', overflow: 'hidden',
}, },
errorContainer: { loadingOrErrorView: {
position: 'absolute',
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
backgroundColor: 'white', height: '100%',
}, width: '100%',
hidden: { backgroundColor: 'white'
height: 0,
flex: 0, // disable 'flex:1' when hiding a View
},
loadingView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
}, },
loadingProgressBar: { loadingProgressBar: {
height: 20, height: 20,

View File

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