fullscreen images on click ionic4 - html

I'm looking to make a live go fullscreen when I click on it, but I did not succeed to find any tutorial that matches my specific case...
I tried to use javascript but did not succeed :/
so my home.page.ts is empty,
but here is my HTML code:
<ion-content>
<ion-grid>
<ion-row>
<ion-col>
<button >
<ion-card color="dark" >
<ion-card-header>
<b>Parking</b>
</ion-card-header>
<ion-card-content>
<img id="img" width="250" height="160" src="http://131.173.8.23:80/mjpg/video.mjpg"/>
</ion-card-content>
</ion-card>
</button>
</ion-col>
<ion-col>
<button>
<ion-card color="dark">
<ion-card-header>
<b>Hall</b>
</ion-card-header>
<ion-card-content>
<img width="250" height="160" src="http://131.95.3.162:80/mjpg/video.mjpg"/>
</ion-card-content>
</ion-card>
</button>
</ion-col>
<ion-col>
<button>
<ion-card color="dark">
<ion-card-header>
<b>Accueil</b>
</ion-card-header>
<ion-card-content>
<img width="250" height="160" src="http://84.87.238.54:80/SnapshotJPEG?Resolution=640x480&Quality=Clarity&0"/>
</ion-card-content>
</ion-card>
</button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>

If you want to display an image full screen when clicked you can use the ionic plugin Photo Viewer. It also adds the ability to pan, zoom, and share the image.

Try this code. I hope it will helps you.
HTML:
<ion-content>
<div class="ion-padding">
<ion-row>
<ion-col>
<button>
<ion-card color="dark">
<ion-card-header>
<b>Parking</b>
</ion-card-header>
<ion-card-content>
<img id="img" width="250" height="160"
src="https://images.pexels.com/photos/326055/pexels-photo-326055.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
(click)="clickImage('https://images.pexels.com/photos/326055/pexels-photo-326055.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500')" />
</ion-card-content>
</ion-card>
</button>
</ion-col>
<ion-col>
<button>
<ion-card color="dark">
<ion-card-header>
<b>Accueil</b>
</ion-card-header>
<ion-card-content>
<img width="250" height="160"
src="https://images.unsplash.com/photo-1541233349642-6e425fe6190e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80://84.87.238.54:80/SnapshotJPEG?Resolution=640x480&Quality=Clarity&0"
(click)="clickImage('https://images.unsplash.com/photo-1541233349642-6e425fe6190e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80://84.87.238.54:80/SnapshotJPEG?Resolution=640x480&Quality=Clarity&0')" />
</ion-card-content>
</ion-card>
</button>
</ion-col>
</ion-row>
</div>
TS:
import { Component } from '#angular/core';
import { PhotoViewer } from '#ionic-native/photo-viewer/ngx';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private photoViewer: PhotoViewer) {}
clickImage(image){
console.log("image clicked",image);
this.photoViewer.show(image);
}
}

Related

Detect ionic/angular modal size (breakpoint) change?

I have an Ionic 6 / angular 13 project which I am working with some modals. My modals have multiple breakpoints and they contains a card with header and content and also two buttons. I want these buttons to be visible at any breakpoints but always be at the bottom of the page view.
modal config:
const modal = await this.modalController.create({
component: MyComponent,
backdropBreakpoint: 0.1,
initialBreakpoint: 0.5,
breakpoints: [smallestBreakPoint, 0.5, 0.9]
})
MyComponent template:
<ion-card style="background-color: white; height: 90%;">
<ion-card-header class="pb-0 pt-2">
<ion-card-title>
...
</ion-card-title>
</ion-card-header>
<ion-card-content>
<ion-item lines="none">
...
</ion-item>
<ion-item lines="none" (click)="..." button>
...
</ion-item>
<ion-row>
<ion-col class="text-center">
<ion-button expand="block" class="custom-button" color="light">
...
</ion-button>
</ion-col>
<ion-col class="text-center" size="8">
<ion-button expand="block" class="custom-button" (click)="...">
...
</ion-button>
</ion-col>
</ion-row>
</ion-card-content>
</ion-card>
I tried changing <ion-row> and <ion-card> position and offset to everything, and none of them did the trick. Also I tried <ion-footer>. Please note that the card div is larger than it should be because it should open fully on 0.9 breakpoint.
Expected output:
How can I do this?
Thanks in advance!

