Beispiel #1
0
        public void Update(AnimatedVisualPlayer player)
        {
            if (_animation == null)
            {
                _animation = new LOTAnimationView();
                SetProperties();
#if __IOS__
                player.Add(_animation);
#else
                player.AddSubview(_animation);
#endif
            }
            else
            {
                SetProperties();
            }

            void SetProperties()
            {
                var path = UriSource?.PathAndQuery ?? "";

                if (_lastPath != path)
                {
                    _animation.SetAnimationNamed(path);
                    _lastPath = path;
                }

                switch (player.Stretch)
                {
                case Windows.UI.Xaml.Media.Stretch.None:
                    _animation.ContentMode = _ViewContentMode.Center;
                    break;

                case Windows.UI.Xaml.Media.Stretch.Uniform:
                    _animation.ContentMode = _ViewContentMode.ScaleAspectFit;
                    break;

                case Windows.UI.Xaml.Media.Stretch.Fill:
                    _animation.ContentMode = _ViewContentMode.ScaleToFill;
                    break;

                case Windows.UI.Xaml.Media.Stretch.UniformToFill:
                    _animation.ContentMode = _ViewContentMode.ScaleAspectFill;
                    break;
                }

                _animation.AnimationSpeed = (nfloat)player.PlaybackRate;

                if (player.AutoPlay && !_isPlaying)
                {
                    Play(true);
                }
            }

            _player = player;
        }
Beispiel #2
0
        partial void InnerUpdate()
        {
            var player = _player;

            if (_animation == null)
            {
                _animation = new LOTAnimationView();
                SetProperties();
#if __IOS__
                player.Add(_animation);
#else
                player.AddSubview(_animation);
#endif
            }
            else
            {
                SetProperties();
            }

            void SetProperties()
            {
                var path = UriSource?.PathAndQuery ?? "";

                if (_lastPath != path)
                {
                    _animation.SetAnimationNamed(path);
                    _lastPath = path;

                    // Force layout to recalculate
                    player.InvalidateMeasure();
                    player.InvalidateArrange();

                    if (player.AutoPlay)
                    {
                        Play(0, 1, true);
                    }
                }

                switch (player.Stretch)
                {
                case Windows.UI.Xaml.Media.Stretch.None:
                    _animation.ContentMode = _ViewContentMode.Center;
                    break;

                case Windows.UI.Xaml.Media.Stretch.Uniform:
                    _animation.ContentMode = _ViewContentMode.ScaleAspectFit;
                    break;

                case Windows.UI.Xaml.Media.Stretch.Fill:
                    _animation.ContentMode = _ViewContentMode.ScaleToFill;
                    break;

                case Windows.UI.Xaml.Media.Stretch.UniformToFill:
                    _animation.ContentMode = _ViewContentMode.ScaleAspectFill;
                    break;
                }

                var duration = TimeSpan.FromSeconds(_animation.AnimationDuration);

                player.SetValue(AnimatedVisualPlayer.DurationProperty, duration);

                var isLoaded = duration > TimeSpan.Zero;

                player.SetValue(AnimatedVisualPlayer.IsAnimatedVisualLoadedProperty, isLoaded);

                _animation.CompletionBlock = isCompleted =>
                {
                    SetIsPlaying(_animation.IsAnimationPlaying);
                };

                _animation.AnimationSpeed = (nfloat)player.PlaybackRate;
            }
        }