This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| using System.Threading.Tasks; | |
| using UIKit; | |
| namespace TextFieldValidation_Medium | |
| { | |
| public partial class ViewController : UIViewController | |
| { | |
| private ValidationTextField _validationField; | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private async void EditingEnded(object sender, EventArgs args) | |
| { | |
| await Validate(); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public async Task<ValidationState> Validate() | |
| { | |
| var trigger = await RunTriggers(); | |
| Update(trigger.State, trigger.Message); // NEW | |
| return trigger.State; | |
| } | |
| ... | |
| private void Update(ValidationState state, string message) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public async Task<ValidationState> Validate() | |
| { | |
| var trigger = await RunTriggers(); | |
| return trigger.State; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private async Task<Trigger> RunTriggers() | |
| { | |
| // Note that the text is pulled outside of the new tasks | |
| var text = _textField.TextField.Text; | |
| // neutral triggers first | |
| foreach(var trigger in _neutralTriggers) | |
| { | |
| if(await Task.Run(() => trigger.TriggerFunction(text))) | |
| { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public class ValidationTextField | |
| { | |
| ... // Private fields | |
| private List<Trigger> _neutralTriggers = new List<Trigger>(); | |
| private List<Trigger> _errorTriggers = new List<Trigger>(); | |
| ... //Public properties | |
| ... // Constructor | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public CGColor EditingColor { get; set; } | |
| ... | |
| public ValidationTextField(BorderedTextField textField) | |
| { | |
| ... // Initialize state colors | |
| EditingColor = _textField.BorderColor; | |
| _textField.TextField.EditingDidBegin += EditingBegan; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public class ValidationTextField | |
| { | |
| private BorderedTextField _textField; | |
| private UILabel _errorLabel; // NEW | |
| private CGColor _neutralStateColor; | |
| ... // State Color Properties | |
| // NEW | |
| public UIFont ErrorFont | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using CoreGraphics; | |
| namespace TextFieldValidation_Medium | |
| { | |
| public class ValidationTextField | |
| { | |
| private BorderedTextField _textField; | |
| private ValidationState _state = ValidationState.Neutral; | |
| public CGColor NeutralStateColor { get; set; } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var borderedField = new BorderedTextField(NameTextField, NameTextField.TextColor.CGColor, BorderDirection.Bottom, 4); |