Ionic styling container

Can some help format my ionic code in order to look like picture 1?
picture 2 is how it currently looks
here is the code:
<ion-content >
<ion-grid>
<ion-row class="ion-text-center">
<ion-col size="0.9" *ngFor="let c of images; let i = index">
<img src="../assets/cards/cardBackground/cardBackground.png" *ngIf="!c.isFlipped" (click)="selectCard(c)"/>
<img [src]="imageDir + c.name + '.png'" *ngIf="c.isFlipped && !c.isMatched" (click)="selectCard(c)"/>
</ion-col>
</ion-row>
<ion-row class="ion-text-center" >
<ion-col >
<ion-card class="card-class">
<img src="../assets/playIcons/player1.svg"/>
<ion-card-header>
<ion-card-title>{{this.player1["name"]}}</ion-card-title>
<ion-card-title>Score: {{this.player1["score"]}}</ion-card-title>
</ion-card-header>
</ion-card>
</ion-col>
<ion-col >
<ion-card class="card-class">
<img src="../assets/playIcons/player2.svg"/>
<ion-card-header>
<ion-card-title>{{this.player2["name"]}}</ion-card-title>
<ion-card-title>Score: {{this.player2["score"]}}</ion-card-title>
</ion-card-header>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
Im not experienced in frontend as much and would really appreciate help thank you
The easiest solution would be to have a nested grid. eg
<ion-grid>
<ion-row class="ion-align-items-center ion-justify-content-center">
<ion-col size="3">
<ion-card class="card-class">
<img src="../assets/playIcons/player1.svg"/>
<ion-card-header>
<ion-card-title>{{this.player1["name"]}}</ion-card-title>
<ion-card-title>Score: {{this.player1["score"]}}</ion-card-title>
</ion-card-header>
</ion-card>
</ion-col>
<ion-col size="6">
<ion-grid>
<ion-row class="ion-text-center">
<ion-col size="0.9" *ngFor="let c of images; let i = index">
<img src="../assets/cards/cardBackground/cardBackground.png" *ngIf="!c.isFlipped" (click)="selectCard(c)"/>
<img [src]="imageDir + c.name + '.png'" *ngIf="c.isFlipped && !c.isMatched" (click)="selectCard(c)"/>
</ion-col>
</ion-row>
</ion-grid>
</ion-col>
<ion-col size="3">
<ion-card class="card-class">
<img src="../assets/playIcons/player2.svg"/>
<ion-card-header>
<ion-card-title>{{this.player2["name"]}}</ion-card-title>
<ion-card-title>Score: {{this.player2["score"]}}</ion-card-title>
</ion-card-header>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
You may want to look at breaking down the nested grid's cards into separate rows.

How to increase the vertical length of one element in a grid?

