/// <summary>
        /// Implementation of method required by the <see cref="T:XFGloss.IGradientRenderer"/> interface. Updates
        /// the gradient fill steps being used by any existing implementation of the property specified by the
        /// propertyName parameter.
        /// </summary>
        /// <param name="propertyName">The name of the XFGloss attached BindableProperty that changed</param>
        /// <param name="steps">The new collection of <see cref="T:XFGloss.GradientStep"/> instances that specify the
        /// colors and positions of each step of the gradient fill</param>
        public void UpdateSteps(string propertyName, GradientStepCollection steps)
        {
            // No need to check property name yet, BackgroundGradient is the only one being handled here.
            var nativeCell = GetNativeCell();

            if (nativeCell != null)
            {
                GetBackgroundGradientDrawable(nativeCell)?.UpdateSteps(steps);
            }
        }
        /// <summary>
        /// Helper function that converts a list of Xamarin.Forms.Color instances to iOS CGColor instances
        /// </summary>
        /// <returns>An array of CGColor instances</returns>
        /// <param name="steps">The colection of <see cref="T:XFGloss.GradientStep"/> instances to be converted</param>
        static CGColor[] ToCGColors(GradientStepCollection steps)
        {
            List <CGColor> result = new List <CGColor>();

            foreach (GradientStep step in steps)
            {
                result.Add(step.StepColor.ToCGColor());
            }

            return(result.ToArray());
        }
        /// <summary>
        /// Provides public access to update the <see cref="T:XFGloss.GradientStepCollection"/> of
        /// <see cref="T:XFGloss.GradientStep"/> instances for an existing gradient fill.
        /// </summary>
        /// <param name="steps">The new gradient steps to be applied to the existing gradient fill</param>
        public void UpdateSteps(GradientStepCollection steps)
        {
            if (_xfgGradient == null)
            {
                return;
            }

            var sf = GetShaderFactory();

            sf?.Dispose();

            _xfgGradient.Steps = steps;

            sf = new XFGlossShaderFactory(_xfgGradient, _shaderMatrix);
            SetShaderFactory(sf);

            Paint.Shader?.Dispose();
            Paint.SetShader(sf.Resize(Bounds.Width(), Bounds.Height()));
        }
        /// <summary>
        /// Updates an existing gradient layer's colors and position percentage values, if found
        /// </summary>
        /// <param name="steps">The <see cref="T:XFGloss.GradientStepCollection"/> of
        /// <see cref="T:XFGloss.GradientStep"/> instances</param>
        public void UpdateSteps(GradientStepCollection steps)
        {
            var gradient = GradientSource ?? new Gradient();

            if (gradient != null && !gradient.Steps.Equals(steps))
            {
                gradient.Steps = new GradientStepCollection(steps);
                Colors         = ToCGColors(steps);
                Locations      = ToNSNumbers(steps);

                if (GradientSource == null)
                {
                    GradientSource = gradient;
                }
                else
                {
                    GradientSource.Steps = gradient.Steps;
                }
            }
        }
        /// <summary>
        /// Helper function that converts a list of step percentages to NSNumbers
        /// </summary>
        /// <returns>An array of NSNumber instances</returns>
        /// <param name="steps">The colection of <see cref="T:XFGloss.GradientStep"/> instances to be converted</param>
        static public NSNumber[] ToNSNumbers(GradientStepCollection steps)
        {
            List <NSNumber> result = new List <NSNumber>();

            float lastStep = float.MinValue;

            foreach (GradientStep step in steps)
            {
                if (lastStep > step.StepPercentage)
                {
                    throw new ArgumentOutOfRangeException(nameof(GradientStep.StepPercentage), "The current StepPercentage " +
                                                          "value must be greater than zero and the previous " +
                                                          " StepPercentage value.");
                }

                result.Add(new NSNumber(step.StepPercentage));
            }

            return(result.ToArray());
        }
Exemple #6
0
 /// <summary>
 /// Implementation of method required by the <see cref="T:XFGloss.IGradientRenderer"/> interface. Updates
 /// the gradient fill steps being used by any existing implementation of the property specified by the
 /// propertyName parameter.
 /// </summary>
 /// <param name="propertyName">The name of the XFGloss attached BindableProperty that changed</param>
 /// <param name="steps">The new collection of <see cref="T:XFGloss.GradientStep"/> instances that specify the
 /// colors and positions of each step of the gradient fill</param>
 public void UpdateSteps(string propertyName, GradientStepCollection steps)
 {
     // No need to check property name yet, BackgroundGradient is the only one being handled here.
     XFGlossGradientLayer.GetGradientLayer(NativeView)?.UpdateSteps(steps);
 }
 /// <summary>
 /// Implementation of method required by the <see cref="T:XFGloss.IGradientRenderer"/> interface. Updates
 /// the gradient fill steps being used by any existing implementation of the property specified by the
 /// propertyName parameter.
 /// </summary>
 /// <param name="propertyName">The name of the XFGloss attached BindableProperty that changed</param>
 /// <param name="steps">The new collection of <see cref="T:XFGloss.GradientStep"/> instances that specify the
 /// colors and positions of each step of the gradient fill</param>
 public void UpdateSteps(string propertyName, GradientStepCollection steps)
 {
     // No need to check property name yet, BackgroundGradient is the only one being handled here.
     GetBackgroundGradientDrawable()?.UpdateSteps(steps);
     Invalidate();
 }
        /// <summary>
        /// Updates the associated <see cref="T:XFGloss.iOS.Views.XFGlossGradientLayer"/> instance's steps collection.
        /// </summary>
        /// <param name="steps">The steps collection to assign</param>
        public void UpdateSteps(GradientStepCollection steps)
        {
            var layer = XFGlossGradientLayer.GetGradientLayer(this);

            layer?.UpdateSteps(steps);
        }