/// <summary> /// Initializes the UI for the PINView /// </summary> public void CreateControl() { hiddenTextEntry.MaxLength = PINLength; SetInputType(PINInputType); var count = PINBoxContainer.Children.Count; if (count < PINLength) { int newBoxesToAdd = PINLength - count; char[] pinCharsArray = PINValue.ToCharArray(); for (int i = 1; i <= newBoxesToAdd; i++) { BoxTemplate boxTemplate = CreateBox(); PINBoxContainer.Children.Add(boxTemplate); // When we assign PINValue in XAML directly, the Boxes outside the default length (4), will not get any value in it, eventhough we have assigned it in XAML // To correct this behavior, we have programatically assigned value to those Boxes which are added after the Default Length if (PINValue.Length >= PINLength) { boxTemplate.SetValueWithAnimation(pinCharsArray[Constants.DefaultPINLength + i - 1]); } } } else if (count > PINLength) { int boxesToRemove = count - PINLength; for (int i = 1; i <= boxesToRemove; i++) { PINBoxContainer.Children.RemoveAt(PINBoxContainer.Children.Count - 1); } } }
/// <summary> /// Creates the instance of one single PIN box UI /// </summary> /// <returns></returns> private BoxTemplate CreateBox(char?charValue = null) { BoxTemplate boxTemplate = new BoxTemplate(); boxTemplate.HeightRequest = BoxSize; boxTemplate.WidthRequest = BoxSize; boxTemplate.Box.BackgroundColor = BoxBackgroundColor; boxTemplate.CharLabel.FontSize = BoxSize / 2; boxTemplate.GestureRecognizers.Add(boxTapGestureRecognizer); boxTemplate.BoxFocusColor = BoxFocusColor; boxTemplate.FocusAnimationType = BoxFocusAnimation; boxTemplate.SecureMode(IsPassword); boxTemplate.SetColor(Color, BoxBorderColor); boxTemplate.SetRadius(BoxShape); if (charValue.HasValue) { boxTemplate.SetValueWithAnimation(charValue.Value); } return(boxTemplate); }