Device ready call

This commit is contained in:
Max Lynch 2015-11-29 16:30:15 -06:00
parent 3327fe8f45
commit 45dc983752
23 changed files with 150 additions and 14 deletions

View File

@ -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

View File

@ -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
View File

@ -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
View File

@ -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
View File

@ -0,0 +1,4 @@
export declare class ActionSheet {
static show: any;
static hide: any;
}

35
dist/plugins/actionsheet.js vendored Normal file
View 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;

View File

@ -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() {
}

View File

@ -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;
}

View File

@ -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
View File

@ -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
View File

@ -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);

View File

@ -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() {
}

View File

@ -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;
}

View File

@ -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
View File

@ -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
View File

@ -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;

View File

@ -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);

View 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;
}

View File

@ -1,7 +1,5 @@
import {Plugin, Cordova} from './plugin';
let PLUGIN_REF = 'navigator.camera';
@Plugin({
name: 'Camera',
plugin: 'cordova-plugin-camera',

View File

@ -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;
}

View File

@ -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({

View File

@ -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;

View File

@ -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",