xamarin/Xamarin.Forms

Focused and UnFocused event of the Editor is not triggered when Editor’s renderer (EditText) is added as custom renderer in Xamarin Forms Android

オープン

#4,231 opened on 2018/10/26

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (1,926 件のフォーク)batch import
e/4 :clock4:help wantedinactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

Description

In my scenario I have added Editor’s renderer (EditText) as custom renderer for my custom layout, FousChanged event of EditText triggers properly but Focused and UnFocused event of Editor is not triggering. When I analyzed the issue, Focused and UnFocused event will be triggered when IsFocused property of Editor is True, in my scenario IsFocused property is not assigned to True. Since, it is read only property I cannot manually assign IsFocused as true. Could you please suggest any override method to check the IsFocused property and also, please provide details about when IsFocused will be assigned as True. Kindly find the code snippet and sample below,

Code snippet:

public class CustomEditor : Editor
 {
 }

CustomEditor customEditor = new CustomEditor();


protected override void OnElementChanged(ElementChangedEventArgs<CustomStack> e)

{

Android.Widget.ScrollView stack = new Android.Widget.ScrollView(Context);

if (e.NewElement != null)

{

var renderer = Platform.CreateRenderer(customEditor);

var nativeEditor = RendererHelper.GetNativeView(renderer.View);


(nativeEditor as EditText).FocusChange += Handle_FocusChange;

nativeEditor.RemoveFromParent();

stack.AddView(nativeEditor);


SetNativeControl(stack);

}
 base.OnElementChanged(e);
 }

Sample:
CustomEditor.zip

Note: This scenario works properly in Xamarin Forms UWP and iOS.

Regards, Ganeshamoorthy C

コントリビューターガイド