Search code examples
iosxamarin.formsreturn-type

Xamarin forms: Search arrow is not available on ios soft keyboard


I have added the following properties to Entry for send option in the soft keyboard.

ReturnType="Send"
ReturnCommand="{Binding SendFromKeyboard}"

On Android, the send arrow is showing on the keyboard. But on ios, no Send arrow is available on the keyboard. But if the ReturnType is Search the search option is available for both android and ios. Is there any additional settings for send option in ios keyboard?

Complete Xaml Code:

<Frame 
     Padding="8,0,8,0"
     Margin="10,5,0,10"
     BackgroundColor="White"
     HorizontalOptions="CenterAndExpand"
     VerticalOptions="CenterAndExpand"
     CornerRadius="10">

     <Entry 
        HorizontalOptions="CenterAndExpand"
        x:Name="amount_entry"
        PlaceholderColor="#c3c3c3"
        VerticalOptions="CenterAndExpand"
        HorizontalTextAlignment="Center"
        BackgroundColor="White"
        FontFamily="Bold"
        ReturnType="Send"
        ReturnCommand="{Binding AddPointsFromKeyboard}"
        Keyboard="Numeric"
        TextColor="#464646"
        TextChanged="Calculate_Points"
        Placeholder="Enter Amount">
     </Entry>
</Frame>

Update for @MatthewLC

In PCL:

using Xamarin.Forms;

namespace MyApp
{
    public class PointsEntry : Entry
    {
    }
}

In IOS:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business_App.iOS;
using Business_App.Renderer;
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(PointsEntry), typeof(PointsEntryRenderer))]
namespace Business_App.iOS
{
    public class PointsEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null && this.Element.Keyboard == Keyboard.Numeric)
            {
                this.AddDoneButton();
            }
        }

        protected void AddDoneButton()
        {
            var toolbar = new UIToolbar(new CGRect(0.0f, 0.0f, 50.0f, 44.0f));

            var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate
            {
                this.Control.ResignFirstResponder();
                var baseEntry = this.Element.GetType();
                ((IEntryController)Element).SendCompleted();
            });

            toolbar.Items = new UIBarButtonItem[] {
                new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace),
                doneButton
            };
            this.Control.InputAccessoryView = toolbar;
         }
    }
 }

On XAML:

<local2:PointsEntry 
    HorizontalOptions="CenterAndExpand"
    x:Name="amount_entry"
    PlaceholderColor="#c3c3c3"
    VerticalOptions="CenterAndExpand"
    HorizontalTextAlignment="Center"
    BackgroundColor="White"
    FontFamily="Bold"
    ReturnType="Send"
    ReturnCommand="{Binding AddPointsFromKeyboard}"
    Keyboard="Numeric"
    TextColor="#464646"
    TextChanged="Calculate_Points"
    Placeholder="Enter Amount">
 </local2:PointsEntry>

After adding the customrenderer also there is no send text on the soft keyboard. If I remove the keyboard property, then send text is showing on the soft keyboard. I am looking for both numeric keyboard and send text on soft keyboard together.


Solution

  • You can use Custom Renderer

    using App1.iOS;
    using Foundation;
    using UIKit;
    
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly:ExportRenderer(typeof(Entry),typeof(MyEntryRenderer))]
    namespace xxx.iOS
    {
        public class MyEntryRenderer:EntryRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
    
                if(Control!=null)
                {
                    Control.ReturnKeyType = UIReturnKeyType.Send;
                }
            }
    
        }
    }
    

    Update

    Because you set the keyboard type as Numeric .So in iOS it will never show the Sendbutton .

    If you do want to input number , you can check if the value is a number in command .