Skip to content

Commit

Permalink
feat(swipecontrol): Implement SwipeItem
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Apr 19, 2021
1 parent dcdd0fc commit cd6c42b
Show file tree
Hide file tree
Showing 5 changed files with 461 additions and 391 deletions.
32 changes: 16 additions & 16 deletions src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/SwipeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class SwipeItem : global::Windows.UI.Xaml.DependencyObject
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public string Text
{
Expand All @@ -21,7 +21,7 @@ public string Text
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Controls.IconSource IconSource
{
Expand All @@ -35,7 +35,7 @@ public string Text
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Media.Brush Foreground
{
Expand All @@ -49,7 +49,7 @@ public string Text
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public object CommandParameter
{
Expand All @@ -63,7 +63,7 @@ public object CommandParameter
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::System.Windows.Input.ICommand Command
{
Expand All @@ -77,7 +77,7 @@ public object CommandParameter
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Controls.SwipeBehaviorOnInvoked BehaviorOnInvoked
{
Expand All @@ -91,7 +91,7 @@ public object CommandParameter
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Media.Brush Background
{
Expand All @@ -105,55 +105,55 @@ public object CommandParameter
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty BackgroundProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Background), typeof(global::Windows.UI.Xaml.Media.Brush),
typeof(global::Windows.UI.Xaml.Controls.SwipeItem),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Media.Brush)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty BehaviorOnInvokedProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(BehaviorOnInvoked), typeof(global::Windows.UI.Xaml.Controls.SwipeBehaviorOnInvoked),
typeof(global::Windows.UI.Xaml.Controls.SwipeItem),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.SwipeBehaviorOnInvoked)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty CommandParameterProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(CommandParameter), typeof(object),
typeof(global::Windows.UI.Xaml.Controls.SwipeItem),
new FrameworkPropertyMetadata(default(object)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty CommandProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Command), typeof(global::System.Windows.Input.ICommand),
typeof(global::Windows.UI.Xaml.Controls.SwipeItem),
new FrameworkPropertyMetadata(default(global::System.Windows.Input.ICommand)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty ForegroundProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Foreground), typeof(global::Windows.UI.Xaml.Media.Brush),
typeof(global::Windows.UI.Xaml.Controls.SwipeItem),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Media.Brush)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty IconSourceProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(IconSource), typeof(global::Windows.UI.Xaml.Controls.IconSource),
typeof(global::Windows.UI.Xaml.Controls.SwipeItem),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.IconSource)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty TextProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
Expand Down Expand Up @@ -192,7 +192,7 @@ public SwipeItem() : base()
// Forced skipping of method Windows.UI.Xaml.Controls.SwipeItem.CommandProperty.get
// Forced skipping of method Windows.UI.Xaml.Controls.SwipeItem.CommandParameterProperty.get
// Forced skipping of method Windows.UI.Xaml.Controls.SwipeItem.BehaviorOnInvokedProperty.get
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public event global::Windows.Foundation.TypedEventHandler<global::Windows.UI.Xaml.Controls.SwipeItem, global::Windows.UI.Xaml.Controls.SwipeItemInvokedEventArgs> Invoked
{
Expand Down
123 changes: 60 additions & 63 deletions src/Uno.UI/UI/Xaml/Controls/SwipeControl/SwipeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,135 +4,132 @@

// IconSource is implemented in WUX in the OS repo, so we don't need to
// include IconSource.h on that side.
using System;
using System.Windows.Input;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;

namespace Windows.UI.Xaml.Controls
{
public partial class SwipeItem
public partial class SwipeItem : DependencyObject
{
static double s_swipeItemWidth = 68.0;
static double s_swipeItemHeight = 60.0;

SwipeItem()
public SwipeItem()
{
__RP_Marker_ClassById(RuntimeProfiler.ProfId_SwipeItem);
}

#pragma endregion


void InvokeSwipe(winrt.SwipeControl& swipeControl)
internal void InvokeSwipe(SwipeControl swipeControl)
{
var eventArgs = winrt.new SwipeItemInvokedEventArgs();
eventArgs.SwipeControl(swipeControl);
m_invokedEventSource(this, eventArgs);
var eventArgs = new SwipeItemInvokedEventArgs(swipeControl);

if (s_CommandProperty)
m_invokedEventSource?.Invoke(this, eventArgs);

if (CommandProperty is {})
{
var command = Command().as<winrt.ICommand > ();
var param = CommandParameter();
var command = Command as ICommand;
var param = CommandParameter;

if (command && command.CanExecute(param))
if (command is {} && command.CanExecute(param))
{
command.Execute(param);
}
}

// It stays open when onInvoked is expand.
if (BehaviorOnInvoked() == winrt.SwipeBehaviorOnInvoked.Close ||
BehaviorOnInvoked() == winrt.SwipeBehaviorOnInvoked.Auto)
if (BehaviorOnInvoked == SwipeBehaviorOnInvoked.Close ||
BehaviorOnInvoked == SwipeBehaviorOnInvoked.Auto)
{
swipeControl.Close();
}
}

void OnPropertyChanged(winrt.DependencyPropertyChangedEventArgs& args)
private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
{
if (args.Property() == winrt.CommandProperty())
if (args.Property == CommandProperty)
{
OnCommandChanged(args.OldValue(). as<winrt.ICommand > (), args.NewValue().as<winrt.ICommand > ());
OnCommandChanged(args.OldValue as ICommand, args.NewValue as ICommand);
}
}

void OnCommandChanged(winrt.ICommand& /oldCommand/, winrt.ICommand& newCommand)
private void OnCommandChanged(ICommand oldCommand, ICommand newCommand)
{
if (var newUICommand = newCommand.try_as<winrt.XamlUICommand>())
if (newCommand is XamlUICommand newUICommand)
{
CommandingHelpers.BindToLabelPropertyIfUnset(newUICommand, this, winrt.TextProperty());
CommandingHelpers.BindToIconSourcePropertyIfUnset(newUICommand, this, winrt.IconSourceProperty());
CommandingHelpers.BindToLabelPropertyIfUnset(newUICommand, this, TextProperty);
CommandingHelpers.BindToIconSourcePropertyIfUnset(newUICommand, this, IconSourceProperty);
}
}

void GenerateControl(winrt.AppBarButton& appBarButton, winrt.Style& swipeItemStyle)
void GenerateControl(AppBarButton appBarButton, Style swipeItemStyle)
{
appBarButton.Style(swipeItemStyle);
if (Background())
if (Background is {})
{
appBarButton.Background(Background());
appBarButton.Background = Background;
}

if (Foreground())
if (Foreground is {})
{
appBarButton.Foreground(Foreground());
appBarButton.Foreground = Foreground;
}

if (IconSource())
if (IconSource is {})
{
appBarButton.Icon(IconSource().CreateIconElement());
appBarButton.Icon = IconSource.CreateIconElement();
}

appBarButton.Label(Text());
appBarButton.Label = Text;
AttachEventHandlers(appBarButton);
}


void AttachEventHandlers(winrt.AppBarButton& appBarButton)
private void AttachEventHandlers(AppBarButton appBarButton)
{
var weakThis = get_weak();
appBarButton.Tapped({
[weakThis]
(auto

&sender, auto & args) {
if (var temp = weakThis.get()) temp.OnItemTapped(sender, args);
var weakThis = new WeakReference<SwipeItem>(this);
appBarButton.Tapped += (sender, args) =>
{
if (weakThis.TryGetTarget(out var temp))
{
temp.OnItemTapped(sender, args);
}
});
appBarButton.PointerPressed({
[weakThis]
(auto

&sender, auto & args) {
if (var temp = weakThis.get()) temp.OnPointerPressed(sender, args);
};
appBarButton.PointerPressed += (sender, args) =>
{
if (weakThis.TryGetTarget(out var temp))
{
temp.OnPointerPressed(sender, args);
}
});
};
}

void OnItemTapped(
winrt.DependencyObject& sender,

winrt.TappedRoutedEventArgs& args)
private void OnItemTapped(
object sender,
TappedRoutedEventArgs args)
{
var current = winrt.VisualTreeHelper.GetParent(sender.try_as<winrt.DependencyObject>());
while (current)
var current = VisualTreeHelper.GetParent(sender as DependencyObject);
while (current is {})
{
var control = current.try_as<winrt.SwipeControl>();
if (control)
var control = current as SwipeControl;
if (control is {})
{
InvokeSwipe(control);
args.Handled(true);
args.Handled = true;
}

current = winrt.VisualTreeHelper.GetParent(current);
current = VisualTreeHelper.GetParent(current);
}
}

void OnPointerPressed(
winrt.DependencyObject& /sender/,

winrt.PointerRoutedEventArgs& args)
private void OnPointerPressed(
object sender,
PointerRoutedEventArgs args)
{
if (args.Pointer().PointerDeviceType() == winrt.Devices.Input.PointerDeviceType.Touch)
if (args.Pointer.PointerDeviceType == Devices.Input.PointerDeviceType.Touch)
{
// if we press an item, we want to handle it and not let the parent SwipeControl receive the input
args.Handled(true);
args.Handled = true;
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions src/Uno.UI/UI/Xaml/Controls/SwipeControl/SwipeItem.h.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ namespace Windows.UI.Xaml.Controls
{
public partial class SwipeItem
{
class SwipeItem :
//class SwipeItem :

public ReferenceTracker<SwipeItem, winrt.implementation.SwipeItemT>,
//public ReferenceTracker<SwipeItem, winrt.implementation.SwipeItemT>,

public SwipeItemProperties
{
//public SwipeItemProperties
//{

public:
//public:

SwipeItem();
//SwipeItem();

// Property changed handler.
void OnPropertyChanged(winrt.DependencyPropertyChangedEventArgs& args);
//// Property changed handler.
//void OnPropertyChanged(winrt.DependencyPropertyChangedEventArgs& args);

void GenerateControl(winrt.AppBarButton& appBarButton, winrt.Style& swipeItemStyle);
//void GenerateControl(winrt.AppBarButton& appBarButton, winrt.Style& swipeItemStyle);

void InvokeSwipe(winrt.SwipeControl& content);
//void InvokeSwipe(winrt.SwipeControl& content);

private:
//private:

void OnItemTapped(
winrt.DependencyObject& sender,
//void OnItemTapped(
// winrt.DependencyObject& sender,

winrt.TappedRoutedEventArgs& args);
//winrt.TappedRoutedEventArgs& args);

void OnPointerPressed(
winrt.DependencyObject& sender,
//void OnPointerPressed(
// winrt.DependencyObject& sender,

winrt.PointerRoutedEventArgs& args);
//winrt.PointerRoutedEventArgs& args);

void OnCommandChanged(winrt.ICommand& oldCommand, winrt.ICommand& newCommand);
//void OnCommandChanged(winrt.ICommand& oldCommand, winrt.ICommand& newCommand);

void AttachEventHandlers(winrt.AppBarButton& appBarButton);
//void AttachEventHandlers(winrt.AppBarButton& appBarButton);
}
}
Loading

0 comments on commit cd6c42b

Please sign in to comment.