Browse Source

Fixed crash on iOS and inject javascript instead of sending messages

Arnaud Vergnet 4 years ago
parent
commit
44f7a99bea

+ 2
- 0
src/components/Custom/AutoHideComponent.js View File

@@ -30,6 +30,8 @@ export default class AutoHideComponent extends React.Component<Props, State> {
30 30
     }
31 31
 
32 32
     onScroll({nativeEvent}: Object) {
33
+        if (nativeEvent.velocity === undefined)
34
+            return;
33 35
         if (nativeEvent.velocity.y > 0.2) { // Go down
34 36
             if (!this.isAnimationDownPlaying) {
35 37
                 this.isAnimationDownPlaying = true;

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

@@ -113,8 +113,9 @@ class WebViewScreen extends React.PureComponent<Props> {
113 113
 
114 114
     onOpenClicked = () => Linking.openURL(this.props.url);
115 115
 
116
-    postMessage = (message: string) => {
117
-        this.webviewRef.current.getNode().postMessage(message);
116
+    injectJavaScript = (script: string) => {
117
+        // console.log(this.webviewRef.current.getNode().webViewRef.current);
118
+        this.webviewRef.current.getNode().injectJavaScript(script);
118 119
     }
119 120
 
120 121
     /**

+ 15
- 8
src/screens/Websites/PlanexScreen.js View File

@@ -105,15 +105,15 @@ calendar.option({
105 105
   }
106 106
 });`;
107 107
 
108
-const LISTEN_TO_MESSAGES = `
109
-document.addEventListener("message", function(event) {
110
-    //alert(event.data);
108
+const EXEC_COMMAND = `
109
+function execCommand(event) {
110
+    alert(JSON.stringify(event));
111 111
     var data = JSON.parse(event.data);
112 112
     if (data.action === "setGroup")
113 113
         displayAde(data.data);
114 114
     else
115 115
         $('#calendar').fullCalendar(data.action, data.data);
116
-}, false);`
116
+};`
117 117
 
118 118
 const CUSTOM_CSS = "body>.container{padding-top:20px; padding-bottom: 50px}header,#entite,#groupe_visibility,#calendar .fc-left,#calendar .fc-right{display:none}.fc-toolbar .fc-center{width:100%}.fc-toolbar .fc-center>*{float:none;width:100%;margin:0}#entite{margin-bottom:5px!important}#entite,#groupe{width:calc(100% - 20px);margin:0 10px}#groupe_visibility{width:100%}#calendar .fc-agendaWeek-view .fc-content-skeleton .fc-title{font-size:.6rem}#calendar .fc-agendaWeek-view .fc-content-skeleton .fc-time{font-size:.5rem}#calendar .fc-month-view .fc-content-skeleton .fc-title{font-size:.6rem}#calendar .fc-month-view .fc-content-skeleton .fc-time{font-size:.7rem}.fc-axis{font-size:.8rem;width:15px!important}.fc-day-header{font-size:.8rem}.fc-unthemed td.fc-today{background:#be1522; opacity:0.4}";
119 119
 const CUSTOM_CSS_DARK = "body{background-color:#121212}.fc-unthemed .fc-content,.fc-unthemed .fc-divider,.fc-unthemed .fc-list-heading td,.fc-unthemed .fc-list-view,.fc-unthemed .fc-popover,.fc-unthemed .fc-row,.fc-unthemed tbody,.fc-unthemed td,.fc-unthemed th,.fc-unthemed thead{border-color:#222}.fc-toolbar .fc-center>*,h2,table{color:#fff}.fc-event-container{color:#121212}.fc-event-container .fc-bg{opacity:0.2;background-color:#000}.fc-unthemed td.fc-today{background:#be1522; opacity:0.4}";
@@ -195,15 +195,17 @@ class PlanexScreen extends React.Component<Props, State> {
195 195
             + FULL_CALENDAR_SETTINGS
196 196
             + "displayAde(" + groupID + ");" // Reset Ade
197 197
             + (DateManager.isWeekend(new Date()) ? "calendar.next()" : "")
198
-            + LISTEN_TO_MESSAGES
199 198
             + INJECT_STYLE;
200 199
 
201 200
         if (ThemeManager.getNightMode())
202 201
             this.customInjectedJS += "$('head').append('<style>" + CUSTOM_CSS_DARK + "</style>');";
203 202
 
204 203
         this.customInjectedJS +=
205
-            'removeAlpha();' +
206
-            '});true;'; // Prevents crash on ios
204
+            'removeAlpha();'
205
+            + '});'
206
+            + EXEC_COMMAND
207
+            + "function cc(msg) {alert(msg)};"
208
+            + 'true;'; // Prevents crash on ios
207 209
     }
208 210
 
209 211
     // componentWillUpdate(prevProps: Props) {
@@ -234,7 +236,12 @@ class PlanexScreen extends React.Component<Props, State> {
234 236
     };
235 237
 
236 238
     sendMessage = (action: string, data: any) => {
237
-        this.webScreenRef.current.postMessage(JSON.stringify({action: action, data: data}));
239
+        let command;
240
+        if (action === "setGroup")
241
+            command = "displayAde(" + data + ")";
242
+        else
243
+            command = "$('#calendar').fullCalendar('" + action + "', '" + data + "')";
244
+        this.webScreenRef.current.injectJavaScript(command + ';true;');
238 245
     }
239 246
 
240 247
     onMessage = (event: Object) => {

Loading…
Cancel
Save