Ionic 3 grid size won't adapt to smaller screen - ionic-framework

I have an Ionic 3 mobile app that I have developed, where I have form fields that I setup in a grid.
There are 3 columns that should appear side-by-side.
In most models it looks fine, but when I view it on an iPhone 5s or even on 6s, the fields do not appear side-by-side.
Instead, the input field drops a line and fills out 100% of the width, with the other columns at the top.
Here is my code:
<ion-grid fixed *ngIf="showPhone">
<ion-row class="edit-field">
<ion-col col-auto class="field-icon">
<ion-icon name="md-remove-circle"></ion-icon>
</ion-col>
<ion-col col-auto class="field-type">
<select name="phoneType" [(ngModel)]="phoneData.phone_type">
<option value="select"> -- Select -- </option>
<option value="home">home</option>
<option value="mobile">mobile</option>
<option value="business">business</option>
<option value="home fax">home fax</option>
<option value="work fax">work fax</option>
<option value="fax">fax</option>
</select>
</ion-col>
<ion-col class="field-input">
<input type="text"
[(ngModel)]="phoneData.phone_number"
(blur)="addPhone(phoneData)"
placeholder="Phone">
</ion-col>
</ion-row>
</ion-grid>
Howe can I make it so that it adapts when viewed on a smaller screen?

You can use media queries for fix it. Depending on the screen size you need to change the width.
ex:
#media screen and (max-width: 992px) {
body {
background-color: blue;
}
}
/* On screens that are 600px or less, set the background color to olive */
#media screen and (max-width: 600px) {
body {
background-color: olive;
}
//whatever in CSS.
}
If you Need to affect the CSS code only for IOS, You should check the platform in css.
Any queries please refer the link https://ionicframework.com/docs/theming/platform-specific-styles/

Related

ion-item reduce width of end slot

I need to make the end slot of my list item take up less width so I can make the name in the first slot longer.
Currently it takes up around 50% of the width and is wasting space.
<ion-list *ngIf="!isLoading">
<ion-item *ngFor="let trail of trails" #defectReport (click)="onViewTrailDetails(trail)">
<fa-icon class="icon icon-center status-open-icon" *ngIf="trail.status === trailStatus.Open" slot="start" [icon]="['fas', 'check-circle']" size="2x"></fa-icon>
<fa-icon class="icon icon-center status-closed-icon" *ngIf="trail.status === trailStatus.Closed" slot="start" [icon]="['fas', 'times-circle']" size="2x"></fa-icon>
<fa-icon class="icon icon-center status-new-icon" *ngIf="trail.status === trailStatus.New" slot="start" [icon]="['fas', 'burn']" size="2x"></fa-icon>
<fa-icon class="icon icon-center status-under-construction-icon" *ngIf="trail.status === trailStatus.UnderConstruction" slot="start" [icon]="['fas', 'exclamation-triangle']" size="2x"></fa-icon>
<ion-label class="first-item-label">
<span><h2 class="heading">{{trail.name}}</h2></span>
<p class="label-text">{{trail.status}}</p>
</ion-label>
<ion-label slot="end" class="second-item-label">
<p class="sub-heading">{{trail.statusNotes}}</p>
<p class="label-text-small">{{trail.lastUpdated | timeAgo}}</p>
</ion-label>
</ion-item>
</ion-list>
I ended up using ion-note. It caused some formatting issues but resolved my problem.
https://ionicframework.com/docs/api/note
<ion-note slot="end" class="second-item-label" [ngClass]="{'margin-top-auto': !trail.statusNotes}">
<p class="sub-heading">{{trail.statusNotes}}</p>
<p class="label-text-small">{{trail.lastUpdated | timeAgo}}</p>
</ion-note>
ion-item is a flex container and ion-label has the style flex-grow: 1.
What I did is setting the first to flex-grow: 2, resulting in 2/3, 1/3 responsive proportions for labels.
In your case just add this to the CSS:
.first-item-label {
flex-grow: 2;
}
If you want the last label to have a fixed width, do this instead:
.second-item-label {
flex: 0 0 80px;
}
I recommend to use the following. Just change / reset the flex style of the label element, since it's a flex layout.
ion-label[slot='end'] {
flex: unset;
text-align: end;
}
The property text-align: end is optional and has nothing to do with the question. But in my opinion the right slot of an item should be right aligned. Especially input field.
You could use every element you want. But ion-label has some predefined styles which harmonize with the framework. And ion-note changes e.g. the font-size (in md style).
Update: This will be fixed in upcoming Ionic version (maybe Ionic 6). With this change flex: 1 is not longer set on slot="end".

ionic 1 - add custom icon to nav button

i'd like to add an image as an icon to a navigation button in the header. is this possible? how should i go about it? here is my current code.. it doesnt work:
in the html code:
<ion-nav-bar class="bar-positive custom-dark">
<ion-nav-buttons side="left">
<button class="button" style="background: #1e1e1c;" ng-click="doSomething()">
<i class="icon home"></i>
</button>
in the css code:
.home
{
background: #1e1e1c;
background-repeat: no-repeat;
background-position: left top;
background-size: contain;
background-image: url('img/finalimages/home.png');
display: inline;
}
You could create a custom icon which can be put as your default back button alternative in ionic.
By doing this way you are getting a number of custom icons which can be used throughout your project.
This can be made by following this tutorial:here

Move parallax per slide progress instead of total progress

