6 min read

In this article by Zainul Setyo Pamungkas, author of the book PhoneGap 4 Mobile Application Development Cookbook, we will see how Ionic framework is one of the most popular HTML5 framework for hybrid application development. Ionic framework provides native such as the UI component that user can use and customize.

(For more resources related to this topic, see here.)

In this article, we will create a clone of Instagram mobile app layout:

  1. First, we need to create new Ionic tabs application project named ionSnap:
    ionic start ionSnap tabs
  2. Change directory to ionSnap:
    cd ionSnap
  3. Then add device platforms to the project:
    ionic platform add ios
    
    ionic platform add android
  4. Let’s change the tab name. Open www/templates/tabs.html and edit each title attribute of ion-tab:
    <ion-tabs class="tabs-icon-top tabs-color-active-positive">
    
        <ion-tab title="Timeline" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/dash">
    
            <ion-nav-view name="tab-dash"></ion-nav-view>
    
        </ion-tab>
    
        <ion-tab title="Explore" icon-off="ion-ios-search" icon-on="ion-ios-search" href="#/tab/chats">
    
            <ion-nav-view name="tab-chats"></ion-nav-view>
    
        </ion-tab>
    
        <ion-tab title="Profile" icon-off="ion-ios-person-outline" icon-on="ion-person" href="#/tab/account">
    
            <ion-nav-view name="tab-account"></ion-nav-view>
    
        </ion-tab>
    
    </ion-tabs>
  5. We have to clean our application to start a new tab based application. Open www/templates/tab-dash.html and clean the content so we have following code:
    <ion-view view-title="Timeline">
    
        <ion-content class="padding">
    
        </ion-content>
    
    </ion-view>
  6. Open www/templates/tab-chats.html and clean it up:
    <ion-view view-title="Explore">
    
        <ion-content>
    
        </ion-content>
    
    </ion-view>
  7. Open www/templates/tab-account.html and clean it up:
    <ion-view view-title="Profile">
    
        <ion-content>
    
        </ion-content>
    
    </ion-view>
  8. Open www/js/controllers.js and delete methods inside controllers so we have following code:
    angular.module('starter.controllers', [])
    
     
    
    .controller('DashCtrl', function($scope) {})
    
     
    
    .controller('ChatsCtrl', function($scope, Chats) {
    
     
    
    })
    
     
    
    .controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
    
       
    
    })
    
     
    
    .controller('AccountCtrl', function($scope) {
    
     
    
    });
  9. We have clean up our tabs application. If we run our application, we will have view like this:PhoneGap 4 Mobile Application Development Cookbook
  10. The next steps, we will create layout for timeline view. Each post of timeline will be displaying username, image, Like button, and Comment button. Open www/template/tab-dash.html and add following div list:
    <ion-view view-title="Timelines">
    
        <ion-content class="has-header">
    
     
    
            <div class="list card">
    
                <div class="item item-avatar">
    
                    <img src="http://placehold.it/50x50">
    
                    <h2>Some title</h2>
    
                    <p>November 05, 1955</p>
    
                </div>
    
                <div class="item item-body">
    
                    <img class="full-image" src="http://placehold.it/500x500">
    
                    <p>
    
                        <a href="#" class="subdued">1 Like</a>
    
                        <a href="#" class="subdued">5 Comments</a>
    
                    </p>
    
                </div>
    
                <div class="item tabs tabs-secondary tabs-icon-left">
    
                    <a class="tab-item" href="#">
    
                        <i class="icon ion-heart"></i> Like
    
                    </a>
    
                    <a class="tab-item" href="#">
    
                        <i class="icon ion-chatbox"></i> Comment
    
                    </a>
    
                    <a class="tab-item" href="#">
    
                        <i class="icon ion-share"></i> Share
    
                    </a>
    
                </div>
    
            </div>
    
     
    
        </ion-content>
    
    </ion-view>

    Our timeline view will be like this:

    PhoneGap 4 Mobile Application Development Cookbook

  11. Then, we will create explore page to display photos in a grid view. First we need to add some styles on our www/css/styles.css:
    .profile ul {
    
        list-style-type: none;
    
    }
    
     
    
    .imageholder {
    
        width: 100%;
    
        height: auto;
    
        display: block;
    
        margin-left: auto;
    
        margin-right: auto;
    
    }
    
     
    
    .profile li img {
    
        float: left;
    
        border: 5px solid #fff;
    
        width: 30%;
    
        height: 10%;
    
        -webkit-transition: box-shadow 0.5s ease;
    
        -moz-transition: box-shadow 0.5s ease;
    
        -o-transition: box-shadow 0.5s ease;
    
        -ms-transition: box-shadow 0.5s ease;
    
        transition: box-shadow 0.5s ease;
    
    }
    
     
    
    .profile li img:hover {
    
        -webkit-box-shadow: 0px 0px 7px rgba(255, 255, 255,
        0.9);
    
        box-shadow: 0px 0px 7px rgba(255, 255, 255, 0.9);
    
    }
  12. Then we just put list with image item like so:
    <ion-view view-title="Explore">
    
        <ion-content>
    
     
    
           <ul class="profile" style="margin-left:5%;">
    
        <li class="profile">
    
          <a href="#"><img src="http://placehold.it/50x50"></a>
    
        </li>
    
        <li class="profile" style="list-style-type: none;">
    
          <a href="#"><img src="http://placehold.it/50x50"></a>
    
        </li>
    
        <li class="profile" style="list-style-type: none;">
    
          <a href="#"><img src="http://placehold.it/50x50"></a>
    
        </li>
    
        <li class="profile" style="list-style-type: none;">
    
          <a href="#"><img src="http://placehold.it/50x50"></a>
    
        </li>
    
        <li class="profile" style="list-style-type: none;">
    
          <a href="#"><img src="http://placehold.it/50x50"></a>
    
        </li>
    
        <li class="profile" style="list-style-type: none;">
    
          <a href="#"><img src="http://placehold.it/50x50"></a>
    
        </li>
    
          </ul>
    
     
    
        </ion-content>
    
    </ion-view>

    Now, our explore page will look like this:

    PhoneGap 4 Mobile Application Development Cookbook

  13. For the last, we will create our profile page. The profile page consists of two parts. The first one is profile header, which shows user information such as username, profile picture, and number of post. The second part is a grid list of picture uploaded by user. It’s similar to grid view on explore page.
  14. To add profile header, open www/css/style.css and add following styles bellow existing style:
    .text-white{
    
      color:#fff;
    
    }
    
     
    
    .profile-pic {
    
        width: 30%;
    
        height: auto;
    
        display: block;
    
        margin-top: -50%;
    
        margin-left: auto;
    
        margin-right: auto;
    
        margin-bottom: 20%;
    
        border-radius: 4em 4em 4em / 4em 4em;
    
    }
  15. Open www/templates/tab-account.html and then add following code inside ion-content:
    <ion-content>
    
     
    
    <div class="user-profile" style="width:100%;heigh:auto;background-color:#fff;float:left;">
    
        <img src="img/cover.jpg">
    
        <div class="avatar">
    
          <img src="img/ionic.png" class="profile-pic">
    
          <ul>
    
            <li>
    
              <p class="text-white text-center" style="margin-top:-15%;margin-bottom:10%;display:block;">@ionsnap, 6 Pictures</p>
    
            </li>
    
           
    
          </ul>
    
         
    
         
    
        </div>
    
      </div>
    
    …
  16. The second part of profile page is the grid list of user images. Let’s add some pictures under profile header and before the close of ion-content tag:
    <ul class="profile" style="margin-left:5%;">
    
      <li class="profile">
    
        <a href="#"><img src="http://placehold.it/100x100"></a>
    
      </li>
    
      <li class="profile" style="list-style-type: none;">
    
        <a href="#"><img src="http://placehold.it/100x100"></a>
    
      </li>
    
      <li class="profile" style="list-style-type: none;">
    
        <a href="#"><img src="http://placehold.it/100x100"></a>
    
      </li>
    
      <li class="profile" style="list-style-type: none;">
    
        <a href="#"><img src="http://placehold.it/100x100"></a>
    
      </li>
    
      <li class="profile" style="list-style-type: none;">
    
        <a href="#"><img src="http://placehold.it/100x100"></a>
    
      </li>
    
      <li class="profile" style="list-style-type: none;">
    
        <a href="#"><img src="http://placehold.it/100x100"></a>
    
      </li>
    
    </ul>
    
     
    
    </ion-content>

    Our profile page will now look like this:

    PhoneGap 4 Mobile Application Development Cookbook

Summary

In this article we have seen steps to create Instagram clone with an Ionic framework with the help of an example.

If you are a developer who wants to get started with mobile application development using PhoneGap, then this article is for you. Basic understanding of web technologies such as HTML, CSS and JavaScript is a must.

Resources for Article:


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here