Skip to content

Commit

Permalink
Merge pull request #138 from kfa/fix_orientation
Browse files Browse the repository at this point in the history
Fixes iOS orientation bug when app is started in portrait.
  • Loading branch information
dankurka committed Aug 11, 2014
2 parents 5e02863 + 7336468 commit 968d401
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.StyleInjector;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;
import com.googlecode.mgwt.dom.client.event.orientation.OrientationChangeEvent;
import com.googlecode.mgwt.dom.client.event.orientation.OrientationChangeEvent.ORIENTATION;
import com.googlecode.mgwt.dom.client.event.orientation.OrientationChangeHandler;
import com.googlecode.mgwt.ui.client.MGWT;

/**
Expand All @@ -31,6 +35,8 @@
*/
public class IOS71BodyBug {

private static HandlerRegistration orientationChangeHandler;

interface Resources extends ClientBundle {

Resources INSTANCE = GWT.create(Resources.class);
Expand All @@ -40,6 +46,13 @@ interface Resources extends ClientBundle {
}

public static void applyWorkaround() {
// iOS bug fix needs only be applied in portrait orientation.
// Fix is deferred until the orientation change event is fired.
if (MGWT.getOrientation() == ORIENTATION.PORTRAIT) {
registerOrientationChangeEvent();
return;
}

if (MGWT.getOsDetection().isIPad() || MGWT.getOsDetection().isIPadRetina()) {
if (isIOS71() && windowInnerHeight() == 672) {
String text = Resources.INSTANCE.css().getText();
Expand All @@ -49,6 +62,17 @@ public static void applyWorkaround() {
}
}

private static void registerOrientationChangeEvent() {
orientationChangeHandler = MGWT.addOrientationChangeHandler(new OrientationChangeHandler() {

@Override
public void onOrientationChanged(OrientationChangeEvent event) {
orientationChangeHandler = null;
applyWorkaround();
}
});
}

private native static boolean isIOS71() /*-{
return !!$wnd.navigator.userAgent.match(/iPad;.*CPU.*OS 7_\d/i);
}-*/;
Expand Down

0 comments on commit 968d401

Please sign in to comment.