-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(android): improve edge to edge handling #11058
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
base: main
Are you sure you want to change the base?
Conversation
|
View your CI Pipeline Execution ↗ for commit 9fe40a4
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves edge-to-edge window handling on Android by refactoring the insets management logic and adding support for enabling edge-to-edge for dialog windows. It also updates the Android SDK from API 35 to API 36 and updates several AndroidX dependencies.
Changes:
- Added new
enableEdgeToEdgeoverloads that accept aWindowparameter for enabling edge-to-edge on dialogs - Refactored window insets handling in
LayoutBaseto simplify overflow edge logic - Added
ignoreEdgeToEdgeOnOlderDevicesflag to optionally disable edge-to-edge on older Android versions - Updated Android SDK to API 36 and AndroidX dependencies to latest versions
Reviewed changes
Copilot reviewed 9 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/Utils.java | Added Window-based edge-to-edge overloads and version check flag |
| packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/LayoutBase.java | Refactored window insets handling logic for cleaner overflow edge management |
| packages/ui-mobile-base/android/widgets/build.gradle | Updated SDK to API 36 and AndroidX dependencies to latest versions |
| packages/ui-mobile-base/android/widgetdemo/src/main/java/org/nativescript/widgetsdemo/MainActivity.kt | Added dialog fragment test case demonstrating Window-based edge-to-edge |
| packages/ui-mobile-base/android/widgetdemo/build.gradle.kts | Updated SDK targets to API 36 |
| packages/types-android/src/lib/android/org.nativescript.widgets.d.ts | Added type declarations for new Java methods |
| packages/core/utils/native-helper.d.ts | Added TypeScript signatures for new edge-to-edge Window overload |
| packages/core/utils/native-helper.android.ts | Exported new getter/setter for ignoreEdgeToEdgeOnOlderDevices flag |
| packages/core/utils/native-helper-for-android.ts | Implemented Window overload support for enableEdgeToEdge |
| packages/core/ui/core/view/index.android.ts | Removed debug console.log and added edge-to-edge support for dialog windows |
| packages/core/core-types/index.ts | Updated AndroidOverflow type to include AndroidOverflowMultiple as standalone option |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public void setOverflowEdge(int value) { | ||
| overflowEdge = value; | ||
|
|
||
| if (value == OverflowEdgeIgnore) { | ||
| ViewCompat.setOnApplyWindowInsetsListener(this, null); | ||
| ViewCompat.requestApplyInsets(this); | ||
| } else if (windowInsetsListener == null) { | ||
| // if incoming inset is empty and previous inset is empty return consumed | ||
| // an incoming empty inset is one way to detect a consumed inset e.g multiple views consumed top/bottom | ||
| return; | ||
| } | ||
|
|
||
| if (windowInsetsListener == null) { | ||
| windowInsetsListener = new androidx.core.view.OnApplyWindowInsetsListener() { | ||
| @NonNull | ||
| @Override | ||
| public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) { | ||
| if (insets.isConsumed()) { | ||
| if (insets.isConsumed() || overflowEdge == OverflowEdgeIgnore) { | ||
| return insets; | ||
| } | ||
| if (v instanceof LayoutBase) { | ||
| LayoutBase base = (LayoutBase) v; | ||
|
|
||
| // should not occur but if it does return the inset | ||
| if (overflowEdge == OverflowEdgeIgnore) { | ||
| return insets; | ||
| } | ||
|
|
||
| Insets statusBar = insets.getInsets(WindowInsetsCompat.Type.statusBars()); | ||
| Insets navBar = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); | ||
| Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime()); | ||
|
|
||
| int insetLeft = navBar.left; | ||
| int insetRight = navBar.right; | ||
| int insetBottom = Math.max(navBar.bottom, ime.bottom); | ||
|
|
||
| insetBuffer.put(EMPTY_INSETS, 0, 32); | ||
| insetBuffer.rewind(); | ||
|
|
||
| if (overflowEdge == OverflowEdgeNone) { | ||
| base.applyingEdges = true; | ||
| v.setPadding(mPaddingLeft + insetLeft, mPaddingTop + statusBar.top, mPaddingRight + insetRight, mPaddingBottom + insetBottom); | ||
| edgeInsets = Insets.of(insetLeft, statusBar.top, insetRight, insetBottom); | ||
| base.applyingEdges = false; | ||
| return WindowInsetsCompat.CONSUMED; | ||
| } | ||
|
|
||
| if (base.insetListener != null) { | ||
| if (overflowEdge == OverflowEdgeDontApply) { | ||
| // if incoming inset is empty and previous inset is empty return consumed | ||
| // an incoming empty inset is one way to detect a consumed inset e.g multiple views consumed top/bottom | ||
| if (Insets.NONE.equals(statusBar) && Insets.NONE.equals(navBar) && Insets.NONE.equals(ime) && Insets.NONE.equals(edgeInsets)) { | ||
| return WindowInsetsCompat.CONSUMED; | ||
| } | ||
|
|
||
| IntBuffer insetData = insetBuffer.asIntBuffer(); | ||
|
|
||
| boolean leftPreviouslyConsumed = insetLeft == 0; | ||
| boolean topPreviouslyConsumed = statusBar.top == 0; | ||
| boolean rightPreviouslyConsumed = insetRight == 0; | ||
| boolean bottomPreviouslyConsumed = insetBottom == 0; | ||
|
|
||
|
|
||
| insetData.put(0, insetLeft).put(1, statusBar.top).put(2, insetRight).put(3, insetBottom).put(4, leftPreviouslyConsumed ? 1 : 0).put(5, topPreviouslyConsumed ? 1 : 0).put(6, rightPreviouslyConsumed ? 1 : 0).put(7, bottomPreviouslyConsumed ? 1 : 0); | ||
|
|
||
| base.insetListener.onApplyWindowInsets(insetBuffer); | ||
|
|
||
| int leftInset = insetData.get(0); | ||
| int topInset = insetData.get(1); | ||
| int rightInset = insetData.get(2); | ||
| int bottomInset = insetData.get(3); | ||
|
|
||
| boolean leftConsumed = insetData.get(4) > 0; | ||
| boolean topConsumed = insetData.get(5) > 0; | ||
| boolean rightConsumed = insetData.get(6) > 0; | ||
| boolean bottomConsumed = insetData.get(7) > 0; | ||
|
|
||
| if (leftConsumed && topConsumed && rightConsumed && bottomConsumed) { | ||
| edgeInsets = Insets.of(leftInset, topInset, rightInset, bottomInset); | ||
| base.setPadding(leftInset, topInset, rightInset, bottomInset); | ||
| return new WindowInsetsCompat.Builder().setInsets(WindowInsetsCompat.Type.systemBars(), Insets.NONE).build(); | ||
| } | ||
|
|
||
| base.setPadding(leftPreviouslyConsumed ? 0 : leftInset, topPreviouslyConsumed ? 0 : topInset, rightPreviouslyConsumed ? 0 : rightInset, bottomPreviouslyConsumed ? 0 : bottomInset); | ||
| if (!(v instanceof LayoutBase)) return insets; | ||
| LayoutBase base = (LayoutBase) v; | ||
|
|
||
| // restore inset edge if not consumed | ||
| Insets statusBar = insets.getInsets(WindowInsetsCompat.Type.statusBars()); | ||
| Insets navBar = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); | ||
| Insets ime = insets.getInsets(WindowInsetsCompat.Type.ime()); | ||
|
|
||
| if (!(leftPreviouslyConsumed || leftConsumed)) { | ||
| leftInset = insetLeft; | ||
| } | ||
| int insetLeft = navBar.left; | ||
| int insetRight = navBar.right; | ||
| int insetBottom = Math.max(navBar.bottom, ime.bottom); | ||
|
|
||
| if (!(topPreviouslyConsumed || topConsumed)) { | ||
| topInset = statusBar.top; | ||
| } | ||
| resetInset(); | ||
|
|
||
| if (!(rightPreviouslyConsumed || rightConsumed)) { | ||
| rightInset = insetRight; | ||
| } | ||
|
|
||
| if (!(bottomPreviouslyConsumed || bottomConsumed)) { | ||
| bottomInset = insetBottom; | ||
| } | ||
|
|
||
| edgeInsets = Insets.of(leftPreviouslyConsumed ? 0 : leftInset, topPreviouslyConsumed ? 0 : topInset, rightPreviouslyConsumed ? 0 : rightInset, bottomPreviouslyConsumed ? 0 : bottomInset); | ||
|
|
||
| return new WindowInsetsCompat.Builder().setInsets(WindowInsetsCompat.Type.systemBars(), Insets.of(leftPreviouslyConsumed || leftConsumed ? 0 : leftInset, topPreviouslyConsumed || topConsumed ? 0 : topInset, rightPreviouslyConsumed || rightConsumed ? 0 : rightInset, bottomPreviouslyConsumed || bottomConsumed ? 0 : bottomInset)).build(); | ||
| } | ||
| } | ||
|
|
||
| boolean overflowLeftConsume = (overflowEdge & OverflowEdgeLeft) == OverflowEdgeLeft; | ||
| boolean overflowTopConsume = (overflowEdge & OverflowEdgeTop) == OverflowEdgeTop; | ||
| boolean overflowRightConsume = (overflowEdge & OverflowEdgeRight) == OverflowEdgeRight; | ||
| boolean overflowBottomConsume = (overflowEdge & OverflowEdgeBottom) == OverflowEdgeBottom; | ||
|
|
||
| boolean overflowLeft = (overflowEdge & OverflowEdgeLeftDontConsume) == OverflowEdgeLeftDontConsume; | ||
| boolean overflowTop = (overflowEdge & OverflowEdgeTopDontConsume) == OverflowEdgeTopDontConsume; | ||
| boolean overflowRight = (overflowEdge & OverflowEdgeRightDontConsume) == OverflowEdgeRightDontConsume; | ||
| boolean overflowBottom = (overflowEdge & OverflowEdgeBottomDontConsume) == OverflowEdgeBottomDontConsume; | ||
| WindowInsetsCompat consumed = new WindowInsetsCompat.Builder() | ||
| .setInsets(WindowInsetsCompat.Type.systemBars(), Insets.NONE).build(); | ||
|
|
||
| if (overflowEdge == OverflowEdgeNone) { | ||
| base.applyingEdges = true; | ||
| v.setPadding(mPaddingLeft + insetLeft, mPaddingTop + statusBar.top, | ||
| mPaddingRight + insetRight, mPaddingBottom + insetBottom); | ||
| edgeInsets = Insets.of(insetLeft, statusBar.top, insetRight, insetBottom); | ||
| base.applyingEdges = false; | ||
| return consumed; | ||
| } |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OverflowEdgeDontApply handling has been completely removed from the window insets listener, but the constant and API support for 'dont-apply' still exist (see core-types/index.ts line 10 and ui/core/view/index.android.ts lines 1674, 1691-1692). This creates a situation where the API accepts 'dont-apply' as a valid value but the implementation no longer handles it, resulting in undefined behavior. Either the implementation should be restored or the API should be updated to remove support for 'dont-apply' and mark it as deprecated.
|
|
||
| public static void enableEdgeToEdge(Activity activity, Window window, @Nullable HandleDarkMode handleDarkMode) { | ||
| if (activity instanceof ComponentActivity) { | ||
| if (Utils.ignoreEdgeToEdgeOnOlderDevices && Build.VERSION.SDK_INT <= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constant Build.VERSION_CODES.UPSIDE_DOWN_CAKE does not exist in the Android SDK. Android API 34 is represented by Build.VERSION_CODES.UPSIDE_DOWN_CAKE but this constant is only available starting from API 35 (when building against compileSdk 35+). The actual value should be the integer constant 34, or you should use a constant that's available at compile time. Consider using Build.VERSION.SDK_INT < 35 or defining your own constant like private static final int API_34 = 34 to check against Android 14 (API 34).
| } | ||
|
|
||
| if (opts) { | ||
| if (typeof options.handleDarkMode === 'function') { |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable options is used instead of opts when checking for handleDarkMode. This should be opts.handleDarkMode to properly handle both the single-parameter and two-parameter overloads. When windowOrOptions is a Window instance, options contains the actual options, but when it's EdgeToEdgeOptions, opts contains the options.
| } | ||
|
|
||
| if (opts) { | ||
| if (typeof options.handleDarkMode === 'function') { |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line references options.handleDarkMode but should reference opts.handleDarkMode. When the function is called with only 2 parameters (activity and EdgeToEdgeOptions), the options parameter is undefined, causing a runtime error. The variable opts is correctly set to point to the right options object in both overload cases (lines 400-403).
Improvements to Android edge-to-edge support and overflow handling.
enableEdgeToEdgeAPI innative-helper-for-android.tsto accept either aWindowor options object, and added new utility functionsgetIgnoreEdgeToEdgeOnOlderDevicesandsetIgnoreEdgeToEdgeOnOlderDevicesfor more granular control. [1] [2] [3] [4]Overflow Handling Improvements:
AndroidOverflowtype to supportAndroidOverflowMultiplein addition to existing options, allowing for more flexible overflow edge configurations.LayoutBase.javato improve inset management and listener setup, including new buffer management methods and more robust handling of ignored edges. [1] [2]Android SDK and Dependency Updates:
androidx.fragment,androidx.activity, and addedandroidx.corefor improved compatibility and access to new features. [1] [2] [3] [4] [5]