2016-07-08 06:29:03 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
|
|
|
|
|
2016-06-26 23:14:48 +08:00
|
|
|
declare var window: any;
|
2016-07-08 06:29:03 +08:00
|
|
|
|
2016-06-10 09:25:53 +08:00
|
|
|
/**
|
2016-06-10 09:47:27 +08:00
|
|
|
* @name 3DTouch
|
2016-06-10 09:25:53 +08:00
|
|
|
* @description
|
|
|
|
* @usage
|
2016-06-10 09:51:23 +08:00
|
|
|
* Please do refer to the original plugin's repo for detailed usage. The usage example here might not be sufficient.
|
2016-06-10 09:47:27 +08:00
|
|
|
* ```
|
2016-07-20 23:17:09 +08:00
|
|
|
* import { ThreeDeeTouch } from 'ionic-native';
|
2016-06-10 09:47:27 +08:00
|
|
|
*
|
2016-07-01 21:54:45 +08:00
|
|
|
* // import for type completion on variables
|
2016-07-20 23:17:09 +08:00
|
|
|
* import { ThreeDeeTouchQuickAction, ThreeDeeTouchForceTouch } from 'ionic-native';
|
2016-06-10 09:47:27 +08:00
|
|
|
* ...
|
|
|
|
*
|
2016-07-20 23:17:09 +08:00
|
|
|
* ThreeDeeTouch.isAvailable().then(isAvailable => console.log("3D Touch available? " + isAvailable));
|
2016-06-10 09:47:27 +08:00
|
|
|
*
|
|
|
|
* ThreeDeeTouch.watchForceTouches()
|
|
|
|
* .subscribe(
|
|
|
|
* (data: ThreeDeeTouchForceTouch) => {
|
|
|
|
* console.log("Force touch %" + data.force);
|
|
|
|
* console.log("Force touch timestamp: " + data.timestamp);
|
|
|
|
* console.log("Force touch x: " + data.x);
|
|
|
|
* console.log("Force touch y: " + data.y);
|
|
|
|
* }
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* let actions: Array<ThreeDeeTouchQuickAction> = [
|
|
|
|
* {
|
|
|
|
* type: 'checkin',
|
|
|
|
* title: 'Check in',
|
|
|
|
* subtitle: 'Quickly check in',
|
|
|
|
* iconType: 'Compose'
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* type: 'share',
|
|
|
|
* title: 'Share',
|
|
|
|
* subtitle: 'Share like you care',
|
|
|
|
* iconType: 'Share'
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* type: 'search',
|
|
|
|
* title: 'Search',
|
|
|
|
* iconType: 'Search'
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* title: 'Show favorites',
|
|
|
|
* iconTemplate: 'HeartTemplate'
|
|
|
|
* }
|
|
|
|
* ];
|
|
|
|
* ThreeDeeTouch.configureQuickActions(actions);
|
2016-07-01 21:54:45 +08:00
|
|
|
*
|
|
|
|
* ThreeDeeTouchForceTouch.onHomeIconPressed().subscribe(
|
|
|
|
* (payload) => {
|
|
|
|
* // returns an object that is the button you presed
|
2016-07-20 23:17:09 +08:00
|
|
|
* console.log('Pressed the ${payload.title} button')
|
2016-07-01 21:54:45 +08:00
|
|
|
* console.log(payload.type)
|
|
|
|
*
|
|
|
|
* }
|
|
|
|
* )
|
2016-06-10 09:47:27 +08:00
|
|
|
* ```
|
2016-06-10 09:25:53 +08:00
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-07-08 06:29:03 +08:00
|
|
|
plugin: 'cordova-plugin-3dtouch',
|
|
|
|
pluginRef: 'ThreeDeeTouch',
|
|
|
|
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-3dtouch',
|
|
|
|
platforms: ['iOS']
|
2016-06-10 09:47:27 +08:00
|
|
|
})
|
|
|
|
export class ThreeDeeTouch {
|
|
|
|
|
2016-07-08 06:29:03 +08:00
|
|
|
/**
|
|
|
|
* You need an iPhone 6S or some future tech to use the features of this plugin, so you can check at runtime if the user's device is supported.
|
|
|
|
* @returns {Promise<boolean>} returns a promise that resolves with a boolean that indicates whether the plugin is available or not
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static isAvailable(): Promise<boolean> { return; }
|
2016-06-10 09:47:27 +08:00
|
|
|
|
2016-07-08 06:29:03 +08:00
|
|
|
/**
|
|
|
|
* You can get a notification when the user force touches the webview. The plugin defines a Force Touch when at least 75% of the maximum force is applied to the screen. Your app will receive the x and y coordinates, so you have to figure out which UI element was touched.
|
|
|
|
* @returns {Observable<ThreeDeeTouchForceTouch>} Returns an observable that sends a `ThreeDeeTouchForceTouch` object
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true
|
|
|
|
})
|
|
|
|
static watchForceTouches(): Observable<ThreeDeeTouchForceTouch> { return; }
|
2016-06-10 09:47:27 +08:00
|
|
|
|
2016-07-08 06:29:03 +08:00
|
|
|
/**
|
|
|
|
* setup the 3D-touch actions, takes an array of objects with the following
|
|
|
|
* @param {string} type (optional) A type that can be used `onHomeIconPressed` callback
|
|
|
|
* @param {string} title Title for your action
|
|
|
|
* @param {string} subtitle (optional) A short description for your action
|
|
|
|
* @param {string} iconType (optional) Choose between Prohibit, Contact, Home, MarkLocation, Favorite, Love, Cloud, Invitation, Confirmation, Mail, Message, Date, Time, CapturePhoto, CaptureVideo, Task, TaskCompleted, Alarm, Bookmark, Shuffle, Audio, Update
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
static configureQuickActions(quickActions: Array<ThreeDeeTouchQuickAction>): void { }
|
2016-06-10 09:47:27 +08:00
|
|
|
|
2016-07-08 06:29:03 +08:00
|
|
|
/**
|
|
|
|
* When a home icon is pressed, your app launches and this JS callback is invoked.
|
|
|
|
* @returns {Observable<any>} returns an observable that notifies you when he user presses on the home screen icon
|
|
|
|
*/
|
|
|
|
static onHomeIconPressed(): Observable<any> {
|
|
|
|
return new Observable(observer => {
|
|
|
|
if (window.ThreeDeeTouch && window.ThreeDeeTouch.onHomeIconPressed) window.ThreeDeeTouch.onHomeIconPressed = observer.next.bind(observer);
|
|
|
|
else {
|
|
|
|
observer.error('3dTouch plugin is not available.');
|
|
|
|
observer.complete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-06-10 09:47:27 +08:00
|
|
|
|
2016-07-08 06:29:03 +08:00
|
|
|
/**
|
|
|
|
* Enable Link Preview.
|
|
|
|
* UIWebView and WKWebView (the webviews powering Cordova apps) don't allow the fancy new link preview feature of iOS9.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
static enableLinkPreview(): void { }
|
2016-06-10 09:47:27 +08:00
|
|
|
|
2016-07-08 06:29:03 +08:00
|
|
|
/**
|
|
|
|
* Disabled the link preview feature, if enabled.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
static disableLinkPreview(): void { }
|
2016-07-20 23:17:09 +08:00
|
|
|
|
2016-06-10 09:47:27 +08:00
|
|
|
}
|
2016-07-20 23:17:09 +08:00
|
|
|
|
2016-06-10 09:47:27 +08:00
|
|
|
export interface ThreeDeeTouchQuickAction {
|
2016-07-08 06:29:03 +08:00
|
|
|
type?: string;
|
|
|
|
title: string;
|
|
|
|
subtitle?: string;
|
|
|
|
iconType?: string;
|
2016-06-10 09:47:27 +08:00
|
|
|
}
|
2016-07-20 23:17:09 +08:00
|
|
|
|
2016-06-10 09:47:27 +08:00
|
|
|
export interface ThreeDeeTouchForceTouch {
|
2016-07-08 06:29:03 +08:00
|
|
|
force: number;
|
|
|
|
timestamp: number;
|
|
|
|
x: number;
|
|
|
|
y: number;
|
2016-07-01 05:28:23 +08:00
|
|
|
}
|