I your case you are right. The behaviour of the preview is not guarantee to match at 100% the behaviour of a real build. Here is some more info: https://nativescript.org/blog/nativescript-preview/
Also in your case the bar you see in the preview on android is the status of the status bar of the preview app and not your app.
This behaviour is may be dependant on:
- NativeScript flavour (vue, angular, core...)
- The layout orders (some layout behave differently)
- The version of nativescript
- The Phone Os version
- All the package used
There might be multiple way of addressing the status bar issue.
In my case I used backgroundSpanUnderStatusBar on the page tag to indicate that the status bar color should be the same as the background of the top component.
On IOS this is great. But on android the my app started "under" the status bar. This is the same describe behaviour of the question. This is because the status bar is os specific.
The solution/cheat I found (inspired from a plugin I do not remember). Calculate the height of the Os status bar and add a top padding to the root element. Here is the calculated height function:
import * as application from 'tns-core-modules/application';
import * as utils from 'tns-core-modules/utils/utils';
getStatusBarHeight() {
let result = 0;
if (application.android) {
const resourceId = (application.android.foregroundActivity || application.android.startActivity).getResources().getIdentifier('status_bar_height', 'dimen', 'android');
if (resourceId) {
result = (application.android.foregroundActivity || application.android.startActivity).getResources().getDimensionPixelSize(resourceId);
result = utils.layout.toDeviceIndependentPixels(result);
}
}
return result;
},
And in use with nativescript vue:
<DockLayout :paddingTop="getStatusBarHeight()"></DockLayout>
Note that I return 0 if on ios and on android I return the calculated value. This is a kind of cheat but works pretty well.
I am running tns-core 6.5.1. Newer version may fix some problem of the status bar on android.
tns preview
, the status bar is ok on my real device. Withtns run android
instead, the status bar overlaps the content. So it's a difference between the preview & run build? With tns – Shend