This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 459
TouchEffect (Press & Hover visual handling) + LongPress #566
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48e0a5a
Added TouchEffect
AndreiMisiukevich bac611b
Removed useless access modifiers
AndreiMisiukevich 2ebedc2
Cleaned code
AndreiMisiukevich f0d9011
Added visual element extension
AndreiMisiukevich 9b56987
Updated element cast
AndreiMisiukevich 56fd4f0
Replaced hardcode by string constants
AndreiMisiukevich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+71.7 KB
src/CommunityToolkit/Xamarin.CommunityToolkit.Sample/Images/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+68.8 KB
src/CommunityToolkit/Xamarin.CommunityToolkit.Sample/Images/button_pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions
94
src/CommunityToolkit/Xamarin.CommunityToolkit.Sample/Pages/Effects/TouchEffectPage.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
src/CommunityToolkit/Xamarin.CommunityToolkit.Sample/Pages/Effects/TouchEffectPage.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/Enums/HoverState.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Xamarin.CommunityToolkit.Effects | ||
{ | ||
public enum HoverState | ||
{ | ||
Normal, | ||
Hovered | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/Enums/HoverStatus.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Xamarin.CommunityToolkit.Effects | ||
{ | ||
public enum HoverStatus | ||
{ | ||
Entered, | ||
Exited | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...nityToolkit/Xamarin.CommunityToolkit/Effects/Touch/Enums/TouchInteractionStatus.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Xamarin.CommunityToolkit.Effects | ||
{ | ||
public enum TouchInteractionStatus | ||
{ | ||
Started, | ||
Completed | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/Enums/TouchState.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Xamarin.CommunityToolkit.Effects | ||
{ | ||
public enum TouchState | ||
{ | ||
Normal, | ||
Pressed | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/Enums/TouchStatus.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Xamarin.CommunityToolkit.Effects | ||
{ | ||
public enum TouchStatus | ||
{ | ||
Started, | ||
Completed, | ||
Canceled | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...kit/Xamarin.CommunityToolkit/Effects/Touch/EventArgs/HoverStateChangedEventArgs.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...it/Xamarin.CommunityToolkit/Effects/Touch/EventArgs/HoverStatusChangedEventArgs.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...oolkit/Xamarin.CommunityToolkit/Effects/Touch/EventArgs/TouchCompletedEventArgs.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...CommunityToolkit/Effects/Touch/EventArgs/TouchInteractionStatusChangedEventArgs.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...kit/Xamarin.CommunityToolkit/Effects/Touch/EventArgs/TouchStateChangedEventArgs.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...it/Xamarin.CommunityToolkit/Effects/Touch/EventArgs/TouchStatusChangedEventArgs.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.