Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brminnick/EntryCustomReturnPlugin

Xamarin.Forms Plugin to customize the Xamarin.Forms.Entry Keyboard Return Button
https://github.com/brminnick/EntryCustomReturnPlugin

nuget xamarin xamarin-android xamarin-forms xamarin-ios xamarin-plugin

Last synced: 3 months ago
JSON representation

Xamarin.Forms Plugin to customize the Xamarin.Forms.Entry Keyboard Return Button

Awesome Lists containing this project

README

        

# Custom `Xamarin.Forms.Entry` Keyboard Return Button

[![NuGet](https://buildstats.info/nuget/Xam.Plugins.Forms.CustomReturnEntry)](https://www.nuget.org/packages/Xam.Plugins.Forms.CustomReturnEntry/)

This SDK was [officially merged into Xamarin.Forms v3.1.0](https://devblogs.microsoft.com/xamarin/xamarin-forms-3-1-improvments?WT.mc_id=entrycustomreturnplugin-github-bramin).

Because this SDK supports Xamarin.Forms v2.5.0.280555, I will continue to maintain it for teams who have not yet upgraded to Xamarin.Forms v3.1.0 or higher.

For developers using Xamarin.Forms 3.1.0 or higher, I recommend removing this NuGet package from your `csproj` and using the APIs included in Xamarin.Forms: `Xamarin.Forms.Entry.ReturnType` & `Xamarin.Forms.Entry.ReturnCommand`.

## ReturnType

| ReturnType | Android | iOS | UWP |
|--------------------|---------|-----|-----|
| **Default** |![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/Android/DefaultButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/iOS/DefaultButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/UWP/DefaultButton.png)|
| **Done** |![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/Android/DoneButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/iOS/DoneButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/UWP/DefaultButton.png)|
| **Go** |![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/Android/GoButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/iOS/GoButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/UWP/DefaultButton.png)|
| **Next** |![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/Android/NextButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/iOS/NextButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/UWP/DefaultButton.png)|
| **Search** |![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/Android/SearchButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/iOS/SearchButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/UWP/SearchButton.png)|
| **Send** |![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/Android/SendButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/iOS/SendButton.png)|![](https://github.com/brminnick/Videos/blob/master/EntryCustomReturnPlugin/Return%20Button%20Images/UWP/DefaultButton.png)|

**Platform Support**

|Platform|Supported|Version|
| ------------------- | :-----------: | :------------------: |
|Xamarin.iOS|Yes|iOS 8+|
|Xamarin.iOS Unified|Yes|iOS 8+|
|Xamarin.Android|Yes|API 15+|
|Windows 10 UWP|Yes|10+|
|Windows Phone Silverlight|No||
|Windows Phone RT|No||
|Windows Store RT|No||
|Xamarin.Mac|No||

This plugin can be consumed as a [`CustomRenderer Control`](./README.md#usage-in-xamarinforms-project-as-a-custom-control) or as an [`Effect`](./README.md#usage-in-xamarinforms-project-as-an-effect).

# Setup

* Available on NuGet: https://www.nuget.org/packages/Xam.Plugins.Forms.CustomReturnEntry/ [![NuGet](https://buildstats.info/nuget/Xam.Plugins.Forms.CustomReturnEntry)](https://www.nuget.org/packages/Xam.Plugins.Forms.CustomReturnEntry/)
* Install into your PCL project and Client projects.

## iOS

In the `FinishedLaunching` method of `AppDelegate.cs`, add `CustomReturnEntryRenderer.Init();`:

```csharp
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
...

global::Xamarin.Forms.Forms.Init();

EntryCustomReturn.Forms.Plugin.iOS.CustomReturnEntryRenderer.Init();

...
}
}
```

**Note:** You must call `EntryCustomReturn.Forms.Plugin.iOS.CustomReturnEntryRenderer.Init();` *after* you call `global::Xamarin.Forms.Forms.Init();`

## Android

In the `Oncreated` method of `MainActivity.cs`, add `CustomReturnEntryRenderer.Init();`:

```csharp
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
...

global::Xamarin.Forms.Forms.Init(this, bundle);

EntryCustomReturn.Forms.Plugin.Android.CustomReturnEntryRenderer.Init();

...
}
}
```

**Note:** You must call `EntryCustomReturn.Forms.Plugin.Android.CustomReturnEntryRenderer.Init();` *after* you call `global::Xamarin.Forms.Forms.Init(this, bundle);`

## UWP

In the `OnLaunched` method of `App.xaml.cs`, add `CustomReturnEntryRenderer.Init();`:

```csharp
public partial class App : Application
{
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
...

global::Xamarin.Forms.Forms.Init(e);

EntryCustomReturn.Forms.Plugin.UWP.CustomReturnEntryRenderer.Init();

...
}
}
```

**Note:** You must call `EntryCustomReturn.Forms.Plugin.UWP.CustomReturnEntryRenderer.Init();` *after* you call `global::Xamarin.Forms.Forms.Init(e);`

# Usage in Xamarin.Forms Project as a Custom Control

This plugin can be consumed as a [`CustomRenderer Control`](./README.md#usage-in-xamarinforms-project-as-a-custom-control) or as an [`Effect`](./README.md#usage-in-xamarinforms-project-as-an-effect).

## 1. Set the `ReturnType` Property

The `ReturnType` property is an enum containing 6 different types: Default, Go, Next, Done, Send, Search.

#### Coded UI

```csharp
var goReturnTypeCustomEntry = new CustomReturnEntry
{
ReturnType = EntryCustomReturn.Forms.Plugin.Abstractions.ReturnType.Go
};
```

#### XAML UI

```xml

```

### Bindable Property

`ReturnType` can also be used as a `Bindable Property` to bind to a ViewModel

#### Coded UI

```csharp
var viewModel = new MyViewModel();
BindingContext = viewModel;

var customReturnEntry = new CustomReturnEntry();
customReturnEntry.SetBinding(CustomReturnEntry.ReturnTypeProperty, nameof(MyViewModel.EntryReturnType));
```

#### XAML UI

```xml

```

## 2. Set the `ReturnCommand` Command

`ReturnCommand` will fire when the user finalizes the text in an entry with the return key.

#### Coded UI

```csharp
goReturnTypeCustomEntry.ReturnCommand = new Command(() => Navigation.PushAsync(new ContentPage()));
```

#### XAML UI
Use the [Coded UI example above](./README.md#coded-ui-2) to initialize a `Command` in the XAML Code Behind

### Bindable Property

`ReturnCommand` can also be used as a `Bindable Property` to bind to a ViewModel

#### Coded UI

```csharp
var viewModel = new MyViewModel();
BindingContext = viewModel;

var customReturnEntry = new CustomReturnEntry();
customReturnEntry.SetBinding(CustomReturnEntry.ReturnCommandProperty nameof(MyViewModel.EntryReturnCommand));
```

#### XAML UI

```xml

```

### 3. Set the `ReturnCommandParameter` Property

The `ReturnCommandParameter` property is an object that can be passed to the `ReturnCommand` property.

#### Coded UI

```csharp
goReturnTypeCustomEntry.ReturnCommand = new Command(async title => await DisplayAlert(title, "", "Ok"));
goReturnTypeCustomEntry.ReturnCommandParameter = "Return Button Tapped";
```

#### XAML UI

```xml

```

### Bindable Property

`ReturnCommandParameter` can also be used as a `Bindable Property` to bind to a ViewModel

#### Coded UI

```csharp
var viewModel = new MyViewModel();
BindingContext = viewModel;

var customReturnEntry = new CustomReturnEntry();
customReturnEntry.SetBinding(CustomReturnEntry.ReturnCommandParameterProperty, nameof(MyViewModel.EntryReturnCommandParameter));
```

#### XAML UI

```xml

```

# Usage in Xamarin.Forms Project as an Effect

This plugin can be consumed as a [`CustomRenderer Control`](./README.md#usage-in-xamarinforms-project-as-a-custom-control) or as an [`Effect`](./README.md#usage-in-xamarinforms-project-as-an-effect).

## 1. Set the `ReturnType` Property

The `ReturnType` property is an enum containing 6 different types: Default, Go, Next, Done, Send, Search.

#### Coded UI

```csharp
var goReturnTypeEntry = new Entry()
CustomReturnEffect.SetReturnType(goReturnTypeEntry, EntryCustomReturn.Forms.Plugin.Abstractions.ReturnType.Go);
```

#### XAML UI

```xml

```

### Bindable Property

`ReturnType` can also be used as a `Bindable Property` to bind to a ViewModel

#### Coded UI

```csharp
var viewModel = new MyViewModel();
BindingContext = viewModel;

var customReturnEntry = new Entry();
customReturnEntry.SetBinding(CustomReturnEffect.ReturnTypeProperty, nameof(MyViewModel.EntryReturnType));
```

#### XAML UI

```xml

```

### 2. Set the `ReturnCommand` Command

`ReturnCommand` will fire when the user finalizes the text in an entry with the return key.

#### Coded UI

```csharp
var goReturnTypeEntry = new Entry()
CustomReturnEffect.SetReturnCommand(goReturnTypeEntry, new Command(() => Navigation.PushAsync(new ContentPage()));
```

#### XAML UI

Use the [Coded UI example above](./README.md#coded-ui-8) to initialize a `Command` in the XAML Code Behind

### Bindable Property

`ReturnCommand` can also be used as a `Bindable Property` to bind to a ViewModel

#### Coded UI

```csharp
var viewModel = new MyViewModel();
BindingContext = viewModel;

var customReturnEntry = new Entry();
customReturnEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(MyViewModel.EntryReturnCommand));
```

#### XAML UI

```xml

```

### 3. Set the `ReturnCommandParameter` Property

The `ReturnCommandParameter` property is an object that can be passed to the `ReturnCommand` property.

#### Coded UI

```csharp
var goReturnTypeEntry = new Entry()
CustomReturnEffect.SetReturnCommand(goReturnTypeEntry, new Command(async title => await DisplayAlert(title, "", "Ok")));
CustomReturnEffect.SetReturnCommandParameter(goReturnTypeEntry, "Return Button Tapped");
```

#### XAML UI

```xml

```

### Bindable Property

`ReturnCommandParameter` can also be used as a `Bindable Property` to bind to a ViewModel

#### Coded UI

```csharp
var viewModel = new MyViewModel();
BindingContext = viewModel;

var customReturnEntry = new Entry();
customReturnEntry.SetBinding(CustomReturnEffect.ReturnCommandParameterProperty, nameof(MyViewModel.EntryReturnCommandParameter));
```

#### XAML UI

```xml

```