I have an ion-grid and I want the right element to increase its vertical length so it would consume the empty space and has the exact the same vertical length like the two left elements. The only thing I achieved was that the left element increased in horizontal length but this is not what I want to achieve here.
<ion-list>
<ion-card>
<ion-row>
<div class="card-title"> El 1</div>
</ion-row>
</ion-card>
<ion-grid>
<ion-row>
<ion-col>
<ion-card>
</ion-card>
</ion-col>
<ion-col>
<ion-card>
</ion-card>
</ion-col>
</ion-row>
<ion-row >
<ion-col>
<ion-card>
</ion-card>
</ion-col>
<ion-col>
</ion-col>
</ion-row>
</ion-grid>
<ion-list>
For more complex grid layouts than the ones provided by default in ion-grid, you can use CSS-grid-layout -- see docs: Basic Concepts of Grid Layout
For your specific example you would have to set the following:
HTML
<div class="wrapper">
<ion-card class="box1">
<div> box1</div>
</ion-card>
<ion-card class="box2">
<div > box2</div>
</ion-card>
<ion-card class="box3">
<div > box3</div>
</ion-card>
<ion-card class="box4">
<div > box4</div>
</ion-card>
<ion-card class="box5">
<div > box5</div>
</ion-card>
</div>
CSS:
.wrapper {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: 100px;
}
.box2 {
grid-column-start: 2;
grid-row-start: 1;
grid-row-end: 3;
}
Result:
Grid layout screenshot
And of course, now you can easily rearrange or modify all of them by referring to each box's class
And it is a very widely supported featured nowadays (>95%)! https://caniuse.com/#feat=css-grid
However, if you are forced to use ion-grid, one option would be to set two different columns and then occupy the left one with 2 rows, and the right one with 1 row and height set to 100%.
This results in a much more complex and less flexible code, hence I would recommend CSS-layout-grid instead.
To achieve the same result as the image above you would use:
<ion-grid>
<ion-row>
<ion-col>
<ion-row>
<ion-card>
<div> box1</div>
</ion-card>
</ion-row>
<ion-row>
<ion-card>
<div> box2</div>
</ion-card>
</ion-row>
</ion-col>
<ion-col>
<ion-row style="height: 100%;">
<ion-card>
<div> box3</div>
</ion-card>
</ion-row>
</ion-col>
</ion-row>
<ion-row >
<ion-col>
<ion-card>
<div> box4</div>
</ion-card>
</ion-col>
<ion-col>
<ion-card>
<div> box5</div>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>

How to center ionic avatar on a page

I am trying to center the avatar to the middle, with the code below but it doesn't work.
I have used this class="ion-align-items-center" that i got from the ionic documents but with no successs.
<ion-grid style ="text-align: center">
<ion-row class="ion-align-items-center" >
<ion-col class="ion-align-items-center" *ngFor="let item of students" >
<!-- <div class= "imageHold" >
<ion-img [src]= "profileImage || item.profileImage"></ion-img>
</div> -->
<ion-avatar class="ion-align-items-center">
<ion-img [src]= "profileImage || item.profileImage"></ion-img>
</ion-avatar>
</ion-col>
</ion-row >
<ion-row style ="text-align: center">
<ion-col>
<ion-button size="small" fill="outline" (click)="chooseProfilePic()" >Choose Profile Photo</ion-button>
</ion-col>
</ion-row>
</ion-grid>
I get this result
add a class in the avatar div.
.avatar{
margin: auto;
}

Angular/Ionic swap elements within *ngFor

I want to be able to create a list of items using *ngFor as follows..
Text - Image
Image-Text
Text - Image
Image-Text
<ion-grid>
<ion-row *ngFor="let item of items">
<ion-col col-6 ">
<ion-card ">
<ion-card-content>{{item.name}}
</ion-card-content>
</ion-card>
</ion-col>
<ion-col col-6 >
<ion-card>
<img [src]="item.img"/>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
However, I am unsure how I could achieve this in a for loop.
Any suggestions? Thanks
Apply flex-direction: row-reverse when the index of the item is odd or even, your choice.
<!--HTML-->
<!--Track the index of each item and apply reverse class if its even or odd (which ever you prefer, just change the comparator)-->
<ion-grid>
<ion-row *ngFor="let item of items; let i = index;" [class.reverse]="i%2 !== 0">
<ion-col col-6>
<ion-card>
<ion-card-content>{{item.name}}
</ion-card-content>
</ion-card>
</ion-col>
<ion-col col-6>
<ion-card>
<img [src]="item.img" />
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
<!--CSS-->
.reverse { flex-direction: row-reverse; }