public void AddWaveShader() { LearnerShimmer element = this.Element as LearnerShimmer; int num1 = element.WaveDirection == WaveDirection.BottomToTop ? 1 : (element.WaveDirection == WaveDirection.TopToBottom ? 1 : 0); int num2 = num1 != 0 ? 0 : this.Width; int num3 = num1 != 0 ? this.Height : 0; int android1 = (int)element.WaveColor.ToAndroid(); int android2 = (int)element.Color.ToAndroid(); float num4 = (float)element.WaveWidth * this.density / (float)this.Width; float num5 = (double)num4 < 0.0 ? 0.0f : ((double)num4 > 1.0 ? 1f : num4); float[] positions = new float[3] { (float)(0.5 - (double)num5 / 2.0), 0.5f, (float)(0.5 + (double)num5 / 2.0) }; this.shader = (Shader) new LinearGradient(0.0f, 0.0f, (float)num2, (float)num3, new int[3] { android2, android1, android2 }, positions, Shader.TileMode.Clamp); this.wavePaint.SetShader(this.shader); }
protected override void DispatchDraw(Canvas canvas) { LearnerShimmer element = this.Element as LearnerShimmer; if (!element.IsActive || this.Height == 0 || this.Width == 0) { base.DispatchDraw(canvas); } else { if (element.CustomView == null) { this.DrawShimmerView(canvas); } base.DispatchDraw(canvas); this.DrawShimmerWave(canvas); } }
private void DrawShimmerWave(Canvas canvas) { float num1 = (float)Math.Tan(Math.PI / 9.0); float num2 = (float)this.Height + num1 * (float)this.Width; float num3 = (float)this.Width + num1 * (float)this.Height; float percent = this.animator != null ? this.animator.AnimatedFraction : 0.0f; this.shimmerMatrix?.Reset(); LearnerShimmer element = this.Element as LearnerShimmer; float dx; float dy; switch (element.WaveDirection) { case WaveDirection.TopToBottom: dx = 0.0f; dy = this.Offset(-num2, num2, percent); break; case WaveDirection.RightToLeft: dx = this.Offset(num3, -num3, percent); dy = 0.0f; break; case WaveDirection.BottomToTop: dx = 0.0f; dy = this.Offset(num2, -num2, percent); break; default: dx = this.Offset(-num3, num3, percent); dy = 0.0f; if (element.WaveDirection == WaveDirection.Default) { this.shimmerMatrix.SetRotate(25f, (float)this.Width / 2f, (float)this.Height / 2f); break; } break; } this.shimmerMatrix.PostTranslate(dx, dy); this.wavePaint.Shader?.SetLocalMatrix(this.shimmerMatrix); canvas.DrawRect(new Android.Graphics.Rect(0, 0, this.Width, this.Height), this.wavePaint); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); LearnerShimmer element = this.Element as LearnerShimmer; if (e.PropertyName == "Color" || e.PropertyName == "WaveColor" || (e.PropertyName == "WaveWidth" || e.PropertyName == "WaveDirection")) { this.AddWaveShader(); this.Invalidate(); } else if (e.PropertyName == "AnimationDuration") { this.AddWaveAnimator(); this.Invalidate(); } else if (e.PropertyName == "Type") { this.Invalidate(); } else if (e.PropertyName == "IsActive") { if (element.IsActive) { this.UpdateShimmerWave(); } else { this.animator?.End(); } } else { if (!(e.PropertyName == "BackgroundColor")) { return; } this.SetBackgroundColor(Android.Graphics.Color.Transparent); } }