DEV Community

george_pollock
george_pollock

Posted on • Originally published at hvitis.dev on

IONIC 4 How to make an app in a few days.

How you can make a mobile app with just JavaScript

Disclaimer : Title is catchy but true. App in this article was created with Angular implemented with TypeScript but you can follow itโ€™s architecture and replicate it with Vanilla JavaScript.

Why should you make an app? ๐Ÿ“ฑ

You may have some cool idea in your head, or you want to have just an app between your friends that does X. There may be many reasons. What is common between them, that path to your own app is fun and educational. Just about anybody can learn a lot - if you are Senior coder with mustach ๐Ÿ‘ด you can make your app with a new framework to get to know it! If you are not even Junior programmer then Iโ€™m just showing you that there is a resource / possibility of creating an app with one of the most popular and forgiving ( or should I say - beginner friendly ) languages out there. No more excuses! Me, personally, I just wanted to have my own app in Google Store, thatโ€™s it. You donโ€™t need more! Each tier of experience will of course benefit from this in another way. If youโ€™re starting your journey it might be an ambitious task but itโ€™s not impossible. Some time ago I didnโ€™t even know that itโ€™s possible to make an App without knowing Java or some advanced Wizardy ๐Ÿ”ฎ

So where do I start โ” - The Big picture ( pick up a Framework )

Currently there is more than a few frameworks that provide compiling from non-native code to an app bundle that you could upload to Google Shop or Apple Store. Just to name the most popular in random order:

  • React native
  • Flutter
  • Xamarin
  • Ionic 4 Which one to choose then? The title of this post is for people who come from Vanilla JavaScript (which is pure JavaScript, no frameworks, no JQuery etc). Xamarin uses C#, Flutter uses Dart, finally React Native comes closer to using JavaScript but still - you need to have knowledge of React (React Native to be exact, since itโ€™s a bit different than pure React Whatโ€™s the difference between them .) Whatโ€™s left? Thatโ€™s right! Ionic 4

The Ionic 4 as a project has started with Angular architecture as a spine for App development but with time they have added support for different frameworks (Vue, React, Angular). While writing your code inside components you CAN you can also Vanilla JavaScript.

alt text

Becauses I have already some Angular knowledge and the Ionic CLI provides very useful tools for creating the scaffold for it I picked up the Angular way of doing things. On the official website you have a great and beautiful tutorial on how to start your own App with just 2 commands. Great community and a few years of presence on the market gives you a lot of resources to study. Iโ€™ve used extensively Simon Grimmโ€™s youtube chanel where you can find virtually anything about Ionic (Thank You Simon) !

Project overview - What do I want to build?

As I menationed before, my main goal it to have an app. The byproduct is the knowledge I will gain in the meantime. The goal is not that complicated - I donโ€™t want to earn money off it, nor change the world so the app should be pretty simple. I came up with an idea of a picture game - You get a pixelized picture and you need to guess whatโ€™s on the picture. Can be extended with different settings like difficulty (amount of pixelization, languages etc).

Sketches needs to be make for general planning - in order to save time.

Letโ€™s get Technical - How will it work?

The app has already been made, so if you want to see how it works you can check it on Android.

There will be one top-level module (1 router) controlling all the pagesโ€™ modules.

The app will consist of 4 pages (views with specific content binded to a route):

  • Start
  • Gameplay
  • GameOver
  • Settings

There will be no backend, no API so all the data will be saves in the applicationโ€™s state. Angular for managing the state of apps uses services so I will make a service responsible for:

  • Loading pictures
  • Changing settings
  • Game progress (points earned, hints left, etc )

Usage of 3rd party library will be necessary for:

  • Rendering pictures: will be done by 3rd party library npm package called Jimp. pictures will come in small size with the app itself as its assets.
  • Sharing buttons: will be implemented with cordova-plugin-x-socialsharing.

Letโ€™s get Technical - How does it look like?

Router is the default app-routing created by default CLI:

const routes: Routes = [
  { path: "",
    loadChildren: "./start/start.module#StartPageModule"
  },
  {
    path: "gameplay",
    loadChildren: "./gameplay/gameplay.module#GameplayPageModule"
  },
  {
    path: "settings",
    loadChildren: "./settings/settings.module#SettingsPageModule"
  },

  {
    path: "gameover",
    loadChildren: "./gameover/gameover.module#GameoverPageModule"
  }
];
Enter fullscreen mode Exit fullscreen mode

Pages is a what user sees on the screen, a view.

Start Game Page - the most important things it consists of are:

  • Start Game Button
  • Settings Button
  • Share Game Button

All the buttons are nested in a Footer

Start Game Button :

<!-- start.page.html -->
<!-- ... -->
  <ion-toolbar color="success" (click)="startGame()">
    <ion-title>Start Game</ion-title>
    <ion-buttons slot="end">
      <ion-icon name="arrow-dropright-circle"></ion-icon>
    </ion-buttons>
  </ion-toolbar>
<!-- ... -->
Enter fullscreen mode Exit fullscreen mode

StartGame button calls a function that using services (custom one and router) resets all game progress (gained points in previous sessions, used hints)

// start.page.ts
// ...
  startGame() {
    this.settingsService.resetAllNewGame();
    return this.router.navigateByUrl('/gameplay');
  }
// ...
Enter fullscreen mode Exit fullscreen mode

Settings Button : Uses just a Router to navigate to a Settings Page:

<!-- start.page.html -->
<!-- ... -->
  <ion-toolbar color="secondary" [routerLink]="['/settings']">
    <ion-title>Settings</ion-title>
    <ion-buttons slot="end">
      <ion-icon name="settings"> </ion-icon>
    </ion-buttons>
  </ion-toolbar>
<!-- ... -->
Enter fullscreen mode Exit fullscreen mode

Share Game Button : Uses the mentioned capacitor library that enables native functionalities of sharing:

<!-- start.page.html -->
<!-- ... -->
<ion-toolbar
    color="primary"
    onclick="window.plugins.socialsharing.share(
        'Check out PixelatedFun app!',
        'Imagine what is hidden!',
        null,
        'https://pixelated.fun')"
  >
    <ion-title>Share</ion-title>
    <ion-buttons slot="end">
      <ion-icon name="paper-plane"> </ion-icon>
    </ion-buttons>
  </ion-toolbar>
<!-- ... -->
Enter fullscreen mode Exit fullscreen mode

Settings Page - place for adjusting difficulty etc:

<!-- settings.page.html -->
<!-- ... -->
 <ion-list>
      <ion-item>
        <ion-label>Difficulty</ion-label>
        <ion-select
          [(ngModel)]="selectedDifficulty"
          (ionChange)="changeDifficulty()"
          [placeholder]="this.difficulty"
        >
          <ion-select-option value="easy">Easy</ion-select-option>
          <ion-select-option value="normal">Normal</ion-select-option>
          <ion-select-option value="hard">Hard</ion-select-option>
        </ion-select>
      </ion-item>
    </ion-list>
<!-- ... -->
Enter fullscreen mode Exit fullscreen mode

What did I learn? - YouTube adventure

Some of the takeouts from this projects are:

  • How Google Android Store works, how to upload and publish an app.
  • How to use Google Analytics and how to publish an Advert on Google Ads.S
  • YouTube chanel: I did 2 things at once, an App and YT Chanel:

ionic 4 youtube chanell video thumb

Top comments (0)