Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to change layout for phone and tablets using Ionic 2?

I see that there is a responsive grid system for Ionic 2, but that appears to just let you create a grid style layout.

I'm looking for something that will allow me to display the view one way on a tablet, and another on a phone. In this specific instance, I have a list of jobs. If it's a tablet, I want to also show a map to the right of the list and plot them out. How to make the map I understand, but how do I tell what they are using and show the correct UI?

like image 743
Jhorra Avatar asked Jul 12 '16 08:07

Jhorra


People also ask

Is Ionic for mobile only?

Desktop Browsers​ Because Ionic is based on web technologies, it works just as well on desktop browsers as it does on mobile devices. For more information on desktop layouts, see Cross Platform.

How do you make an Ionic app responsive?

If you want to make your views responsive when using the grid, you can define how much space it used on different screen sizes. Simply add a bit more of text inside and see how it changes when making the window bigger or smaller.

Can Ionic be used for Web development?

The Ionic Framework provides over 100 UI Components that web developers can use in their favorite frameworks (Angular, React, or Vue) to compose beautiful, performant UI experiences for iOS, Android, Web, and Desktop.

How can you use grid layout in Ionic with simple example?

Creating Simple Basic Grid in Ionic Let us create a simple basic grid inside the Ionic tab, go to tab1. page. html and replace the following code with ion-content. You can see in the example above we placed the Columns horizontally within the row, and it is quickly adjusting as per the available space inside the row.


1 Answers

You could decide how the layout is going to be shown by using the platform information:

Platform Name   Description
android on a device running Android.
cordova on a device running Cordova.
core    on a desktop device.
ios on a device running iOS.
ipad    on an iPad device.
iphone  on an iPhone device.
mobile  on a mobile device.
mobileweb   in a browser on a mobile device.
phablet on a phablet device.
tablet  on a tablet device.
windows on a device running Windows.

By using the underlying platform information you could show or hide things if its a tablet (or an ipad) by just simply doing:

this.isTabletOrIpad = this.platform.is('tablet') || this.platform.is('ipad');

And then by using *ngIf or whatever you need in your views, or using that isTabletOrIpad property to decide whether to initialize the map or not.

like image 105
sebaferreras Avatar answered Nov 16 '22 04:11

sebaferreras