Device ready call
This commit is contained in:
parent
3327fe8f45
commit
45dc983752
@ -1,6 +1,6 @@
|
||||
import {Page, NavController} from 'ionic/ionic'
|
||||
|
||||
import {Camera, StatusBar, Toast} from 'ionic-native';
|
||||
import {ActionSheet, Camera, StatusBar, Toast} from 'ionic-native';
|
||||
|
||||
import {Plugin} from '../plugin/plugin';
|
||||
|
||||
@ -12,6 +12,7 @@ export class HomePage {
|
||||
this.nav = nav;
|
||||
|
||||
this.plugins = [
|
||||
ActionSheet,
|
||||
Camera,
|
||||
StatusBar,
|
||||
Toast
|
||||
|
@ -1,9 +1,21 @@
|
||||
import {Page, NavParams} from 'ionic/ionic';
|
||||
|
||||
import {Camera, StatusBar, Toast} from 'ionic-native';
|
||||
import {Camera, StatusBar, Toast, ActionSheet} from 'ionic-native';
|
||||
|
||||
// To specify arguments for any plugin calls
|
||||
var demoArgs = {};
|
||||
demoArgs[ActionSheet] = {
|
||||
show: {
|
||||
'title': 'What do you want with this image?',
|
||||
'buttonLabels': ['Share via Facebook', 'Share via Twitter'],
|
||||
'androidEnableCancelButton' : true, // default false
|
||||
'winphoneEnableCancelButton' : true, // default false
|
||||
'addCancelButtonWithLabel': 'Cancel',
|
||||
'addDestructiveButtonWithLabel' : 'Delete it',
|
||||
'position': [20, 40] // for iPad pass in the [x, y] position of the popover
|
||||
}
|
||||
}
|
||||
|
||||
demoArgs[Toast] = {
|
||||
showWithOptions: [
|
||||
{
|
||||
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
export * from './plugins/actionsheet';
|
||||
export * from './plugins/camera';
|
||||
export * from './plugins/statusbar';
|
||||
export * from './plugins/toast';
|
||||
|
11
dist/index.js
vendored
11
dist/index.js
vendored
@ -1,6 +1,17 @@
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
var DEVICE_READY_TIMEOUT = 2000;
|
||||
__export(require('./plugins/actionsheet'));
|
||||
__export(require('./plugins/camera'));
|
||||
__export(require('./plugins/statusbar'));
|
||||
__export(require('./plugins/toast'));
|
||||
var didFireReady = false;
|
||||
window.addEventListener('deviceready', function () {
|
||||
didFireReady = true;
|
||||
});
|
||||
setTimeout(function () {
|
||||
if (!didFireReady) {
|
||||
console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.');
|
||||
}
|
||||
}, DEVICE_READY_TIMEOUT);
|
||||
|
4
dist/plugins/actionsheet.d.ts
vendored
Normal file
4
dist/plugins/actionsheet.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export declare class ActionSheet {
|
||||
static show: any;
|
||||
static hide: any;
|
||||
}
|
35
dist/plugins/actionsheet.js
vendored
Normal file
35
dist/plugins/actionsheet.js
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
|
||||
switch (arguments.length) {
|
||||
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
|
||||
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
|
||||
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
|
||||
}
|
||||
};
|
||||
var plugin_1 = require('./plugin');
|
||||
var ActionSheet = (function () {
|
||||
function ActionSheet() {
|
||||
}
|
||||
__decorate([
|
||||
plugin_1.Cordova({
|
||||
successIndex: 1,
|
||||
errIndex: 2
|
||||
})
|
||||
], ActionSheet, "show");
|
||||
__decorate([
|
||||
plugin_1.Cordova({
|
||||
successIndex: 1,
|
||||
errIndex: 2
|
||||
})
|
||||
], ActionSheet, "hide");
|
||||
ActionSheet = __decorate([
|
||||
plugin_1.Plugin({
|
||||
name: 'ActionSheet',
|
||||
plugin: 'cordova-plugin-actionsheet',
|
||||
pluginRef: 'plugins.actionsheet',
|
||||
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-actionsheet'
|
||||
})
|
||||
], ActionSheet);
|
||||
return ActionSheet;
|
||||
})();
|
||||
exports.ActionSheet = ActionSheet;
|
1
dist/plugins/camera.js
vendored
1
dist/plugins/camera.js
vendored
@ -7,7 +7,6 @@ if (typeof __decorate !== "function") __decorate = function (decorators, target,
|
||||
}
|
||||
};
|
||||
var plugin_1 = require('./plugin');
|
||||
var PLUGIN_REF = 'navigator.camera';
|
||||
var Camera = (function () {
|
||||
function Camera() {
|
||||
}
|
||||
|
7
dist/plugins/plugin.js
vendored
7
dist/plugins/plugin.js
vendored
@ -6,8 +6,13 @@ exports.wrap = function (pluginObj, methodName, opts) {
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
console.log('Trying', pluginObj.name, methodName, args);
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!window.cordova) {
|
||||
console.warn('Native: tried calling ' + pluginObj.name + '.' + methodName + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
|
||||
reject({
|
||||
error: 'cordova_not_available'
|
||||
});
|
||||
}
|
||||
if (typeof opts.successIndex !== 'undefined') {
|
||||
args[opts.successIndex] = resolve;
|
||||
}
|
||||
|
3
dist/plugins/toast.js
vendored
3
dist/plugins/toast.js
vendored
@ -26,7 +26,8 @@ var Toast = (function () {
|
||||
plugin_1.Plugin({
|
||||
name: 'Toast',
|
||||
plugin: 'cordova-plugin-x-toast',
|
||||
pluginRef: 'plugins.toast'
|
||||
pluginRef: 'plugins.toast',
|
||||
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
|
||||
})
|
||||
], Toast);
|
||||
return Toast;
|
||||
|
1
dist/src/index.d.ts
vendored
1
dist/src/index.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
export * from './plugins/actionsheet';
|
||||
export * from './plugins/camera';
|
||||
export * from './plugins/statusbar';
|
||||
export * from './plugins/toast';
|
||||
|
11
dist/src/index.js
vendored
11
dist/src/index.js
vendored
@ -1,6 +1,17 @@
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
var DEVICE_READY_TIMEOUT = 2000;
|
||||
__export(require('./plugins/actionsheet'));
|
||||
__export(require('./plugins/camera'));
|
||||
__export(require('./plugins/statusbar'));
|
||||
__export(require('./plugins/toast'));
|
||||
var didFireReady = false;
|
||||
window.addEventListener('deviceready', function () {
|
||||
didFireReady = true;
|
||||
});
|
||||
setTimeout(function () {
|
||||
if (!didFireReady && window.cordova) {
|
||||
console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.');
|
||||
}
|
||||
}, DEVICE_READY_TIMEOUT);
|
||||
|
1
dist/src/plugins/camera.js
vendored
1
dist/src/plugins/camera.js
vendored
@ -8,7 +8,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var plugin_1 = require('./plugin');
|
||||
var PLUGIN_REF = 'navigator.camera';
|
||||
var Camera = (function () {
|
||||
function Camera() {
|
||||
}
|
||||
|
7
dist/src/plugins/plugin.js
vendored
7
dist/src/plugins/plugin.js
vendored
@ -6,8 +6,13 @@ exports.wrap = function (pluginObj, methodName, opts) {
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i - 0] = arguments[_i];
|
||||
}
|
||||
console.log('Trying', pluginObj.name, methodName, args);
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!window.cordova) {
|
||||
console.warn('Native: tried calling ' + pluginObj.name + '.' + methodName + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
|
||||
reject({
|
||||
error: 'cordova_not_available'
|
||||
});
|
||||
}
|
||||
if (typeof opts.successIndex !== 'undefined') {
|
||||
args[opts.successIndex] = resolve;
|
||||
}
|
||||
|
3
dist/src/plugins/toast.js
vendored
3
dist/src/plugins/toast.js
vendored
@ -29,7 +29,8 @@ var Toast = (function () {
|
||||
plugin_1.Plugin({
|
||||
name: 'Toast',
|
||||
plugin: 'cordova-plugin-x-toast',
|
||||
pluginRef: 'plugins.toast'
|
||||
pluginRef: 'plugins.toast',
|
||||
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
|
||||
}),
|
||||
__metadata('design:paramtypes', [])
|
||||
], Toast);
|
||||
|
3
dist/src/util.js
vendored
3
dist/src/util.js
vendored
@ -1,5 +1,8 @@
|
||||
function get(obj, path) {
|
||||
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
|
||||
if (!obj) {
|
||||
return null;
|
||||
}
|
||||
obj = obj[path[i]];
|
||||
}
|
||||
return obj;
|
||||
|
3
dist/util.js
vendored
3
dist/util.js
vendored
@ -1,5 +1,8 @@
|
||||
function get(obj, path) {
|
||||
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
|
||||
if (!obj) {
|
||||
return null;
|
||||
}
|
||||
obj = obj[path[i]];
|
||||
}
|
||||
return obj;
|
||||
|
17
src/index.ts
17
src/index.ts
@ -1,3 +1,20 @@
|
||||
const DEVICE_READY_TIMEOUT = 2000;
|
||||
|
||||
export * from './plugins/actionsheet';
|
||||
export * from './plugins/camera';
|
||||
export * from './plugins/statusbar';
|
||||
export * from './plugins/toast';
|
||||
|
||||
declare var window;
|
||||
|
||||
|
||||
let didFireReady = false;
|
||||
window.addEventListener('deviceready', function() {
|
||||
didFireReady = true;
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
if(!didFireReady && window.cordova) {
|
||||
console.warn('Native: deviceready did not fire within ' + DEVICE_READY_TIMEOUT + 'ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.');
|
||||
}
|
||||
}, DEVICE_READY_TIMEOUT);
|
||||
|
21
src/plugins/actionsheet.ts
Normal file
21
src/plugins/actionsheet.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import {Plugin, Cordova} from './plugin';
|
||||
|
||||
@Plugin({
|
||||
name: 'ActionSheet',
|
||||
plugin: 'cordova-plugin-actionsheet',
|
||||
pluginRef: 'plugins.actionsheet',
|
||||
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-actionsheet'
|
||||
})
|
||||
export class ActionSheet {
|
||||
@Cordova({
|
||||
successIndex: 1,
|
||||
errIndex: 2
|
||||
})
|
||||
static show;
|
||||
|
||||
@Cordova({
|
||||
successIndex: 1,
|
||||
errIndex: 2
|
||||
})
|
||||
static hide;
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
import {Plugin, Cordova} from './plugin';
|
||||
|
||||
let PLUGIN_REF = 'navigator.camera';
|
||||
|
||||
@Plugin({
|
||||
name: 'Camera',
|
||||
plugin: 'cordova-plugin-camera',
|
||||
|
@ -5,9 +5,15 @@ declare var Promise;
|
||||
|
||||
export const wrap = function(pluginObj, methodName, opts: any = {}) {
|
||||
return (...args) => {
|
||||
console.log('Trying', pluginObj.name, methodName, args);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(!window.cordova) {
|
||||
console.warn('Native: tried calling ' + pluginObj.name + '.' + methodName + ', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator');
|
||||
reject({
|
||||
error: 'cordova_not_available'
|
||||
})
|
||||
}
|
||||
|
||||
if(typeof opts.successIndex !== 'undefined') {
|
||||
args[opts.successIndex] = resolve;
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ import {Plugin, Cordova} from './plugin';
|
||||
@Plugin({
|
||||
name: 'Toast',
|
||||
plugin: 'cordova-plugin-x-toast',
|
||||
pluginRef: 'plugins.toast'
|
||||
pluginRef: 'plugins.toast',
|
||||
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
|
||||
})
|
||||
export class Toast {
|
||||
@Cordova({
|
||||
|
@ -1,5 +1,6 @@
|
||||
export function get(obj, path) {
|
||||
for (var i=0, path = path.split('.'), len = path.length; i < len; i++) {
|
||||
for(var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
|
||||
if(!obj) { return null; }
|
||||
obj = obj[path[i]];
|
||||
}
|
||||
return obj;
|
||||
|
@ -15,9 +15,9 @@
|
||||
"node_modules"
|
||||
],
|
||||
"files": [
|
||||
"src/cordova.ts",
|
||||
"src/index.ts",
|
||||
"src/plugin-config.ts",
|
||||
"src/plugins/actionsheet.ts",
|
||||
"src/plugins/camera.ts",
|
||||
"src/plugins/plugin.ts",
|
||||
"src/plugins/statusbar.ts",
|
||||
|
Loading…
Reference in New Issue
Block a user