Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Home Indicator Height on iOS #336

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019 Gluon
* Copyright (c) 2016, 2022 Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -138,6 +138,12 @@ static Optional<DisplayService> create() {
*/
float getScreenScale();

/**
* Returns the height of Home Indicator
* @return the height of Home Indicator
*/
int getHomeIndicatorHeight();

/**
* Returns true if the device has a round screen
* @return true if the device has a round screen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020 Gluon
* Copyright (c) 2016, 2022 Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -103,6 +103,12 @@ public float getScreenScale() {
return scale;
}

@Override
public int getHomeIndicatorHeight() {
// Not Implemented Yet
return 0;
}

@Override
public boolean isScreenRound() {
return screenRound();
Expand All @@ -122,4 +128,4 @@ public ReadOnlyObjectProperty<Notch> notchProperty() {
private native static boolean isPhoneFactor();
private native static double[] screenSize();
private native static boolean screenRound();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019 Gluon
* Copyright (c) 2016, 2022 Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -86,6 +86,11 @@ public float getScreenScale() {
return (float) Math.min(Screen.getPrimary().getOutputScaleX(), Screen.getPrimary().getOutputScaleY());
}

@Override
public int getHomeIndicatorHeight() {
return 0;
}

@Override
public boolean isScreenRound() {
return false;
Expand All @@ -107,4 +112,4 @@ private static void log(String message, Throwable cause) {
cause.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019 Gluon
* Copyright (c) 2016, 2022 Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,7 +38,7 @@
public class IOSDisplayService implements DisplayService {

static {
System.loadLibrary("Display");
Platform.runLater(()->System.loadLibrary("Display"));
initDisplay();
}

Expand Down Expand Up @@ -80,6 +80,11 @@ public Dimension2D getDefaultDimensions() {
return new Dimension2D(dim[0], dim[1]);
}

@Override
public int getHomeIndicatorHeight() {
return getSafeAreaInsets()[1];
}

@Override
public float getScreenScale() {
return screenScale();
Expand All @@ -100,6 +105,11 @@ public ReadOnlyObjectProperty<Notch> notchProperty() {
return notch.getReadOnlyProperty();
}

private int [] getSafeAreaInsets() {
return safeAreaInsets();
}


// native
private static native void initDisplay();

Expand All @@ -108,6 +118,7 @@ public ReadOnlyObjectProperty<Notch> notchProperty() {
private native static double[] screenBounds();
private native static float screenScale();
private native static boolean isNotchFound();
private native static int[] safeAreaInsets();

private static native void startObserver();
private static native void stopObserver();
Expand All @@ -119,4 +130,4 @@ private static void notifyDisplay(String o) {
Platform.runLater(() -> notch.setValue(d));
}
}
}
}
31 changes: 30 additions & 1 deletion modules/display/src/main/native/ios/Display.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,33 @@ -(void)OrientationDidChange:(NSNotification*)notification
sendNotch();
}

@end
JNIEXPORT jintArray JNICALL Java_com_gluonhq_attach_display_impl_IOSDisplayService_safeAreaInsets
(JNIEnv *env, jclass jClass)
{
jintArray output = (*env)->NewIntArray(env, 2);
if (output == NULL) {
return NULL;
}

if (@available(iOS 11.0, *)) {
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if(!window)
{
AttachLog(@"key window was nil");
return NULL;
}
CGFloat topPadding = window.safeAreaInsets.top;
CGFloat bottomPadding = window.safeAreaInsets.bottom;

jint res[] = {topPadding, bottomPadding};
(*env)->SetIntArrayRegion(env, output, 0, 2, res);
return output;

}
jint res[]={0,0};
(*env)->SetIntArrayRegion(env, output, 0, 2, res);
return output;
}


@end