Angular 角度-禁用用户双击时弹出的上下文菜单
我正在尝试禁用NativeScript+Angular移动应用程序(iOS和Android平台)中的剪切、复制、粘贴和选择所有操作 在我创建的指令中(如下所示) 我对使用Angular的NativeSCript非常陌生。因此,任何帮助都将不胜感激Angular 角度-禁用用户双击时弹出的上下文菜单,angular,nativescript,Angular,Nativescript,我正在尝试禁用NativeScript+Angular移动应用程序(iOS和Android平台)中的剪切、复制、粘贴和选择所有操作 在我创建的指令中(如下所示) 我对使用Angular的NativeSCript非常陌生。因此,任何帮助都将不胜感激 使用本机API时,请参考官方android文档,setOnTouchListener(…)需要一个接口实例 textField.nativeView.setOnTouchListener(new android.view.View.OnTouchLis
使用本机API时,请参考官方android文档,
setOnTouchListener(…)
需要一个接口实例
textField.nativeView.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function (view, event) {
if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
view.requestFocus();
utils.ad.showSoftInput(view);
}
return true;
}
}));
setOnTouchListener()需要OnTouchListener()作为参数。您应该尝试使用setOnTouchListener(null)或创建一个什么都不做的OnTouchListener()。iOS平台呢@Manoj这个问题是针对Android的,你有没有在iOS上测试过它?这在Android上很好,但iOS应用程序崩溃了。TypeError:试图更改不可配置属性@ManojThis的getter是针对Android的,而不是针对iOS的。我们在这里使用的是Android原生API。运行此代码之前必须执行平台检查。平台检查已经存在。在此行抛出错误-Object.defineProperty(textField.nativeView,“disableMenu”,“{@Manoj
textField.nativeView.setOnTouchListener(false);
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;
}
}
}
System.err: Error: Cannot convert boolean to Landroid/view/View$OnTouchListener; at index 0
textField.nativeView.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function (view, event) {
if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
view.requestFocus();
utils.ad.showSoftInput(view);
}
return true;
}
}));