Skip to content

Commit

Permalink
Fix for null pointer exception in safe area
Browse files Browse the repository at this point in the history
Fixed #3764
  • Loading branch information
shai-almog committed Nov 17, 2023
1 parent 3bd5ff3 commit 2bc1b2e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Ports/iOSPort/nativeSources/IOSNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -8286,37 +8286,41 @@ JAVA_BOOLEAN com_codename1_impl_ios_IOSNative_nativeIsAlphaMaskSupportedGlobal__
JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetLeft___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.left * scaleValue);
} else {
return 0;
if(window != nil && window.safeAreaInsets != nil) {
return (JAVA_INT)(window.safeAreaInsets.left * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetTop___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.top * scaleValue);
} else {
return 0;
if(window != nil && window.safeAreaInsets != nil) {
return (JAVA_INT)(window.safeAreaInsets.top * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetRight___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.right * scaleValue);
} else {
return 0;
if(window != nil && window.safeAreaInsets != nil) {
return (JAVA_INT)(window.safeAreaInsets.right * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplaySafeInsetBottom___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
if (@available(iOS 11.0, *)) {
UIWindow *window = UIApplication.sharedApplication.keyWindow;
return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue);
} else {
return 0;
if(window != nil && window.safeAreaInsets != nil) {
return (JAVA_INT)(window.safeAreaInsets.bottom * scaleValue);
}
}
return 0;
}

JAVA_INT com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject) {
Expand Down

0 comments on commit 2bc1b2e

Please sign in to comment.