Skip to content

Commit

Permalink
Fixed window rotation issue on iPad Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Oct 27, 2023
1 parent 9e2b8e1 commit c1c8e19
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dev.webfx.kit.mapper.peers.javafxgraphics.emul_coupling.base;

import com.sun.javafx.tk.TKStageListener;
import javafx.stage.Stage;
import dev.webfx.kit.mapper.peers.javafxgraphics.emul_coupling.StagePeer;
import dev.webfx.platform.uischeduler.UiScheduler;
import javafx.stage.Stage;

/**
* @author Bruno Salmon
Expand All @@ -25,7 +26,7 @@ public void setTKStageListener(TKStageListener listener) {

@Override
public void setBounds(float x, float y, boolean xSet, boolean ySet, float w, float h, float cw, float ch, float xGravity, float yGravity) {
//Logger.log("x = " + x + ", y = " + y + ", w = " + w + ", h = " + h + ", cw = " + cw + ", ch = " + ch);
//Console.log("x = " + x + ", y = " + y + ", w = " + w + ", h = " + h + ", cw = " + cw + ", ch = " + ch);
changedWindowSize();
}

Expand All @@ -34,6 +35,7 @@ public void changedWindowSize() {
double height = getPeerWindowHeight();
if (width == lastWidth && height == lastHeight)
return;
//Console.log("Window size changed. Width: " + lastWidth + " -> " + width + ". Height: " + lastHeight + " -> " + height);
getWindow().notifySizeChanged(width, height);
if (listener != null)
listener.changedSize((float) width, (float) height);
Expand All @@ -42,6 +44,10 @@ public void changedWindowSize() {
scenePeer.changedWindowSize(width, height);
lastWidth = width;
lastHeight = height;
// Workaround for a browser bug observed on Chrome on iPad where the window width/height properties were still
// not final after rotating the iPad despite the resize event being fired in JS. So we schedule a subsequent
// update to get the final values (this won't create an infinite loop, because these values will stabilize).
UiScheduler.scheduleInAnimationFrame(this::changedWindowSize, 5); // 5 animation frames seem enough
}

protected abstract double getPeerWindowWidth();
Expand Down

0 comments on commit c1c8e19

Please sign in to comment.