Browse Source

Fixed body padding not applying on some cases

Arnaud Vergnet 4 years ago
parent
commit
b336c95f20
2 changed files with 3 additions and 29 deletions
  1. 3
    28
      src/components/Screens/WebViewScreen.js
  2. 0
    1
      src/screens/Websites/PlanexScreen.js

+ 3
- 28
src/components/Screens/WebViewScreen.js View File

@@ -114,7 +114,6 @@ class WebViewScreen extends React.PureComponent<Props> {
114 114
     onOpenClicked = () => Linking.openURL(this.props.url);
115 115
 
116 116
     injectJavaScript = (script: string) => {
117
-        // console.log(this.webviewRef.current.getNode().webViewRef.current);
118 117
         this.webviewRef.current.getNode().injectJavaScript(script);
119 118
     }
120 119
 
@@ -125,46 +124,21 @@ class WebViewScreen extends React.PureComponent<Props> {
125 124
      */
126 125
     getRenderLoading = () => <BasicLoadingScreen isAbsolute={true}/>;
127 126
 
128
-// document.getElementsByTagName('body')[0].style.paddingTop = '100px';
129
-
130
-// $( 'body *' ).filter(function(){
131
-//   var position = $(this).css('position');
132
-//   var top = $(this).css('top');
133
-//   if((position === 'fixed') && top !== 'auto'){
134
-//     console.log(top);
135
-//     $(this).css('top', 'calc(' + top + ' + 100px)');
136
-//     console.log($(this).css('top'));
137
-//   };
138
-// });
139
-
140
-// document.querySelectorAll('body *').forEach(function(node){
141
-//   var style = window.getComputedStyle(node);
142
-//   var position = style.getPropertyValue('position');
143
-//   var top = style.getPropertyValue('top');
144
-//   if((position === 'fixed') && top !== 'auto'){
145
-//     console.log(top);
146
-//     node.style.top = 'calc(' + top + ' + 100px)';
147
-//     console.log(node.style.top);
148
-//   	console.log(node);
149
-//   };
150
-// });
151
-
152 127
     getJavascriptPadding(padding: number) {
153 128
         return (
154
-            "document.getElementsByTagName('body')[0].style.paddingTop = '" + padding + "px';\n" +
129
+            "document.getElementsByTagName('body')[0].style.paddingTop = '" + padding + "px';" +
155 130
             "true;"
156 131
         );
157 132
     }
158 133
 
159 134
     render() {
160 135
         const {containerPaddingTop, onScrollWithListener} = this.props.collapsibleStack;
161
-        const customJS = this.getJavascriptPadding(containerPaddingTop);
162 136
         return (
163 137
             <AnimatedWebView
164 138
                 ref={this.webviewRef}
165 139
                 source={{uri: this.props.url}}
166 140
                 startInLoadingState={true}
167
-                injectedJavaScript={this.props.customJS + customJS}
141
+                injectedJavaScript={this.props.customJS}
168 142
                 javaScriptEnabled={true}
169 143
                 renderLoading={this.getRenderLoading}
170 144
                 renderError={() => <ErrorView
@@ -175,6 +149,7 @@ class WebViewScreen extends React.PureComponent<Props> {
175 149
                     this.canGoBack = navState.canGoBack;
176 150
                 }}
177 151
                 onMessage={this.props.onMessage}
152
+                onLoad={() => this.injectJavaScript(this.getJavascriptPadding(containerPaddingTop))}
178 153
                 // Animations
179 154
                 onScroll={onScrollWithListener(this.props.onScroll)}
180 155
             />

+ 0
- 1
src/screens/Websites/PlanexScreen.js View File

@@ -204,7 +204,6 @@ class PlanexScreen extends React.Component<Props, State> {
204 204
             'removeAlpha();'
205 205
             + '});'
206 206
             + EXEC_COMMAND
207
-            + "function cc(msg) {alert(msg)};"
208 207
             + 'true;'; // Prevents crash on ios
209 208
     }
210 209
 

Loading…
Cancel
Save