I'm trying to disable cut, copy, paste and select all actions from a NativeScript + Angular mobile app (iOS and Android platform)
<TextField class="m-5 input input-border" disableCutCopyPaste> </TextField>
So I created a directive which works fine on Stock Android OS devices but on Custom Android OS devices, users can do cut, copy, paste action by double tapping on the text entered on the textfield
In order to disable double tap, I added the following line of code
textField.nativeView.setOnTouchListener(false);
in the directive I created (given below)
import { Directive, OnInit, OnDestroy, ElementRef, Renderer2 } from "@angular/core";
import { isIOS } from "tns-core-modules/platform";
import { layout } from "tns-core-modules/utils/utils";
import { EventData } from "tns-core-modules/data/observable";
import { TextField } from "tns-core-modules/ui/text-field";
declare var UITextField, CGRectMake;
if (isIOS) {
UITextField.prototype._originalCanPerformActionWithSender = UITextField.prototype.canPerformActionWithSender;
UITextField.prototype.canPerformActionWithSender = function (action, sender) {
if (this.disableMenu) {
return false;
}
return UITextField.prototype._originalCanPerformActionWithSender.call(this, action, sender)
};
}
@Directive({
selector: "[disableCutCopyPaste]"
})
export class DisableCutCopyPasteDirective implements OnInit, OnDestroy {
listener: () => void;
constructor(private renderer: Renderer2, private el: ElementRef) {
}
ngOnInit() {
this.listener = this.renderer.listen(this.el.nativeElement, TextField.loadedEvent, (event: EventData) => {
const textField = <TextField>event.object;
if (isIOS) {
Object.defineProperty(textField.nativeView, "disableMenu", {
get: function () {
return true;
}
});
} else {
textField.nativeView.setLongClickable(false);
textField.nativeView.setOnTouchListener(false);
}
});
}
ngOnDestroy() {
this.removeListener();
}
private removeListener() {
if (this.listener) {
this.listener();
this.listener = null;
}
}
}
It's not working and I'm getting the following error
System.err: Error: Cannot convert boolean to Landroid/view/View$OnTouchListener; at index 0
I'm pretty new to NativeSCript with Angular. So any help would be appreciated.