Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

TouchEffect (Press & Hover visual handling) + LongPress #566

Merged
merged 6 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Effects.TouchEffectPage"
x:Name="Page">

<pages:BasePage.Resources>
<Style x:Key="GridRowContentStyle" TargetType="StackLayout">
<Setter Property="HorizontalOptions" Value="CenterAndExpand" />
<Setter Property="VerticalOptions" Value="CenterAndExpand" />
<Setter Property="Spacing" Value="10" />
</Style>
</pages:BasePage.Resources>

<Grid RowDefinitions="Auto,*,*,*,*" Padding="{StaticResource ContentPadding}">

<Label Grid.Row="0"
HorizontalOptions="CenterAndExpand"
FontSize="Title"
TextColor="Black"
Text="{Binding Count, StringFormat='Touches: {0}', Source={x:Reference Page}}" />

<StackLayout Grid.Row="1"
Style="{StaticResource GridRowContentStyle}">
<Label Text="Image | Toggle | Hover" />
<Image xct:TouchEffect.NormalBackgroundImageSource="{xct:ImageResource Id=Xamarin.CommunityToolkit.Sample.Images.button.png}"
xct:TouchEffect.PressedBackgroundImageSource="{xct:ImageResource Id=Xamarin.CommunityToolkit.Sample.Images.button_pressed.png}"
xct:TouchEffect.HoveredOpacity="0.8"
xct:TouchEffect.IsToggled="False"
xct:TouchEffect.Command="{Binding Command, Source={x:Reference Page}}"/>

</StackLayout>

<StackLayout Grid.Row="2"
Style="{StaticResource GridRowContentStyle}">

<Label Text="Scale | Fade | Animated" />

<StackLayout Orientation="Horizontal"
HorizontalOptions="CenterAndExpand"
xct:TouchEffect.AnimationDuration="250"
xct:TouchEffect.AnimationEasing="{x:Static Easing.CubicInOut}"
xct:TouchEffect.PressedScale="0.8"
xct:TouchEffect.PressedOpacity="0.6"
xct:TouchEffect.Command="{Binding Command, Source={x:Reference Page}}">
<BoxView Color="Gold" />
<Label Text="The entire layout receives touches" />
<BoxView Color="Gold"/>
</StackLayout>
</StackLayout>

<StackLayout Grid.Row="3"
Style="{StaticResource GridRowContentStyle}">

<Label Text="Native | Long Press" />

<StackLayout Orientation="Horizontal"
HorizontalOptions="CenterAndExpand"
BackgroundColor="Black"
Padding="20"
xct:TouchEffect.HoveredScale="1.2"
xct:TouchEffect.NativeAnimation="True"
xct:TouchEffect.LongPressCommand="{Binding LongPressCommand, Source={x:Reference Page}}"
xct:TouchEffect.Command="{Binding Command, Source={x:Reference Page}}">
<Label Text="TITLE"
TextColor="White"
FontSize="Large"/>
</StackLayout>
</StackLayout>

<StackLayout Grid.Row="4"
Style="{StaticResource GridRowContentStyle}">

<Label Text="Color | Rotation | Pulse | Animated" />

<StackLayout Orientation="Horizontal"
HorizontalOptions="CenterAndExpand"
Padding="20"
xct:TouchEffect.AnimationDuration="500"
xct:TouchEffect.PulseCount="2"
xct:TouchEffect.NormalBackgroundColor="Gold"
xct:TouchEffect.PressedBackgroundColor="Orange"
xct:TouchEffect.PressedRotation="15"
xct:TouchEffect.Command="{Binding Command, Source={x:Reference Page}}">
<Label Text="TITLE"
TextColor="White"
FontSize="Large"/>
</StackLayout>
</StackLayout>

</Grid>
</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Windows.Input;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Xamarin.CommunityToolkit.Sample.Pages.Effects
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TouchEffectPage
{
public TouchEffectPage()
{
Command = new Command(() =>
{
Count++;
OnPropertyChanged(nameof(Count));
});
LongPressCommand = new Command(() => Application.Current.MainPage.DisplayAlert("LongPressCommand", "LongPressCommand was executed.", "OK"));
InitializeComponent();

}

public ICommand Command { get; }

public ICommand LongPressCommand { get; }

public int Count { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class EffectsGalleryViewModel : BaseGalleryViewModel
nameof(IconTintColorEffect),
"With the IconTintColorEffect you set the tint color of an Image or ImageButton."
),

new SectionModel(
typeof(TouchEffectPage),
nameof(TouchEffect),
"The TouchEffect is an effect that allows changing the view's appearance depending on the touch state (normal, pressed, hovered). Also, it allows to handle long presses."
),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Compile Remove="resources\**" />
<EmbeddedResource Remove="resources\**" />
<None Remove="resources\**" />
<EmbeddedResource Include="Images\**" />
<EmbeddedResource Update="Resx\AppResources.es.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>AppResources.es.Designer.cs</LastGenOutput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ sealed class EffectIds
/// Effect Id for <see cref="VisualFeedbackEffect"/>
/// </summary>
public static string VisualFeedback => $"{effectResolutionGroupName}.{nameof(VisualFeedbackEffect)}";

/// <summary>
/// Effect Id for <see cref="TouchEffect"/>
/// </summary>
public static string TouchEffect => $"{effectResolutionGroupName}.{nameof(TouchEffect)}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Xamarin.CommunityToolkit.Effects
{
public enum HoverState
{
Normal,
Hovered
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Xamarin.CommunityToolkit.Effects
{
public enum HoverStatus
{
Entered,
Exited
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Xamarin.CommunityToolkit.Effects
{
public enum TouchInteractionStatus
{
Started,
Completed
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Xamarin.CommunityToolkit.Effects
{
public enum TouchState
{
Normal,
Pressed
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Xamarin.CommunityToolkit.Effects
{
public enum TouchStatus
{
Started,
Completed,
AndreiMisiukevich marked this conversation as resolved.
Show resolved Hide resolved
Canceled
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class HoverStateChangedEventArgs : EventArgs
{
internal HoverStateChangedEventArgs(HoverState state)
=> State = state;

public HoverState State { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class HoverStatusChangedEventArgs : EventArgs
{
internal HoverStatusChangedEventArgs(HoverStatus status)
=> Status = status;

public HoverStatus Status { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class TouchCompletedEventArgs : EventArgs
{
internal TouchCompletedEventArgs(object parameter)
=> Parameter = parameter;

public object Parameter { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class TouchInteractionStatusChangedEventArgs : EventArgs
{
internal TouchInteractionStatusChangedEventArgs(TouchInteractionStatus touchInteractionStatus)
=> TouchInteractionStatus = touchInteractionStatus;

public TouchInteractionStatus TouchInteractionStatus { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class TouchStateChangedEventArgs : EventArgs
{
internal TouchStateChangedEventArgs(TouchState state)
=> State = state;

public TouchState State { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class TouchStatusChangedEventArgs : EventArgs
{
internal TouchStatusChangedEventArgs(TouchStatus status)
=> Status = status;

public TouchStatus Status { get; }
}
}
Loading