How to disable toolbar-background for some ion-navbars? - ionic2

My app is in cordova, ionic 3.2. I want global style for ion-navbar component. So I declared style with .toolbar-background in variables.scss file. Now the style of ion-navbar in all pages are changed. its working fine. Now I want to disable the style for a specific ion-navbar only. Can anybody help me on how it possible please?
eg:
I have below code in variable.scss;
.toolbar-background{
background-color: red !important;
}
I have below code for header in app.html page(for left side menu header);
The background of this toolbar is red.
<ion-header>
<ion-toolbar>
<ion-title text-center>
Hellow!
</ion-title>
</ion-toolbar>
</ion-header>
Below is the code for footer in the app.html;
The background of this toolbar is red. I do not want red color only for this component. How to disable this style that showing due to toolbar-background?
<ion-footer>
<ion-navbar secondary >
this is the footer
</ion-navbar>
</ion-footer>

Related

Ionic2 custom components in Pages

I am using Ionic as a PWA. I use pages for navigation and I developed a component called common-header which displays the username and page name. It accepts an input called HeaderTitle and it displays the title. The component is declared in components.module.ts and I have imported the componentmodule in my PageModule. When I use the component in my page the component css styles does not work as expected.
If I remove the declaration of CommonHeader component in componentmodule and define in pagemodule the UI looks good.
This is the html code of CommonHeader.
<ion-navbar hideBackButton>
<ion-title>
{{UserName}}
</ion-title>
<ion-title>
{{HeaderTitle}}
</ion-title>
</ion-navbar>
Below is the Html code of my page
<ion-header>
<tr-header [HeaderTitle]="HeaderTitle"></tr-header>
</ion-header>
<ion-content padding>
Page Content
</ion-content>
The problem is CSS looks weird like the button does not have proper color/height. All this happens if I declare a component in componentmodule.ts and use the componentmodule file in my page module.
If I declare the component in my page module only it works great. But I need my custom component to be used in all the pages. What am I doing wrong?

Ionic 3 - Extract the side menu in it's own component

I need to build a scalable menu for an ionic 2/3 app (preferably using ion-menu). Following the guides on the docs the menu should be a sibling of the main content and they suggest to keep it inside app.html, which is a very high place inside the app that doesn't have to be crowded too much.
If we have a big menu or if we need to use several different menus, triggered by actions inside app, this place is not appropriate for this purpose.
I want to hide the complexity of the menu in it's own container/component and handle the logic outside app.component.ts.
app.html should stay slim and a construction like the one below may be useful.
<app-menu></app-menu> // this should be the enclosing container of the menu logic
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
If I do this, the following error comes up:
Menu: must have a [content] element to listen for drag events on. Example:
<ion-menu [content]="content"></ion-menu>
<ion-nav #content></ion-nav>
Any thoughts on how to implement this, avoiding to add code directly to app.html and app.component.ts?
Tks
error code just tells you to write <ion-nav #content></ion-nav> if you use <ion-menu [content]="content"></ion-menu>...
example toggle menu code below ...
<ion-header>
<ion-navbar color="danger">
<ion-buttons start>
<button ion-button icon-only menuToggle>
<ion-icon name="menu">
</ion-icon>
</button>
</ion-buttons>
</ion-navbar>
<ion-menu [content]="content">
<ion-content padding>
this is awkmal
</ion-content>
</ion-menu>
</ion-header>
<ion-nav #content></ion-nav>

How to programmatically hide header and tabs in landscape mode in Ionic 3?

