CommunityToolkit/Maui.Markup

[Proposal] Add TypedBindings to GesturesExtensions

brminnick opened this issue · 1 comments

Feature name

Add TypedBindings to GesturesExtensions

Progress tracker

  • Android Implementation
  • iOS Implementation
  • MacCatalyst Implementation
  • Windows Implementation
  • Tizen Implementation
  • Unit Tests
  • Samples
  • Documentation: MicrosoftDocs/CommunityToolkit#272

Summary

This proposal augments GesturesExtensions by adding the following APIs that support Typed Bindings

  • .BindClickGesture()
  • .BindSwipeGesture()
  • .BindTapGesture()

Motivation

This is a continuation of #155 adding the ability to use Typed Bindings in CommunityToolkit.Maui.Markup

Detailed Design

public static TGestureElement BindClickGesture<TGestureElement, TCommandBindingContext, TParameterBindingContext,
  TParameterSource>(
  this TGestureElement gestureElement,
  Expression<Func<TCommandBindingContext, ICommand>> getter,
  Action<TCommandBindingContext, ICommand>? setter = null,
  TCommandBindingContext? source = default,
  BindingMode commandBindingMode = BindingMode.Default,
  Expression<Func<TParameterBindingContext, TParameterSource>>? parameterGetter = null,
  Action<TParameterBindingContext, TParameterSource>? parameterSetter = null,
  BindingMode parameterBindingMode = BindingMode.Default,
  TParameterBindingContext? parameterSource = default,
  int? numberOfClicksRequired = null) where TGestureElement : BindableObject, IGestureRecognizers;

public static TGestureElement BindClickGesture<TGestureElement, TCommandBindingContext, TParameterBindingContext,
  TParameterSource>(
  this TGestureElement gestureElement,
  Func<TCommandBindingContext, ICommand>> getter,
  (Func<TCommandBindingContext, object?>, string)[] handlers,
  Action<TCommandBindingContext, ICommand>? setter = null,
  TCommandBindingContext? source = default,
  BindingMode commandBindingMode = BindingMode.Default,
  Expression<Func<TParameterBindingContext, TParameterSource>>? parameterGetter = null,
  Action<TParameterBindingContext, TParameterSource>? parameterSetter = null,
  BindingMode parameterBindingMode = BindingMode.Default,
  TParameterBindingContext? parameterSource = default,
  int? numberOfClicksRequired = null) where TGestureElement : BindableObject, IGestureRecognizers;

public static TGestureElement BindSwipeGesture<TGestureElement, TCommandBindingContext, TParameterBindingContext,
  TParameterSource>(
  this TGestureElement gestureElement,
  Expression<Func<TCommandBindingContext, ICommand>> getter,
  Action<TCommandBindingContext, ICommand>? setter = null,
  TCommandBindingContext? source = default,
  BindingMode commandBindingMode = BindingMode.Default,
  Expression<Func<TParameterBindingContext, TParameterSource>>? parameterGetter = null,
  Action<TParameterBindingContext, TParameterSource>? parameterSetter = null,
  BindingMode parameterBindingMode = BindingMode.Default,
  TParameterBindingContext? parameterSource = default,
  int? numberOfClicksRequired = null) where TGestureElement : BindableObject, IGestureRecognizers;

public static TGestureElement BindSwipeGesture<TGestureElement, TCommandBindingContext, TParameterBindingContext,
  TParameterSource>(
  this TGestureElement gestureElement,
  Func<TCommandBindingContext, ICommand>> getter,
  (Func<TCommandBindingContext, object?>, string)[] handlers,
  Action<TCommandBindingContext, ICommand>? setter = null,
  TCommandBindingContext? source = default,
  BindingMode commandBindingMode = BindingMode.Default,
  Expression<Func<TParameterBindingContext, TParameterSource>>? parameterGetter = null,
  Action<TParameterBindingContext, TParameterSource>? parameterSetter = null,
  BindingMode parameterBindingMode = BindingMode.Default,
  TParameterBindingContext? parameterSource = default,
  int? numberOfClicksRequired = null) where TGestureElement : BindableObject, IGestureRecognizers;

public static TGestureElement BindTapGesture<TGestureElement, TCommandBindingContext, TParameterBindingContext,
  TParameterSource>(
  this TGestureElement gestureElement,
  Expression<Func<TCommandBindingContext, ICommand>> getter,
  Action<TCommandBindingContext, ICommand>? setter = null,
  TCommandBindingContext? source = default,
  BindingMode commandBindingMode = BindingMode.Default,
  Expression<Func<TParameterBindingContext, TParameterSource>>? parameterGetter = null,
  Action<TParameterBindingContext, TParameterSource>? parameterSetter = null,
  BindingMode parameterBindingMode = BindingMode.Default,
  TParameterBindingContext? parameterSource = default,
  int? numberOfClicksRequired = null) where TGestureElement : BindableObject, IGestureRecognizers;

public static TGestureElement BindTapGesture<TGestureElement, TCommandBindingContext, TParameterBindingContext,
  TParameterSource>(
  this TGestureElement gestureElement,
  Func<TCommandBindingContext, ICommand>> getter,
  (Func<TCommandBindingContext, object?>, string)[] handlers,
  Action<TCommandBindingContext, ICommand>? setter = null,
  TCommandBindingContext? source = default,
  BindingMode commandBindingMode = BindingMode.Default,
  Expression<Func<TParameterBindingContext, TParameterSource>>? parameterGetter = null,
  Action<TParameterBindingContext, TParameterSource>? parameterSetter = null,
  BindingMode parameterBindingMode = BindingMode.Default,
  TParameterBindingContext? parameterSource = default,
  int? numberOfClicksRequired = null) where TGestureElement : BindableObject, IGestureRecognizers;

Usage Syntax

new Label().BindTapGesture(static (ViewModel vm) => vm.TapGestureCommand, mode: BindingMode.OneWay)

Drawbacks

None

Alternatives

The following APIs currently exist without support for Typed Bindings (require reflection):

  • BindClickGesture
  • BindSwipeGesture
  • BindTapGesture

Unresolved Questions

None

Reopening Proposal.

Only Proposals moved to the Closed Project Column and Completed Project Column can be closed.