private void RemoveToast(ToastItem toastItem) { if (toastItem.IsFinalizing) { return; } toastItem.IsFinalizing = true; toastItem.FinalizingActions(); var storyboard = new Storyboard(); var projectionAnimation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(0.6)), To = 90 }; storyboard.Children.Add(projectionAnimation); Storyboard.SetTargetProperty(projectionAnimation, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationX)")); Storyboard.SetTarget(projectionAnimation, toastItem.Element); var item = toastItem; EventHandler completedHandler = null; completedHandler = (s, ea) => { _toastItems.Remove(item); _activeItemsControl.Items.Remove(item.Element); UpdateVisibility(); TryDequeue(); storyboard.Completed -= completedHandler; }; storyboard.Completed += completedHandler; storyboard.Begin(); }
private void RemoveToast(ToastItem toastItem) { if (toastItem.IsFinalizing) return; toastItem.IsFinalizing = true; toastItem.FinalizingActions(); var storyboard = new Storyboard(); var projectionAnimation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(0.6)), To = 90 }; storyboard.Children.Add(projectionAnimation); Storyboard.SetTargetProperty(projectionAnimation, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationX)")); Storyboard.SetTarget(projectionAnimation, toastItem.Element); var item = toastItem; EventHandler completedHandler = null; completedHandler = (s, ea) => { _toastItems.Remove(item); ActiveToastList.Items.Remove(item.Element); UpdateVisibility(); TryDequeue(); storyboard.Completed -= completedHandler; }; storyboard.Completed += completedHandler; storyboard.Begin(); }
public void Show(string text, float duration) { if (toastItem == null) { GameObject prefab = Resources.Load <GameObject>("ToastManager/ToastItem"); toastItem = Instantiate(prefab).GetComponent <ToastItem>(); } if (UIRoot.list.Count > 0) { Transform tran = toastItem.gameObject.transform; tran.parent = UIRoot.list[0].transform; tran.localPosition = Vector3.zero; tran.localScale = Vector3.one; tran.localRotation = Quaternion.identity; } toastItem.SetText(text); toastItem.SetDuration(duration); Invoke("InternalShow", 0.05f); }
private void AppendToast(NotificationItem notification) { //root layout var layoutGrid = new Grid(); var toastItem = new ToastItem(layoutGrid, DateTime.Now, notification); layoutGrid.HorizontalAlignment = HorizontalAlignment.Stretch; //layoutGrid.Height = 70; layoutGrid.Margin = new Thickness(0, 0, 0, 2); //2 - a margin between toasts layoutGrid.Background = notification.Brush; layoutGrid.Projection = new PlaneProjection(); layoutGrid.RenderTransformOrigin = new Point(0.5, 0.5); layoutGrid.RenderTransform = new CompositeTransform { TranslateX = -800 }; layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); Button closeButton = null; if (notification.ShowCloseButton) { layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40.0) }); //close button closeButton = new Button(); SetColumn(closeButton, 1); closeButton.Tag = toastItem; closeButton.Width = 66; closeButton.Height = 90; closeButton.Content = "\u2716"; //X symbol closeButton.BorderThickness = new Thickness(0); closeButton.FontSize = 32; closeButton.Padding = new Thickness(0); closeButton.Opacity = 0.4; closeButton.Margin = new Thickness(-12, -15, -8, -8); //TODO: fix it closeButton.HorizontalAlignment = HorizontalAlignment.Right; closeButton.Tap += CloseButton_OnTap; layoutGrid.Children.Add(closeButton); } //toast content var contentGrid = new Grid(); contentGrid.Tag = toastItem; contentGrid.Children.Add(notification.Content); layoutGrid.Children.Add(contentGrid); contentGrid.Tap += ContentGrid_OnTap; toastItem.FinalizingActions += () => contentGrid.Tap -= ContentGrid_OnTap; if (closeButton != null) { toastItem.FinalizingActions += () => closeButton.Tap -= CloseButton_OnTap; } //appear animation var animation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(0.2)), To = 0 }; var storyboard = new Storyboard(); storyboard.Children.Add(animation); Storyboard.SetTarget(animation, layoutGrid); Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)")); storyboard.Begin(); _activeItemsControl.Items.Add(layoutGrid); _toastItems.Add(toastItem); }
private void AppendToast(NotificationItem notification) { //root layout var layoutGrid = new Grid(); var toastItem = new ToastItem(layoutGrid, DateTime.Now, notification); layoutGrid.HorizontalAlignment = HorizontalAlignment.Stretch; layoutGrid.Height = 70; layoutGrid.Margin = new Thickness(0, 0, 0, 2); //2 - a margin between toasts layoutGrid.Background = notification.Brush; layoutGrid.Projection = new PlaneProjection(); layoutGrid.RenderTransformOrigin = new Point(0.5, 0.5); layoutGrid.RenderTransform = new CompositeTransform { TranslateX = -800 }; layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); Button closeButton = null; if (notification.ShowCloseButton) { layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40.0) }); //close button closeButton = new Button(); SetColumn(closeButton, 1); closeButton.Tag = toastItem; closeButton.Width = 66; closeButton.Height = 90; closeButton.Content = "\u2716"; //X symbol closeButton.BorderThickness = new Thickness(0); closeButton.FontSize = 32; closeButton.Padding = new Thickness(0); closeButton.Opacity = 0.4; closeButton.Margin = new Thickness(-12, -15, -8, -8); //TODO: fix it closeButton.FontSize = 32; closeButton.HorizontalAlignment = HorizontalAlignment.Right; closeButton.Tap += CloseButton_OnTap; layoutGrid.Children.Add(closeButton); } //toast content var contentGrid = new Grid(); contentGrid.Tag = toastItem; contentGrid.Children.Add(notification.Content); layoutGrid.Children.Add(contentGrid); contentGrid.Tap += ContentGrid_OnTap; toastItem.FinalizingActions += () => contentGrid.Tap -= ContentGrid_OnTap; if (closeButton != null) { toastItem.FinalizingActions += () => closeButton.Tap -= CloseButton_OnTap; } //appear animation var animation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(0.2)), To = 0 }; var storyboard = new Storyboard(); storyboard.Children.Add(animation); Storyboard.SetTarget(animation, layoutGrid); Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)")); storyboard.Begin(); _activeItemsControl.Items.Add(layoutGrid); _toastItems.Add(toastItem); }
private void AppendToast(NotificationItem notification) { //root layout var layoutGrid = new Grid(); var toastItem = new ToastItem(layoutGrid, DateTime.Now, notification); layoutGrid.HorizontalAlignment = HorizontalAlignment.Stretch; layoutGrid.Height = 65; layoutGrid.Margin = new Thickness(0, 0, 0, 4); layoutGrid.Background = new SolidColorBrush(notification.Color); layoutGrid.Projection = new PlaneProjection(); layoutGrid.RenderTransformOrigin = new Point(0.5, 0.5); layoutGrid.RenderTransform = new CompositeTransform { TranslateX = -800 }; layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(65.0) }); //close button var closeButton = new Button(); Grid.SetColumn(closeButton, 1); closeButton.Tag = toastItem; closeButton.Width = 80; closeButton.Height = 90; closeButton.Content = "\u2716"; closeButton.BorderThickness = new Thickness(0); closeButton.FontSize = 32; closeButton.Padding = new Thickness(0); closeButton.Opacity = 0.4; closeButton.Margin = new Thickness(-6, -12, -10, -8); closeButton.FontSize = 32; closeButton.HorizontalAlignment = HorizontalAlignment.Right; closeButton.Tap += closeButton_OnTap; layoutGrid.Children.Add(closeButton); //toast content var contentGrid = new Grid(); contentGrid.Tag = toastItem; contentGrid.Background = new SolidColorBrush(Color.FromArgb(1, 255, 255, 255)); contentGrid.Children.Add(notification.Content); layoutGrid.Children.Add(contentGrid); contentGrid.Tap += contentGrid_OnTap; toastItem.FinalizingActions += () => contentGrid.Tap -= contentGrid_OnTap; toastItem.FinalizingActions += () => closeButton.Tap -= closeButton_OnTap; //appear animation var animation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromSeconds(0.2)), To = 0 }; var storyboard = new Storyboard(); storyboard.Children.Add(animation); Storyboard.SetTarget(animation, layoutGrid); Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)")); storyboard.Begin(); ActiveToastList.Items.Add(layoutGrid); _toastItems.Add(toastItem); }