0

I am using a CustomEditorRenderer to solve the spacing issue between keyboard and Editor. I already posted a ticket related to that. Now I have attachment and send icons are in the same place. But when the keyboard appears, only Editor is showing on the UI, the attachment and send icons are not showing.

UI:

enter image description here

My XAML:

<Grid 
x:Name="newcomment_stack"
Margin="2,0,2,10"
IsVisible="false">

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="8*" />
    <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Image 
Grid.Row="0" 
Grid.Column="0"
VerticalOptions="CenterAndExpand"
x:Name="Attachment_Image"
Source="ic_attachment_xx.png">
    <Image.WidthRequest>
        <OnIdiom x:TypeArguments="x:Double">
            <OnIdiom.Phone>40</OnIdiom.Phone>
            <OnIdiom.Tablet>60</OnIdiom.Tablet>
            <OnIdiom.Desktop>40</OnIdiom.Desktop>
        </OnIdiom>
    </Image.WidthRequest>
    <Image.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
            <OnIdiom.Phone>40</OnIdiom.Phone>
            <OnIdiom.Tablet>60</OnIdiom.Tablet>
            <OnIdiom.Desktop>40</OnIdiom.Desktop>
        </OnIdiom>
    </Image.HeightRequest>
</Image>

<renderer:CustomEditor
    Grid.Row="0" 
    Grid.Column="1"
    x:Name="commentbody_entry"
    Placeholder="Add your comment here"
    BackgroundColor="#f1f1f1"
    PlaceholderColor = "#a39ea1"
    TextColor = "#54493b"
    TextChanged="commentbody_entry_TextChanged"
    Style="{StaticResource AddCommentEditorStyle}">
    <renderer:CustomEditor.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double">
            <OnIdiom.Phone>60</OnIdiom.Phone>
            <OnIdiom.Tablet>90</OnIdiom.Tablet>
            <OnIdiom.Desktop>60</OnIdiom.Desktop>
        </OnIdiom>
    </renderer:CustomEditor.HeightRequest>
</renderer:CustomEditor>

<StackLayout 
    x:Name="sendcomment_stack"
    IsEnabled="False"
    VerticalOptions="CenterAndExpand"
    Grid.Row="0" 
    Grid.Column="2">
    <Image 
        x:Name="sendcomment_image"
        Source="ic_gray_sendcomment_xx.png">
        <Image.WidthRequest>
            <OnIdiom x:TypeArguments="x:Double">
                <OnIdiom.Phone>40</OnIdiom.Phone>
                <OnIdiom.Tablet>60</OnIdiom.Tablet>
                <OnIdiom.Desktop>40</OnIdiom.Desktop>
            </OnIdiom>
        </Image.WidthRequest>
        <Image.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double">
                <OnIdiom.Phone>40</OnIdiom.Phone>
                <OnIdiom.Tablet>60</OnIdiom.Tablet>
                <OnIdiom.Desktop>40</OnIdiom.Desktop>
            </OnIdiom>
        </Image.HeightRequest>
    </Image>
    <StackLayout.GestureRecognizers>
        <TapGestureRecognizer
            Tapped="Send_Comment"
            NumberOfTapsRequired="1">
        </TapGestureRecognizer>
    </StackLayout.GestureRecognizers>
</StackLayout>
</Grid>

My CustomEditorRenderer in IOS:

public class CustomEditorRenderer : EditorRenderer
{
    public CustomEditorRenderer()
    {
        UIKeyboard.Notifications.ObserveWillShow((sender, args) =>
        {
            if (Element != null)
            {
                Element.Margin = new Thickness(0, 0, 0, args.FrameEnd.Height); //push the entry up to keyboard height when keyboard is activated
            }
        });

        UIKeyboard.Notifications.ObserveWillHide((sender, args) =>
        {
            if (Element != null)
            {
                Element.Margin = new Thickness(0); //set the margins to zero when keyboard is dismissed
            }
        });
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.Layer.CornerRadius = 10;
            Control.TextColor = UIColor.Black;
        }
    }
}

Is there any way to pull up the send and attachment icons when the keyboard appears?

Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105

1 Answers1

0

When you use Grid, the layout will not move up when you open the keyboard. You just need to put your Grid in the ScrollView of ContentPage. If you use ScrollView, you need to note that the ObserveWillShow and ObserveWillHide methods in your CustomEditorRenderer are not needed.

Like this:

 <ScrollView>
      <StackLayout>
            <Grid Margin="20,600,20,20">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

 
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

               <Image Grid.Row="0"
               Grid.Column="0"
               VerticalOptions="CenterAndExpand"
               Source="Test.png">
               </Image>

               <Editor
                 WidthRequest="100"
                 Grid.Row="0"
                 Grid.Column="1"
                 Placeholder="test"
                 BackgroundColor="#f1f1f1"
                 PlaceholderColor = "#a39ea1"
                 TextColor = "#54493b"/>
               
               <Image Grid.Row="0"
               Grid.Column="2"
               VerticalOptions="CenterAndExpand"
               Source="Test.png">
               </Image>
             </Grid>
          </StackLayout>
        </ScrollView>
Zack
  • 1,255
  • 1
  • 2
  • 5
  • Tried this solution but it is not working. I need an output like this https://i.stack.imgur.com/CC9pT.jpg – Sreejith Sree Mar 02 '23 at 11:48
  • When I try this solution UI is like this https://i.stack.imgur.com/sTtvs.png – Sreejith Sree Mar 02 '23 at 11:51
  • It is not moving to top of keyboard when the keyboard appeares – Sreejith Sree Mar 02 '23 at 11:51
  • When I run my code on the iOS emulator, it works normally. According to the screenshot you provided, is the editor and image not moved up? Did you unregister the ObserveWillShow and ObserveWillHide methods in your renderer when you try to nest the Scollview. – Zack Mar 03 '23 at 08:38
  • Here is the sample project, could you please check: https://drive.google.com/file/d/1lDKJ4zgmSalFbdhcrlL_iQUqn7WDslr4/view?usp=share_link Also I am adding the real content page having all components: https://drive.google.com/file/d/1VVsqsWHjsXhwIlXWHjFWrn9upMR_aXIm/view?usp=share_link – Sreejith Sree Mar 09 '23 at 12:16
  • I tested your code, the layout looks a bit strange, but the desired effect can be achieved after adding ScrollView, you can try to create a new project and try the code in my answer to see if it is the effect you want. – Zack Mar 10 '23 at 09:11
  • I tried with scrollview, it is not working – Sreejith Sree Mar 10 '23 at 12:04
  • I can't reproduce your problem, which version are you testing, I'm using the 16.2 emulator for testing – Zack Mar 13 '23 at 09:17
  • Could you please share a working sample that you tested, on my side still i have same issue – Sreejith Sree Mar 17 '23 at 11:01
  • Saw you asked the same question on Q&A([Xamarin Forms: Spacing issue between keyboard and the bottom layout in chat page](https://learn.microsoft.com/en-us/answers/questions/1185481/xamarin-forms-spacing-issue-between-keyboard-and-t?orderby=helpful)), let's focus on that one – Zack Mar 20 '23 at 08:22
  • Initially I was testing on 15.4 simulator, now I updated the ios version to 16.2 and tested the same feature. Still same issue, the editor is not visible on the UI when the keyboard appears. – Sreejith Sree Mar 30 '23 at 14:33