I'm writing an Ionic 2 app and want to use the Slider component (based on Swiper) to do something similar to this demo: http://idangero.us/swiper/demos/28-parallax.html
But whenever I add a parallax item it moves based on the total slider progress (like the background in the demo) and I found no way to have them move based on a single slide progress (like the text in the demo). (Swiper docs)
Does anyone know if that's possible? The Ionic docs don't have any details on parallax in slides.
What I tried:
<ion-slides parallax progress>
<ion-slide>
<h2>No Parallax</h2>
<p data-swiper-parallax="-100">Parallax: -100</p>
<p data-swiper-parallax="-200">Parallax: -200</p>
</ion-slide>
<ion-slide>
<h2>No Parallax</h2>
<p data-swiper-parallax="-100">Parallax: -100</p>
<p data-swiper-parallax="-200">Parallax: -200</p>
</ion-slide>
<ion-slide>
<h2>No Parallax</h2>
<p data-swiper-parallax="-100">Parallax: -100</p>
<p data-swiper-parallax="-200">Parallax: -200</p>
</ion-slide>
</ion-slides>
Demo: http://plnkr.co/edit/k0b92hqkdeUR57t71RR4?p=preview
You can achieve this by putting your background image to be parallaxed in the first slide, like this:
<ion-slides parallax pager>
<ion-slide>
<div class="image-parallax">
<img data-swiper-parallax="2100" src="url.to/image.png"/>
</div>
</ion-slide>
<ion-slide>
<p> Other slide content </p>
<ion-slide>
</ion-slides>
And then, style the div as this:
.image-parallax{
position: absolute;
img{
margin-left: 200px;
width: 2000px;
height: auto;
}
}
And then adjust the margins, width and height of the background.
Hope it helps!
I have managed to solve this with ionic 4, putting the background image in and making the background-attachment local.
my.page.html:
<ion-slides [options]="slideOpts" class="parallax-bg" data-swiper-parallax-x="-20%" [ngStyle]="{'background-image':'url(assets/images/background_'+category+'.svg)'}">
my.page.scss:
.parallax-bg {
background-position: center;
background-attachment: local;
background-repeat: repeat-x;
}

How to have a responsive ionic grid in ionic 2

I have a list of cards that I need to show them in 1 column in small devices and 2 columns in medium device and 3 columns in large devices
based on https://stackoverflow.com/a/36432126/2279488 and https://stackoverflow.com/a/36432126/2279488 I tried below codes but no success at the end.
1.
<ion-row responsive-sm>
<ion-col *ngFor="let card of cards" width-50>
<ion-card >
on small device it shows correctly, on large and medium it shows 2 cards only
2.
<ion-row responsive-sm>
<ion-col width-50>
<ion-card *ngFor="let card of cards">
on small device it shows correctly, on large and medium 1 column is shown and all cards are in the column
3.
<ion-row responsive-sm>
<ion-col>
<ion-card *ngFor="let card of cards">
on small device it shows correctly, on medium and large it shows only 1 column and cards are shown in that column
I found the solution, in case other people having same issue
I added wrap to my first code and it works.
<ion-row responsive-sm wrap>
<ion-col *ngFor="let card of cards" width-50>
<ion-card >
I added in my HTML below code and it working for me.
<ion-row class="categoryView">
<ion-col class="gridCol" width-40></ion-col>
<ion-col class="gridCol" width-40></ion-col>
</ion-row>
ion-col.gridCol.col {
height: 80px;
background: azure;
margin: 10px;
}
ion-row.categoryView.row {
height: 100px;
background: black;
}

webkit-transform issue on safari using select elements

I am developing a webapp for ipad and have come across an issue using select option elements when moving divs with webkit-transform. Forgive the table layout but I'm trying to replicate the issue in the app as closely as possible.
Click on the green box and the panels move to the left and the select box is fine. Reload the page and click on the red box and the panels move to the left (using webkit-transform) and when you click on the select box, the list is displayed outside of the browser and the container box jumps.
Note that this is not an issue on the latest GA chrome builds.
<html>
<head>
<title>Select Testing</title>
<style>
.button {
position: relative;
width: 44px;
height: 44px;
}
#moveGood {
background-color: lime;
}
#moveBad {
background-color: red;
}
div#panels {
position: relative;
height: 100%
}
div.panel {
position: relative;
top: 0px;
left: 0px;
width: 200px;
height: 50px;
border: 2px solid black;
}
.leftBad {
-webkit-transform: translate3d(-200px, 0, 0);
}
.leftGood {
left: -200px;
}
div#panelContainer {
position: absolute;
top: 100px;
left: 0;
overflow: hidden;
width: 210px;
}
</style>
<script type="text/javascript">
function leftBad() {
document.getElementById("panels").className += ' leftBad';
}
function leftGood() {
document.getElementById("panels").className += ' leftGood';
}
</script>
</head>
<body>
<div id="moveBad" class="button" onclick="leftBad();"></div>
<div id="moveGood" class="button" onclick="leftGood()";></div>
<div id="panelContainer">
<div id="panels">
<table>
<tr>
<td>
<div id="page1" class="panel">
</div>
</td>
<td>
<div id="page2" class="panel">
<select>
<option value="volvo">
Volvo
</option>
<option value="saab">
Saab
</option>
<option value="mercedes">
Mercedes
</option>
<option value="audi">
Audi
</option>
</select>
</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Safari tries to be helpful when there's a select box partially out of view, if you see:
http://jsfiddle.net/H5J27/
The first example doesn't have -webkit-transform, but when you click on it, it will be displaced in order to reveal it fully.
Now, Safari apparently isn't aware that, once transformed, the select box is in full view. The engine still thinks it's partially obstructed and it will move the select box and it's parent container to a point where it thinks you can see it.
The workarounds are not very encouraging. I'm guessing you're doing this coupled with animation in order to enjoy the benefits of hardware acceleration, so I'd add an event listener and the end of the animation, remove the css transform and apply normal positioning. This will get complicated if you have to do it on several elements, but it's good enough for a one time thing.