I have one view in portrait mode and another in landscape mode where I want to show chart and I hide tabs and header (fullscreen mode, no scrolling). My view in landscape mode would look something like this:
<div showWhen="landscape" class="chart-settings split-container">
<ion-toolbar showWhen="landscape">
<ion-grid>
<ion-row>
<ion-col col-6>
<ion-item>
<ion-label>Period</ion-label>
<ion-select [(ngModel)]="period">
//options
</ion-select>
</ion-item>
</ion-col>
<ion-col col-6>
<ion-item>
<ion-label>Won/Lost</ion-label>
<ion-select [(ngModel)]="gender">
//options
</ion-select>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
</ion-toolbar>
<div class="flexChart">
<div id="chartdiv" [style.width.%]="100" [style.height.%]="100"></div>
</div>
I use flex to fill out the page and create "fullscreen effect with no scrolling".
Thanks
Well it seems there is this:
http://ionicframework.com/docs/api/platform/Platform/
It has:
isPortrait()
isLandscape()
so you can do:
platform.isPortrait() or platform.isLandscape()
if you inject platform into constructor.
Combine this with *NgIf:
https://angular.io/guide/template-syntax#ngif
CSS overflow, overflow-x, overflow-y is what you'd look to for prevent scrolling provided it's a block level container:
https://developer.mozilla.org/en/docs/Web/CSS/overflow
UPDATE
Based on this comment:
That was my initial thought. The problem with this is that it leaves
padding on top. I solved it by configuring styles, but it seemed
pretty dirty solution to me
You can fix that padding issue by getting the instance of the Content and call the resize() method like this:
import { Component, ViewChild } from '#angular/core';
import { Content } from 'ionic-angular';
#Component({...})
export class MyPage{
#ViewChild(Content) content: Content;
public yourMethod(): void {
this.content.resize();
}
}
https://ionicframework.com/docs/api/components/content/Content/#resize
Tell the content to recalculate its dimensions. This should be called
after dynamically adding/removing headers, footers, or tabs.
You can check landscape or portrait with platform, then you can get the ref of nav from template:
<ion-header>
<ion-navbar #navBar>
...
</ion-navbar>
</ion-header>
and call setHidden(true) in component with its ref:
#ViewChild('navBar') navBar: Navbar
// call in proper place
this.navBar.setHidden(true)
for tabs, I think you can do in the same way

Ionic2 navbar coloring globally

I just started to work with ionic v2 today and I am trying to color my app to match my preferences. While playing with the color variables gave some colors, I cannot find how to color every navbar to my preference although I can color them individually. What are the variables I should access in order to give all navbars the same color?
Thanks in advance.
This is done as globally only sigle class can change your toolbar color gobally.
.toolbar-background{
background-color: "color you want to give" !important;
}
or you can do seperately for each platform like
.toolbar-wp-themecolor .toolbar-background-wp{
}
.toolbar-md-themecolor .toolbar-background-md{
}
.toolbar-ios-themecolor .toolbar-background-ios{
}
or if you want to control with global color variable then for each page you can use like
<ion-header>
<ion-navbar color="themecolor">
<ion-title>Notifications</ion-title>
</ion-navbar>
</ion-header>
where themecolor can be defined in variable.scss
$colors: (
primary: #387ef5,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
white: #ffffff,
themecolor: #574D70
);

How to create custom full screen modal in Ionic2

I want to create custom Full screen Loader component in Ionic2. But my modal div do not cover the header/navbar area. I want it to be like Ionic LoadingComponent covering everything in my app and also have my template variable. Please have a look at image.
My modal css is
#modal{
width: 100%;
height:100%;
position: absolute;
z-index: 100;
background: red;
top: 0px;
left: 0;
}
Please help.
EDIT
My ModalPage has navbar
<ion-header>
<ion-navbar primary>
<button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Hello Ionic</ion-title>
</ion-navbar>
</ion-header>
EDIT
I found a workaround for this. I just use Ionic2 Popover, Popover gives 100% width+height, full screen. I called the modal popover on button click and dismiss it on 100% download.
You don't need that style rule to make the modal be fullscreen. Please take a look at this plunker.
Like you can se there, the HomePage contains a navbar, but the ModalPage html code is just
<ion-content></ion-content>
With that, and just changing the background-color
ion-page.modal-page ion-content {
background-color: red;
}
The modal should be fullscreen, without showing a navbar.