Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): cordova events not firing #4712

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const nativeBridge = (function (exports) {
return filePath;
};
const initEvents = (win, cap) => {
const doc = win.document;
const cordova = win.cordova;
cap.addListener = (pluginName, eventName, callback) => {
const callbackId = cap.nativeCallback(pluginName, 'addListener', {
eventName: eventName,
Expand All @@ -58,6 +56,7 @@ const nativeBridge = (function (exports) {
}, callback);
};
cap.createEvent = (eventName, eventData) => {
const doc = win.document;
if (doc) {
const ev = doc.createEvent('Events');
ev.initEvent(eventName, false, false);
Expand All @@ -74,6 +73,8 @@ const nativeBridge = (function (exports) {
return null;
};
cap.triggerEvent = (eventName, target, eventData) => {
const doc = win.document;
const cordova = win.cordova;
eventData = eventData || {};
const ev = cap.createEvent(eventName, eventData);
if (ev) {
Expand Down
6 changes: 3 additions & 3 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const initBridge = (w: any): void => {
};

const initEvents = (win: WindowCapacitor, cap: CapacitorInstance) => {
const doc = win.document;
const cordova = win.cordova;

cap.addListener = (pluginName, eventName, callback) => {
const callbackId = cap.nativeCallback(
pluginName,
Expand Down Expand Up @@ -81,6 +78,7 @@ const initBridge = (w: any): void => {
};

cap.createEvent = (eventName, eventData) => {
const doc = win.document;
if (doc) {
const ev = doc.createEvent('Events');
ev.initEvent(eventName, false, false);
Expand All @@ -98,6 +96,8 @@ const initBridge = (w: any): void => {
};

cap.triggerEvent = (eventName, target, eventData) => {
const doc = win.document;
const cordova = win.cordova;
eventData = eventData || {};
const ev = cap.createEvent(eventName, eventData);

Expand Down
5 changes: 3 additions & 2 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const nativeBridge = (function (exports) {
return filePath;
};
const initEvents = (win, cap) => {
const doc = win.document;
const cordova = win.cordova;
cap.addListener = (pluginName, eventName, callback) => {
const callbackId = cap.nativeCallback(pluginName, 'addListener', {
eventName: eventName,
Expand All @@ -58,6 +56,7 @@ const nativeBridge = (function (exports) {
}, callback);
};
cap.createEvent = (eventName, eventData) => {
const doc = win.document;
if (doc) {
const ev = doc.createEvent('Events');
ev.initEvent(eventName, false, false);
Expand All @@ -74,6 +73,8 @@ const nativeBridge = (function (exports) {
return null;
};
cap.triggerEvent = (eventName, target, eventData) => {
const doc = win.document;
const cordova = win.cordova;
eventData = eventData || {};
const ev = cap.createEvent(eventName, eventData);
if (ev) {
Expand Down