• Stars
    star
    205
  • Rank 191,264 (Top 4 %)
  • Language
    TypeScript
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ionic Native Mocks are designed to be used as placeholders during development for the actual Ionic Native modules.

Ionic Native Mocks

Ionic Native Mocks are designed to be used as placeholders during development for the actual Ionic Native modules. Ionic Native is a curated set of wrappers for Apache Cordova plugins that make adding any native functionality you need to your Ionic mobile application easier.

Ionic Native wraps plugin callbacks in a Promise or Observable, providing a common interface for all plugins and making it easy to use plugins with Angular change detection.

However, once you integrate these plugins into your Ionic application, use of a device or emulator is required for development and testing which can slow your workflow.

Installation

This project allows developers to use Ionic Native Mocks in place of the actual Ionic Native modules. They can be installed in via to methods.

  1. via npm: Installing these prebuilt mocks is easy but they are not easily customized.
  2. via GitHub and manually added to your Ionic project: Installing this way means the mocks can be customized to return specific data, like a specific parsing of a QR code.

Installation via npm

Run following command to install a Ionic Native Mock into your project.

npm install @ionic-native-mocks/[plug-in] --save

For instance, to install the camera mock:

npm install @ionic-native-mocks/camera --save

You also need to install the Ionic Native package for each plugin you want to add. Please see the Ionic Native documentation for complete instructions on how to add and use the plugins.

Documentation

For the full Ionic Native documentation, please visit https://ionicframework.com/docs/native/.

Basic Usage

To use a plugin, import and add the plugin provider to your @NgModule, and then inject it where you wish to use it.

// app.module.ts
import { Camera } from '@ionic-native/camera';
import { CameraMock } from '@ionic-native-mocks/camera';
...

@NgModule({
  ...

  providers: [
    ...
    { provide: Camera, useClass: CameraMock }
    ...
  ]
  ...
})
export class AppModule { }
import { Platform } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';

@Component({ ... })
export class MyComponent {

  constructor(private camera: Camera, private platform: Platform) {

    platform.ready().then(() => {

      const options: CameraOptions = {
        quality: 100,
        destinationType: this.camera.DestinationType.DATA_URL,
        encodingType: this.camera.EncodingType.JPEG,
        mediaType: this.camera.MediaType.PICTURE
      }

      this.camera.getPicture(options).then((imageData) => {
        // imageData is either a base64 encoded string or a file URI
        // If it's base64:
        console.log(imageData);
        let base64Image = 'data:image/jpeg;base64,' + imageData;
      }, (err) => {
        // Handle error
      });
    });
  }
}

Customization

To learn how to customize an Ionic Native Mock, see the guide at: https://chrisgriffith.wordpress.com/2017/08/21/customizing-ionic-native-mocks/ (https://chrisgriffith.wordpress.com/2017/08/21/customizing-ionic-native-mocks/)

Missing a mock? Found a problem?

Let us know or submit a PR!

Credits

Chris Griffith - @chrisgriffith

Leif Wells - @leifwells

More Repositories

1

glasstone-dolan

HTML conversion project
HTML
14
star
2

Ionic-Brackets-Extension

A Brackets code hinting extension for the Ionic Framework
JavaScript
11
star
3

jQuery-Mobile-Brackets-Extension

jQuery Mobile Brackets Code Hinting Extension
JavaScript
10
star
4

Ionic2Do

Source Code for Mobile App Development with Ionic
JavaScript
9
star
5

O-Reilly-Ionic-Video

JavaScript
8
star
6

ng-conf-workshop

For the 2016 ng-conf workshop on Ionic v2
7
star
7

OnsenUI-Brackets-Extension

JavaScript
5
star
8

ionic-profile-design

TypeScript
4
star
9

Ionic2Parks

Source Code for Mobile App Development with Ionic 2
JavaScript
4
star
10

Polymer-Brackets-Extension

A Brackets code hinting extension for the Polymer Project
JavaScript
4
star
11

ionic4book-weather

The source code for Mobile App Development with Ionic's Weather sample app.
TypeScript
4
star
12

ionic-sidemenu-demo

A sample app with a vertical tab like nav system
TypeScript
4
star
13

autocomplete-ionic-framework

CoffeeScript
3
star
14

autocomplete-angular-material

CoffeeScript
3
star
15

Ionic-Unlock-Component

CSS
2
star
16

Phonegap-Demo

Lynda.com demo assets
CSS
2
star
17

autocomplete-zurb-apps

CoffeeScript
1
star
18

autocomplete-onsenui

CoffeeScript
1
star
19

dsnNow

TypeScript
1
star
20

Ionic2Weather

Source Code for Mobile App Development with Ionic 2
JavaScript
1
star
21

electron-preso

CSS
1
star
22

Adobe-MAX-2013

Adobe MAX 2013 - Workshop Assets
CSS
1
star
23

ionic4book-parks

The source code for Mobile App Development with Ionic's National Park sample app.
TypeScript
1
star
24

apress-autoupdate-server

Code for the Auto Update Server for Apress' Electron: Beginner to Pro
JavaScript
1
star