Parcourir la source

Merge pull request #52 from react-native-community/cleaning-unused-state-and-will-mount

(Contains #51) Cleaning unused state and will mount
Thibault Malbranche il y a 5 ans
Parent
révision
7b21e7317d
No account linked to committer's email address
2 fichiers modifiés avec 2 ajouts et 16 suppressions
  1. 1
    9
      js/WebView.android.js
  2. 1
    7
      js/WebView.ios.js

+ 1
- 9
js/WebView.android.js Voir le fichier

@@ -54,7 +54,6 @@ const defaultRenderLoading = () => (
54 54
 type State = {|
55 55
   viewState: WebViewState,
56 56
   lastErrorEvent: ?WebViewError,
57
-  startInLoadingState: boolean,
58 57
 |};
59 58
 
60 59
 /**
@@ -71,19 +70,12 @@ class WebView extends React.Component<WebViewSharedProps, State> {
71 70
   };
72 71
 
73 72
   state = {
74
-    viewState: WebViewState.IDLE,
73
+    viewState: this.props.startInLoadingState ? WebViewState.LOADING : WebViewState.IDLE,
75 74
     lastErrorEvent: null,
76
-    startInLoadingState: true,
77 75
   };
78 76
 
79 77
   webViewRef = React.createRef();
80 78
 
81
-  UNSAFE_componentWillMount() {
82
-    if (this.props.startInLoadingState) {
83
-      this.setState({ viewState: WebViewState.LOADING });
84
-    }
85
-  }
86
-
87 79
   render() {
88 80
     let otherView = null;
89 81
 

+ 1
- 7
js/WebView.ios.js Voir le fichier

@@ -76,7 +76,6 @@ const JSNavigationScheme = 'react-js-navigation';
76 76
 type State = {|
77 77
   viewState: WebViewState,
78 78
   lastErrorEvent: ?WebViewError,
79
-  startInLoadingState: boolean,
80 79
 |};
81 80
 
82 81
 const DataDetectorTypes = [
@@ -137,18 +136,13 @@ class WebView extends React.Component<WebViewSharedProps, State> {
137 136
   };
138 137
 
139 138
   state = {
140
-    viewState: WebViewState.IDLE,
139
+    viewState: this.props.startInLoadingState ? WebViewState.LOADING : WebViewState.IDLE,
141 140
     lastErrorEvent: null,
142
-    startInLoadingState: true,
143 141
   };
144 142
 
145 143
   webViewRef = React.createRef();
146 144
 
147 145
   UNSAFE_componentWillMount() {
148
-    if (this.props.startInLoadingState) {
149
-      this.setState({ viewState: WebViewState.LOADING });
150
-    }
151
-
152 146
     if (
153 147
       this.props.useWebKit === true &&
154 148
       this.props.scalesPageToFit !== undefined