I would like to achieve the same behavior of statusbar as in the capacitor example, i.e. automatically add the correct padding so my app content doesn't display inside the status bar.
However, I don't use the ionic framework but angular and the status bar overlays the webview of my application. Therefore, the content of my app is visible in the status bar.
I was expecting a method that allows to change this behavior (as the _ overlaysWebView_ method of ionic native status bar).
I also tried to add <preference name="StatusBarOverlaysWebView" value="false" /> in the config.xml file but I don't know if I should install the cordova statusbar plugin or not.
Maybe I shouldn't change this configuration and just play with padding, but then I don't know how to handle the different status bar height on different iOS devices.
I'm new to Capacitor and I never used Ionic nor Cordova. I someone could help me deal with this problem, I would be very grateful.
I have also had this issue on some applications I have worked on in the past ond only recently found a clean, less hacky way of fixing it. You will have to add the safe-area-inset-* where * can be left, right, top or bottom. This accounts for where the notch position will be when the device is either in portrait or landscape mode.
You can learn more about this by looking at this answer https://stackoverflow.com/a/47895315/4687451
You can set the padding of your directly in your css code thanks to the env variables. It works only on iOS so it can be applied on any tag you need.
body{
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
This could be achieved by adding following line in CAPViewBridgeController file
webView?.frame.origin = CGPoint(x: 0, y: UIApplication.shared.statusBarFrame.size.height)
webView?.frame.size.height = UIScreen.main.bounds.size.height - UIApplication.shared.statusBarFrame.size.height;
Search for below function and update. The function should look like this
extension CAPBridgeViewController: CAPBridgeDelegate {
internal var bridgedWebView: WKWebView? {
webView?.frame.origin = CGPoint(x: 0, y: UIApplication.shared.statusBarFrame.size.height)
webView?.frame.size.height = UIScreen.main.bounds.size.height - UIApplication.shared.statusBarFrame.size.height;
return webView
}
internal var bridgedViewController: UIViewController? {
return self
}
}
Related
Using capacitor to build an app in ios. In ios the webview covers the whole screen, for iphone-x that means the notch will be included and content will go behind it, like the picture on the right. But i want the picture on the left, black bars on 'no go areas'.
The expected solution (html/css) for this would be to set correct viewport and use the 'safe-area'insert-?', se: https://css-tricks.com/the-notch-and-css/
But for the webview in ios the 'safe-area'insert' will always be 0, that is how it works => this solution is useless.
How can i solve this? Can i change the webview to not cover the whole screen, without changing in the capacitor-framework?
You can use a compatible Cordova plugin cordova-plugin-safearea
npm i -D cordova-plugin-safearea
npx cap sync
With this installed, you can request the safe margin area over the cordova/capacitor bridge:
// Types for clarity
type SafeArea = {
top: string,
bottom: string,
}
window.plugins.safearea.get(
(result: SafeArea) => {
// elegantly set the result somewhere in app state
},
(error: any) => {
// maybe set some sensible fallbacks?
}
);
You could use these values to specify extra padding on the body, or on your header / bottom-menu components
The docs say it returns the values as Numbers, but it seems to me they are actually strings (consider parseFloat before doing math with them).
I have just implemented this in React (running the getter in React.useLayoutEffect); the project is wrapped in Capacitor and have tested on two iOS devices with different ingenious Apple notch screen formats (iPhone 8 and iPhone 11 Pro).
Refer to the documentation for more at https://github.com/rickgbw/cordova-plugin-safearea
There is a CSS variable preset by capacitor you can use to set the padding or a margin for example.
html {
--ion-safe-area-top: env(safe-area-inset-top);
--ion-safe-area-bottom: env(safe-area-inset-bottom);
--ion-safe-area-left: env(safe-area-inset-left);
--ion-safe-area-right: env(safe-area-inset-right);
}
Since iOS 11, when the UIWebView is full screen, a fake background appears on the status bar with the same color of the UIWebView background.
Anyone knows how to get rid of it?
Even adding the IUWebView to a storyboard and make it full screen will make the status bar background to appear
I've been trying to edit the size and some other properties of the UIWebView and none of them worked, but it's definitely something from the UIWebView.
Also tried to see all the subviews and it's sizes and didn't see anything strange.
Attached a screenshot, see the grey "statusbar", it disappears when scrolling, and doesn't appear if the UIWebView is not over that part of the screen.
I want it as on the second screenshot, only remove the fake background, not the status bar.
This happens because of UIScrollView new behavior to adjust the content inset to include safe area insets like the status bar.
To fix it, just set it to UIScrollViewContentInsetAdjustmentNever
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
Since iOS 11 Beta 4 you can add this to your viewport and will also remove the fake statusbar
viewport-fit=cover
To do this entirely in HTML/CSS, viewport-fit=cover in the Viewport meta tag is the correct way to handle this.
But you'll also want to adjust your padding dynamically to handle the differently sized status bar on iPhone X with its notched camera/speaker.
Luckily, Apple exposed some CSS constants for the safe area insets, so you can take advantage of those in your CSS:
i.e., padding-top: constant(safe-area-inset-top);
I wrote a bit more about this scenario and the new features for iOS 11 and iPhone X: https://ayogo.com/blog/ios11-viewport/
Swift version:
webView.scrollView.contentInsetAdjustmentBehavior = .never
I am using ionic for application.I have one ionic modal in my app.When i am setting height in px or percentage its coming correct for all android device but not for ios.If i use .platform-ios for height in CSS for ios devices its not coming same for all ios devices.
I have added vh for ios but still not same for all ios devices.What can i do can anyone suggest me.
css:-
.appModal
{
height:120px;
}
.platform-ios .appModal
{
height:40vh;
}
Thank you.
You may want to have a look at this link.
You can see that iOS 9.3 Safari and above support the Viewport Height and Width measurements vh and vw
Older iOS devices don't support these, see the known issues tab on that link for more information.
As a fallback you can use something like:
.class-name {
height: 300px;
height: 40vh;
}
Browsers that support vh will use specified 40vh but older browsers/devices will see theres an error and default back to the 300px height.
Please note: more widely supported css should appear first in your markup. Otherwise you won't be able to overwrite for the newer browser.
i have this issue too ;
the best solutions i found is to use javascript is supported every where ;)
code be something like this :
var heighDevice = window.screen.height;
var FirstELement = document.getElementById('MyAppModal');//MyAppModal id element
var heightElm = (heighDevice * 40) / 100; // 40 is height in vh
// add the height to the element
FirstELement.style["height"] = heightElm + "px";
I customized the navigation bar frame(y position) so it shows on the bottom in iOS 9.x with code like:
self.navigationController.navigationBar.frame = CGRectMake(0, 320-32, oldRect.size.width, oldRect.size.height);
but it stops working in iOS 10. got something like the screenshot.the top part is covered too. Any idea how to fix this?
We are trying to display an indicator that the web page is loading when launching an instance of InAppBrowser on iOS version of Cordova 3.4.
Android works fine with a spinner on the bottom, but iOS shows nothing but a white screen until the page suddenly pops up.
We were initially looking into using event listeners:
https://github.com/apache/cordova-plugin-inappbrowser/blob/dev/doc/index.md#addeventlistener
to listen to loadstart and loadstop and add js/css to show loading within the appbrowser window
https://github.com/apache/cordova-plugin-inappbrowser/blob/dev/doc/index.md#executescript
and
https://github.com/apache/cordova-plugin-inappbrowser/blob/dev/doc/index.md#insertcss
Still working on a viable solution.
The iOS InAppBrowser object has its own spinner which it adds to the webview automatically.
However, as the spinner is created as UIActivityIndicatorViewStyleWhite and the background of the webview is white you can't see it.
So I updated this like so:
self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
Also, the x co-ordinate of the spinner's frame are outside the bounds of an iPhones view. To fix this I updated the frame to:
self.spinner.frame = CGRectMake(self.view.frame.size.width / 2 - 10, self.view.frame.size.height/ 2 - 10, 20, 20);
This should centre the spinner no matter what size of device you are using.
I have only tested this in portrait mode.
You may want to fork Cordova (I'm testing this with 3.4) and submit a patch or see if there is a "proper" way to do this.
For anyone else using Phonegap Build, you can use my public plugin that implements these changes and makes the loading indicator (spinner) appear as it should in iOS.
Add this to your config.xml in your Phonegap Build project in place of the default InAppBrowser plugin to get the grey spinner described above by Goku:
<gap:plugin name="com.cordova.plugin.inappbrowser.with.loading.spinner" version="1.0.2" />