Skip to content

Instantly share code, notes, and snippets.

@joshstrange
Created July 5, 2019 14:22
Show Gist options
  • Save joshstrange/23546d07c9294671200d3b5f4c85c934 to your computer and use it in GitHub Desktop.
Save joshstrange/23546d07c9294671200d3b5f4c85c934 to your computer and use it in GitHub Desktop.
Patch ionic angular to fix swipe back issue
/* tslint:disable */
var fs = require('fs');
let filePath = './node_modules/@ionic/angular/dist/fesm5.js';
let monkeyPatch = `// Start monkey patching
StackController.prototype.startBackTransition = function () {
return __awaiter(this, void 0, void 0, function () {
var leavingView, views, enteringView_1;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
leavingView = this.activeView;
if (!leavingView) return [3 /*break*/, 2];
views = this.getStack(leavingView.stackId);
enteringView_1 = views[views.length - 2];
enteringView_1.ref.changeDetectorRef.reattach();
return [4 /*yield*/, this.wait((/**
* @return {?}
*/
function () {
return _this.transition(enteringView_1, // entering view
leavingView, // leaving view
'back', true, false);
}))];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
};
StackController.prototype.endBackTransition = function (shouldComplete) {
shouldComplete = true;
if (shouldComplete) {
this.skipTransition = true;
this.pop(1);
}
};
// End monkey patching`;
if(fs.existsSync(filePath)) {
console.log('Found File to patch');
let lines = fs.readFileSync(filePath, {encoding: 'UTF-8'}).split('\n');
let monkeyPatchLines = monkeyPatch.split('\n');
if(!lines[lines.length - 2].startsWith('export')) {
throw new Error('Something is odd, bailing');
}
if(lines[lines.length - 3] === monkeyPatchLines[monkeyPatchLines.length-1]) {
console.log('Already patched!');
} else {
console.log('Patching...');
lines.splice(lines.length - 3, 1, monkeyPatch);
fs.writeFileSync(filePath, lines.join('\n'));
console.log('Patched!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment