protected override async Task OnParametersSetAsync()
        {
            previousVisibility = currentVisibility;

            if (!OnLightDismissClick.HasDelegate)
            {
                OnLightDismissClick = OnDismiss; //OnLightDismissClick. //= EventCallback.Factory.Create(this, onPanelClick);
            }

            if (IsOpen && (currentVisibility == PanelVisibilityState.Closed || currentVisibility == PanelVisibilityState.AnimatingClosed))
            {
                currentVisibility = PanelVisibilityState.AnimatingOpen;
            }
            if (!IsOpen && (currentVisibility == PanelVisibilityState.Open || currentVisibility == PanelVisibilityState.AnimatingOpen))
            {
                currentVisibility = PanelVisibilityState.AnimatingClosed;
                // This StateHasChanged call was added because using a custom close button in NavigationTemplate did not cause a state change to occur.
                // The result was that the animation class would not get added and the close transition would not show.  This is a hack to make it work.
                InvokeAsync(StateHasChanged);
            }

            //Debug.WriteLine($"Was: {previousVisibility}  Current:{currentVisibility}");

            if (_jsAvailable)
            {
                if (currentVisibility != previousVisibility)
                {
                    Debug.WriteLine("Clearing animation timer");
                    _clearExistingAnimationTimer();
                    if (currentVisibility == PanelVisibilityState.AnimatingOpen)
                    {
                        isAnimating          = true;
                        animationRenderStart = true;
                        _animateTo(PanelVisibilityState.Open);
                    }
                    else if (currentVisibility == PanelVisibilityState.AnimatingClosed)
                    {
                        isAnimating = true;
                        //animationRenderStart = true;
                        _animateTo(PanelVisibilityState.Closed);
                    }
                }

                //await SetRegistrationsAsync();
            }


            await base.OnParametersSetAsync();
        }
Example #2
0
        public Panel()
        {
            Debug.WriteLine("Panel Created");
            _animationTimer = new Timer();

            HeaderTemplate = builder =>
            {
                if (HeaderText != null)
                {
                    builder.OpenElement(0, "div");
                    {
                        builder.AddAttribute(1, "class", "ms-Panel-header");
                        builder.OpenElement(2, "p");
                        {
                            builder.AddAttribute(3, "class", "xlargeFont ms-Panel-headerText");
                            //builder.AddAttribute(4, "id", )
                            builder.AddAttribute(5, "role", "heading");
                            builder.AddAttribute(6, "aria-level", "2");
                            builder.AddContent(7, HeaderText);
                        }
                        builder.CloseElement();
                    }
                    builder.CloseElement();
                }
            };

            onPanelClick = () =>
            {
                this._dismiss();
            };

            _dismiss = async() =>
            {
                await OnDismiss.InvokeAsync(null);

                //normally, would check react synth events to see if event was interrupted from the OnDismiss callback before calling the following...
                // To Do
                this.Close();
            };

            _clearExistingAnimationTimer = () =>
            {
                if (_animationTimer.Enabled)
                {
                    _animationTimer.Stop();
                    _animationTimer.Elapsed -= _handler;
                }
            };

            _animateTo = (animationState) =>
            {
                _animationTimer.Interval = 200;
                _handler = null;
                _handler = (s, e) =>
                {
                    InvokeAsync(() =>
                    {
                        //Debug.WriteLine("Inside invokeAsync from animateTo timer elapsed");
                        _animationTimer.Elapsed -= _handler;
                        _animationTimer.Stop();

                        previousVisibility = currentVisibility;
                        currentVisibility  = animationState;
                        _onTransitionComplete();
                    });
                };
                _animationTimer.Elapsed += _handler;
                _animationTimer.Start();
            };

            _onTransitionComplete = async() =>
            {
                isAnimating = false;
                //StateHasChanged();
                await UpdateFooterPositionAsync();

                if (currentVisibility == PanelVisibilityState.Open)
                {
                    await OnOpened.InvokeAsync(null);
                }
                if (currentVisibility == PanelVisibilityState.Closed)
                {
                    await OnDismissed.InvokeAsync(null);
                }
                StateHasChanged();
            };
        }