Hi guys,
I have an Entry
with some Triggers
. One of them is checking is an email is valid. The problem is that a user pastes an email, the Entry
doesn't fire the Triggers
.
How can I update an Entry
in this case?
I tried to prevent Cut
, Paste
or Copy
but it doesn't work.
iOS
[assembly: ExportRenderer(typeof(Entry), typeof(EntryCustomRenderer))] namespace MyProject.iOS.Renderers { /// <summary> /// Entry extra renderer. /// </summary> public class EntryCustomRenderer : EntryRenderer { [...] public override bool CanPerform(ObjCRuntime.Selector action, Foundation.NSObject withSender) { if (action.Name == "paste:" || action.Name == "copy:" || action.Name == "cut:") return false; return base.CanPerform(action, withSender); } } }
Android
Callback
namespace MyProject.Droid.Renderers { public class Callback : Java.Lang.Object, ActionMode.ICallback { public bool OnActionItemClicked(ActionMode mode, IMenuItem item) { return false; } public bool OnCreateActionMode(ActionMode mode, IMenu menu) { return false; } public void OnDestroyActionMode(ActionMode mode) { } public bool OnPrepareActionMode(ActionMode mode, IMenu menu) { return false; } } }
EntryRender
public class EntryCustomRenderer : EntryRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { base.OnElementChanged(e); [...] // prevent copy/paste Control.CustomSelectionActionModeCallback = new Callback(); } }
Thanks in advance
Answers
@EnricoRossini - I remove Cut and Paste options using the following (excuse the magic numbers):
For iOS:
For Android:
Thank @JohnHardman
I applied your code but I have the same result. See the attach. I replaced my code in Callback with yours.
@EnricoRossini - I cannot remember why (I should have commented it), but for Android, I put the callback handling in my main Activity class, and then in my custom Entry renderer, did:
That doesn't look like something I would have done without a good reason :-) Might be worth a try.
In my
MainActivity
I put the callbackIn my
EntryCustomRenderer
I wroteI can paste everything.
@EnricoRossini - I'm afraid I don't remember what more (if anything) I had to do on Android to remove Cut & Paste. Whilst I have it working, I don't have time right now to work out what else in my codebase might have affected this.
Is the other code above working for you on iOS?
In iOS
action
has a lot ofName
But
paste
is not in the list. Then when an entry has a long press, it displaysPaste
@EnricoRossini did you find any solution to disable paste function
@EnricoRossini @SivaShankarArumugam Were you guys able to hide
paste
? I'm having this issue now.