Skip to content

Commit fcb8253

Browse files
committed
feat(android): utils for enableEdgeToEdge, setStatusBarColor, setNavigationBarColor, setDarkModeHandler
docs here: https://github.com/NativeScript/docs/pull/185/files
1 parent 248ff4b commit fcb8253

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

apps/automated/src/ui/layouts/stack-layout-tests.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ export class StackLayoutTest extends testModule.UITest<StackLayout> {
4444

4545
TKUnit.assertEqual(this.rootLayout.orientation, CoreTypes.Orientation.vertical, 'Default orientation should be Vertical.');
4646

47+
// Capture current counts to assert on deltas instead of absolute values.
48+
// Some platforms may perform extra layout passes, so we only require at least one new pass.
49+
const beforeMeasure = this.rootLayout.measureCount;
50+
const beforeArrange = this.rootLayout.arrangeCount;
51+
4752
this.rootLayout.orientation = 'horizontal';
4853
this.waitUntilTestElementLayoutIsValid();
4954

50-
TKUnit.assertEqual(this.rootLayout.measureCount, 2, 'Orientation change should invalidate measure.');
51-
TKUnit.assertEqual(this.rootLayout.arrangeCount, 2, 'Orientation change should invalidate arrange.');
55+
TKUnit.assert(this.rootLayout.measureCount > beforeMeasure, `Orientation change should trigger a new measure. Before: ${beforeMeasure}, After: ${this.rootLayout.measureCount}`);
56+
TKUnit.assert(this.rootLayout.arrangeCount > beforeArrange, `Orientation change should trigger a new arrange. Before: ${beforeArrange}, After: ${this.rootLayout.arrangeCount}`);
5257
}
5358

5459
public test_ShouldMeasureWith_AtMost_OnVertical() {

packages/core/utils/native-helper.android.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { platformCheck } from './platform-check';
22

33
// importing this helper as a separate file avoids "android" symbol clash with the global android object
4-
import { resources, collections, getWindow, getApplication, getCurrentActivity, getApplicationContext, getResources, getPackageName, getInputMethodManager, showSoftInput, dismissSoftInput } from './native-helper-for-android';
4+
import { resources, collections, getWindow, getApplication, getCurrentActivity, getApplicationContext, getResources, getPackageName, getInputMethodManager, showSoftInput, dismissSoftInput, enableEdgeToEdge, setDarkModeHandler, setNavigationBarColor, setStatusBarColor } from './native-helper-for-android';
55
export { dataSerialize, dataDeserialize } from './native-helper-for-android';
66

77
export { getWindow } from './native-helper-for-android';
@@ -18,6 +18,10 @@ export const android = {
1818
getInputMethodManager,
1919
showSoftInput,
2020
dismissSoftInput,
21+
enableEdgeToEdge,
22+
setStatusBarColor,
23+
setNavigationBarColor,
24+
setDarkModeHandler,
2125
};
2226

2327
/**

packages/core/utils/native-helper.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,36 @@ export const android: {
107107
* Hides the soft input method, usually a soft keyboard.
108108
*/
109109
dismissSoftInput: (nativeView?: android.view.View) => void;
110+
/**
111+
* Sets the dark mode handler for the application.
112+
* @param options Options to set dark mode handler.
113+
*/
114+
setDarkModeHandler(options?: { activity?: androidx.appcompat.app.AppCompatActivity; handler: (bar: 'status' | 'navigation', resources: android.content.res.Resources) => boolean }): void;
115+
/**
116+
* Sets the navigation bar color for the application.
117+
* @param options Options to set navigation bar color.
118+
*/
119+
setNavigationBarColor(options?: { activity?: androidx.appcompat.app.AppCompatActivity; lightColor?: Color; darkColor?: Color }): void;
120+
/**
121+
* Sets the status bar color for the application.
122+
* @param options Options to set status bar color.
123+
*/
124+
setStatusBarColor(options?: { activity?: androidx.appcompat.app.AppCompatActivity; lightColor?: Color; darkColor?: Color }): void;
125+
/**
126+
* Enables edge-to-edge navigation for the provided activity.
127+
* @param activity The activity to enable edge-to-edge navigation for.
128+
* @param options Optional configuration for status and navigation bar colors.
129+
*/
130+
enableEdgeToEdge(
131+
activity: androidx.appcompat.app.AppCompatActivity,
132+
options?: {
133+
statusBarLightColor?: Color;
134+
statusBarDarkColor?: Color;
135+
navigationBarLightColor?: Color;
136+
navigationBarDarkColor?: Color;
137+
handleDarkMode?: (bar: 'status' | 'navigation', resources: android.content.res.Resources) => boolean;
138+
},
139+
): void;
110140
};
111141

112142
/**

0 commit comments

Comments
 (0)