Skip to content

Commit 9efeb0a

Browse files
authored
refactor(haptics): remove cordova haptics support (#29186)
BREAKING CHANGE: Support for the Cordova Haptics plugin has been removed. Components that integrate with haptics, such as `ion-picker` and `ion-toggle`, will continue to function but will no longer play haptics in Cordova environments. Developers should migrate to Capacitor to continue to have haptics in these components.
1 parent b0a10df commit 9efeb0a

File tree

2 files changed

+13
-57
lines changed

2 files changed

+13
-57
lines changed

BREAKING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver
1616
- [Browser and Platform Support](#version-8x-browser-platform-support)
1717
- [Dark Mode](#version-8x-dark-mode)
1818
- [Global Styles](#version-8x-global-styles)
19+
- [Haptics](#version-8x-haptics)
1920
- [Components](#version-8x-components)
2021
- [Button](#version-8x-button)
2122
- [Checkbox](#version-8x-checkbox)
@@ -141,6 +142,10 @@ Developers who want to disable dynamic font scaling can set `--ion-dynamic-font:
141142

142143
For more information on the dynamic font, refer to the [Dynamic Font Scaling documentation](https://ionicframework.com/docs/layout/dynamic-font-scaling).
143144

145+
<h2 id="version-8x-haptics">Haptics</h2>
146+
147+
- Support for the Cordova Haptics plugin has been removed. Components that integrate with haptics, such as `ion-picker` and `ion-toggle`, will continue to function but will no longer play haptics in Cordova environments. Developers should migrate to Capacitor to continue to have haptics in these components.
148+
144149
<h2 id="version-8x-components">Components</h2>
145150

146151
<h4 id="version-8x-button">Button</h4>

core/src/utils/native/haptic.ts

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,8 @@ interface HapticNotificationOptions {
5656
type: CapacitorNotificationType;
5757
}
5858

59-
interface TapticEngine {
60-
gestureSelectionStart: () => void;
61-
gestureSelectionChanged: () => void;
62-
gestureSelectionEnd: () => void;
63-
}
64-
6559
const HapticEngine = {
6660
getEngine(): HapticsPlugin | undefined {
67-
const tapticEngine = (window as any).TapticEngine;
68-
if (tapticEngine) {
69-
// Cordova
70-
// TODO FW-4707 - Remove this in Ionic 8
71-
return tapticEngine;
72-
}
7361
const capacitor = getCapacitor();
7462

7563
if (capacitor?.isPluginAvailable('Haptics')) {
@@ -102,82 +90,45 @@ const HapticEngine = {
10290

10391
return true;
10492
},
105-
isCordova() {
106-
return (window as any).TapticEngine !== undefined;
107-
},
108-
isCapacitor() {
109-
return getCapacitor() !== undefined;
110-
},
11193
impact(options: HapticImpactOptions) {
11294
const engine = this.getEngine();
11395
if (!engine) {
11496
return;
11597
}
116-
/**
117-
* To provide backwards compatibility with Cordova apps,
118-
* we convert the style to lowercase.
119-
*
120-
* TODO: FW-4707 - Remove this in Ionic 8
121-
*/
122-
const style = this.isCapacitor() ? options.style : (options.style.toLowerCase() as ImpactStyle);
123-
engine.impact({ style });
98+
99+
engine.impact({ style: options.style });
124100
},
125101
notification(options: HapticNotificationOptions) {
126102
const engine = this.getEngine();
127103
if (!engine) {
128104
return;
129105
}
130-
/**
131-
* To provide backwards compatibility with Cordova apps,
132-
* we convert the style to lowercase.
133-
*
134-
* TODO: FW-4707 - Remove this in Ionic 8
135-
*/
136-
const type = this.isCapacitor() ? options.type : (options.type.toLowerCase() as NotificationType);
137-
engine.notification({ type });
106+
107+
engine.notification({ type: options.type });
138108
},
139109
selection() {
140-
/**
141-
* To provide backwards compatibility with Cordova apps,
142-
* we convert the style to lowercase.
143-
*
144-
* TODO: FW-4707 - Remove this in Ionic 8
145-
*/
146-
const style = this.isCapacitor() ? ImpactStyle.Light : ('light' as ImpactStyle);
147-
this.impact({ style });
110+
this.impact({ style: ImpactStyle.Light });
148111
},
149112
selectionStart() {
150113
const engine = this.getEngine();
151114
if (!engine) {
152115
return;
153116
}
154-
if (this.isCapacitor()) {
155-
engine.selectionStart();
156-
} else {
157-
(engine as unknown as TapticEngine).gestureSelectionStart();
158-
}
117+
engine.selectionStart();
159118
},
160119
selectionChanged() {
161120
const engine = this.getEngine();
162121
if (!engine) {
163122
return;
164123
}
165-
if (this.isCapacitor()) {
166-
engine.selectionChanged();
167-
} else {
168-
(engine as unknown as TapticEngine).gestureSelectionChanged();
169-
}
124+
engine.selectionChanged();
170125
},
171126
selectionEnd() {
172127
const engine = this.getEngine();
173128
if (!engine) {
174129
return;
175130
}
176-
if (this.isCapacitor()) {
177-
engine.selectionEnd();
178-
} else {
179-
(engine as unknown as TapticEngine).gestureSelectionEnd();
180-
}
131+
engine.selectionEnd();
181132
},
182133
};
183134

0 commit comments

Comments
 (0)