From 12733213877f127f9d09e9522b67087169d42c9e Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Thu, 31 Jan 2019 12:45:46 +0530 Subject: [PATCH 1/6] mf textview similar to BR --- MVMCoreUI/Atoms/Views/MFTextView.h | 8 +++++ MVMCoreUI/Atoms/Views/MFTextView.m | 50 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.h b/MVMCoreUI/Atoms/Views/MFTextView.h index b1c80bdd..9d568b6a 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.h +++ b/MVMCoreUI/Atoms/Views/MFTextView.h @@ -7,6 +7,7 @@ // #import +#import "SeparatorView.h" @interface CustomTextView: UITextView @@ -25,7 +26,14 @@ @property (weak, nonatomic) id delegate; @property (weak, nonatomic) IBOutlet CustomTextView *textView; +@property (assign, nonatomic) BOOL hideBorder; +@property (strong, nonatomic) UIBezierPath *borderPath; +@property (nonatomic, readwrite) BOOL errorShowing; +@property (weak, nonatomic) SeparatorView *bottomLine; + +(MFTextView *) MFTextViewWithPlaceholderString:(NSString *) placeholder delegate:(id) delegate; +- (void)makeBordersForTextView; + @end diff --git a/MVMCoreUI/Atoms/Views/MFTextView.m b/MVMCoreUI/Atoms/Views/MFTextView.m index 1e734e3f..621947cf 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.m +++ b/MVMCoreUI/Atoms/Views/MFTextView.m @@ -10,6 +10,8 @@ #import "UIColor+MFConvenience.h" #import "MVMCoreUIUtility.h" #import "MVMCoreUIConstants.h" +#import "MFStyler.h" + @import MVMCore.MVMCoreConstants; @protocol CustomTextViewDelegate @@ -163,7 +165,55 @@ view.textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo; } [view didSetFont:view.textView.font]; + +// self.bottomLine = bottomLine; + return view; } + +#pragma mark - bordered textview +- (void)makeBordersForTextView { + + SeparatorView *bottomLine = [SeparatorView separatorAddToView:self position:SeparatorPositionBot]; + self.placeHolderLabel.font = [MFStyler fontB3]; + [self.textView setFont:[MFStyler fontB2]]; + [self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)]; + self.errorShowing = false; +} + +- (void)addBezierPathForBorders { + CGRect frame = self.frame; + self.borderPath = [UIBezierPath bezierPath]; + [self.borderPath moveToPoint:CGPointMake(frame.origin.x, frame.origin.y + frame.size.height)]; + [self.borderPath addLineToPoint:CGPointMake(frame.origin.x, frame.origin.y)]; + [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y)]; + [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)]; + + self.borderPath.lineWidth = 1; + + UIColor *strokeColor; + if (self.errorShowing) { + strokeColor = [UIColor mfPumpkinColor]; + self.bottomLine.backgroundColor = [UIColor mfPumpkinColor]; + } else { + strokeColor = [UIColor mfSilver]; + self.bottomLine.backgroundColor = [UIColor mfSilver]; + } + + [strokeColor setStroke]; + + [self.borderPath stroke]; +} + +- (void)drawRect:(CGRect)rect { + [super drawRect:rect]; + [self.borderPath removeAllPoints]; + self.layer.cornerRadius = 0; + self.hideBorder = false; + if (!self.hideBorder) { + [self addBezierPathForBorders]; + } +} + @end From a1effe87a4e80893b1c0525509b3d4b12a0e0a84 Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Fri, 1 Feb 2019 15:02:33 +0530 Subject: [PATCH 2/6] adding settext validations for placeholder Adding check for delegate to avoid crashes --- MVMCoreUI/Atoms/Views/MFTextView.m | 48 +++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.m b/MVMCoreUI/Atoms/Views/MFTextView.m index 621947cf..adea9598 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.m +++ b/MVMCoreUI/Atoms/Views/MFTextView.m @@ -20,6 +20,7 @@ -(void) didSetFont:(UIFont *) font; -(void) didSetContainerInset:(UIEdgeInsets)textContainerInset; -(void) didSetTextColor:(UIColor *)textColor; +-(void) didSetText:(NSString *)text; @end @@ -50,6 +51,11 @@ [self.delegateForUIChange didSetTextColor:textColor]; } +- (void)setText:(NSString *)text { + [super setText:text]; + [self.delegateForUIChange didSetText:text]; +} + @end @@ -103,33 +109,61 @@ // self.placeHolderLabel.textColor = textColor; } +- (void)didSetText:(NSString *)text { + [self showOrHidePlaceholderForTextView:self.textView]; +} + #pragma Mark UITextView Delegate methods forwarding -(BOOL)textViewShouldBeginEditing:(UITextView *)textView { - return [self.delegate textViewShouldBeginEditing:textView]; + if ([self.delegate respondsToSelector:@selector(textViewShouldBeginEditing:)]) { + return [self.delegate textViewShouldBeginEditing:textView]; + } + return true; } -(void)textViewDidBeginEditing:(UITextView *)textView { - [self.delegate textViewDidBeginEditing:textView]; - [self showOrHidePlaceholderForTextView:textView]; + [self showOrHidePlaceholderForTextView:textView]; + if ([self.delegate respondsToSelector:@selector(textViewDidBeginEditing:)]) { + [self.delegate textViewDidBeginEditing:textView]; + + } + } -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { - return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text]; + if ([self.delegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)]) { + return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text]; + + } + return true; } -(void)textViewDidChange:(UITextView *)textView { - [self.delegate textViewDidBeginEditing:textView]; [self showOrHidePlaceholderForTextView:textView]; + if ([self.delegate respondsToSelector:@selector(textViewDidChange:)]) { + [self.delegate textViewDidChange:textView]; + + } + } -(BOOL)textViewShouldEndEditing:(UITextView *)textView { - return [self.delegate textViewShouldEndEditing:textView]; + if ([self.delegate respondsToSelector:@selector(textViewShouldEndEditing:)]) { + return [self.delegate textViewShouldEndEditing:textView]; + + } + return true; } -(void)textViewDidEndEditing:(UITextView *)textView { - [self.delegate textViewDidEndEditing:textView]; [self showOrHidePlaceholderForTextView:textView]; + if ([self.delegate respondsToSelector:@selector(textViewDidEndEditing:)]) { + [self.delegate textViewDidEndEditing:textView]; + + } + + } - (void) showOrHidePlaceholderForTextView:(UITextView *) textView { From e5b06feae6dd34aed5525b56ace0c4a0803b5bfa Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Fri, 1 Feb 2019 20:39:23 +0530 Subject: [PATCH 3/6] adding toolbar --- MVMCoreUI/Atoms/Views/MFTextView.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.m b/MVMCoreUI/Atoms/Views/MFTextView.m index adea9598..5234b076 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.m +++ b/MVMCoreUI/Atoms/Views/MFTextView.m @@ -11,6 +11,7 @@ #import "MVMCoreUIUtility.h" #import "MVMCoreUIConstants.h" #import "MFStyler.h" +#import "MVMCoreUICommonViewsUtility.h" @import MVMCore.MVMCoreConstants; @@ -213,6 +214,7 @@ self.placeHolderLabel.font = [MFStyler fontB3]; [self.textView setFont:[MFStyler fontB2]]; [self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)]; + [MVMCoreUICommonViewsUtility addDismissToolbar:self.textView delegate:self.delegate]; self.errorShowing = false; } From 7b3018e6084bf271a134e1d11a392cdc516c61f9 Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Fri, 8 Feb 2019 20:39:03 +0530 Subject: [PATCH 4/6] border check so that BAU flow wont get affected --- MVMCoreUI/Atoms/Views/MFTextView.h | 8 ++++---- MVMCoreUI/Atoms/Views/MFTextView.m | 15 +++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.h b/MVMCoreUI/Atoms/Views/MFTextView.h index 9d568b6a..da147a5f 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.h +++ b/MVMCoreUI/Atoms/Views/MFTextView.h @@ -24,15 +24,15 @@ @interface MFTextView : UIView -@property (weak, nonatomic) id delegate; +@property (weak, nonatomic, nullable) id delegate; @property (weak, nonatomic) IBOutlet CustomTextView *textView; @property (assign, nonatomic) BOOL hideBorder; -@property (strong, nonatomic) UIBezierPath *borderPath; +@property (strong, nonatomic, nullable) UIBezierPath *borderPath; @property (nonatomic, readwrite) BOOL errorShowing; -@property (weak, nonatomic) SeparatorView *bottomLine; +@property (weak, nonatomic, nullable) SeparatorView *bottomLine; -+(MFTextView *) MFTextViewWithPlaceholderString:(NSString *) placeholder delegate:(id) delegate; ++(MFTextView *_Nullable) MFTextViewWithPlaceholderString:(NSString *_Nullable) placeholder delegate:(id _Nullable ) delegate; - (void)makeBordersForTextView; diff --git a/MVMCoreUI/Atoms/Views/MFTextView.m b/MVMCoreUI/Atoms/Views/MFTextView.m index 5234b076..866c6c00 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.m +++ b/MVMCoreUI/Atoms/Views/MFTextView.m @@ -200,9 +200,7 @@ view.textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo; } [view didSetFont:view.textView.font]; - -// self.bottomLine = bottomLine; - + view.hideBorder = YES; return view; } @@ -210,12 +208,14 @@ #pragma mark - bordered textview - (void)makeBordersForTextView { - SeparatorView *bottomLine = [SeparatorView separatorAddToView:self position:SeparatorPositionBot]; + [SeparatorView separatorAddToView:self position:SeparatorPositionBot]; self.placeHolderLabel.font = [MFStyler fontB3]; [self.textView setFont:[MFStyler fontB2]]; [self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)]; - [MVMCoreUICommonViewsUtility addDismissToolbar:self.textView delegate:self.delegate]; - self.errorShowing = false; + [MVMCoreUICommonViewsUtility addDismissToolbarToTextView:self.textView delegate:self.delegate]; + self.errorShowing = NO; + self.hideBorder = NO; + [self layoutIfNeeded]; } - (void)addBezierPathForBorders { @@ -245,9 +245,8 @@ - (void)drawRect:(CGRect)rect { [super drawRect:rect]; [self.borderPath removeAllPoints]; - self.layer.cornerRadius = 0; - self.hideBorder = false; if (!self.hideBorder) { + self.layer.cornerRadius = 0; [self addBezierPathForBorders]; } } From 69586928655307d1773e8f83af1b52e3230b581c Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Mon, 11 Feb 2019 18:10:37 +0530 Subject: [PATCH 5/6] adding comment --- MVMCoreUI/Atoms/Views/MFTextView.h | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.h b/MVMCoreUI/Atoms/Views/MFTextView.h index da147a5f..4641fcf2 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.h +++ b/MVMCoreUI/Atoms/Views/MFTextView.h @@ -34,6 +34,7 @@ +(MFTextView *_Nullable) MFTextViewWithPlaceholderString:(NSString *_Nullable) placeholder delegate:(id _Nullable ) delegate; +//This method will make the UI as per brand refresh (Similar to UITextField) - (void)makeBordersForTextView; @end From f8c4253b39cea3757ff25345896c6684d751882f Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Tue, 12 Feb 2019 20:34:42 +0530 Subject: [PATCH 6/6] spaces, spearator map --- MVMCoreUI/Atoms/Views/MFTextView.h | 1 - MVMCoreUI/Atoms/Views/MFTextView.m | 41 ++++++------------------------ 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.h b/MVMCoreUI/Atoms/Views/MFTextView.h index 4641fcf2..38ba964a 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.h +++ b/MVMCoreUI/Atoms/Views/MFTextView.h @@ -31,7 +31,6 @@ @property (nonatomic, readwrite) BOOL errorShowing; @property (weak, nonatomic, nullable) SeparatorView *bottomLine; - +(MFTextView *_Nullable) MFTextViewWithPlaceholderString:(NSString *_Nullable) placeholder delegate:(id _Nullable ) delegate; //This method will make the UI as per brand refresh (Similar to UITextField) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.m b/MVMCoreUI/Atoms/Views/MFTextView.m index 866c6c00..c120d964 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.m +++ b/MVMCoreUI/Atoms/Views/MFTextView.m @@ -57,8 +57,6 @@ [self.delegateForUIChange didSetText:text]; } - - @end @interface MFTextView () @@ -81,33 +79,25 @@ -(void)didSetContainerInset:(UIEdgeInsets)textContainerInset { UILabel *placeHolderLabel = self.placeHolderLabel; [placeHolderLabel removeConstraints:[self.placeHolderLabel constraints]]; - CGSize labelSize = [placeHolderLabel.text sizeWithAttributes:@{NSFontAttributeName: self.placeHolderLabel.font}]; - NSArray *constrainsApplied = @[@"PH_TRAILING", @"PH_LEADING", @"PH_TOP"]; - for (NSLayoutConstraint *constraint in self.constraints) { if ([constrainsApplied containsObject:constraint.identifier]) { [self removeConstraint:constraint]; } } - [placeHolderLabel addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[placeHolderLabel(height)]" options:0 metrics:@{@"height":@(ceilf(labelSize.height))} views:NSDictionaryOfVariableBindings(placeHolderLabel)]]; [placeHolderLabel addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[placeHolderLabel(width)]" options:0 metrics:@{@"width":@(ceilf(labelSize.width))} views:NSDictionaryOfVariableBindings(placeHolderLabel)]]; - NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:placeHolderLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0 constant:(textContainerInset.left + 5)]; leadingConstraint.identifier = @"PH_LEADING"; - NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:placeHolderLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:textContainerInset.top]; topConstraint.identifier = @"PH_TOP"; - [NSLayoutConstraint activateConstraints:@[leadingConstraint, topConstraint]]; - [self updateConstraints]; } -(void)didSetTextColor:(UIColor *)textColor { -// self.placeHolderLabel.textColor = textColor; + } - (void)didSetText:(NSString *)text { @@ -124,18 +114,15 @@ } -(void)textViewDidBeginEditing:(UITextView *)textView { - [self showOrHidePlaceholderForTextView:textView]; + [self showOrHidePlaceholderForTextView:textView]; if ([self.delegate respondsToSelector:@selector(textViewDidBeginEditing:)]) { [self.delegate textViewDidBeginEditing:textView]; - } - } -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if ([self.delegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)]) { return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text]; - } return true; } @@ -144,15 +131,12 @@ [self showOrHidePlaceholderForTextView:textView]; if ([self.delegate respondsToSelector:@selector(textViewDidChange:)]) { [self.delegate textViewDidChange:textView]; - } - } -(BOOL)textViewShouldEndEditing:(UITextView *)textView { if ([self.delegate respondsToSelector:@selector(textViewShouldEndEditing:)]) { - return [self.delegate textViewShouldEndEditing:textView]; - + return [self.delegate textViewShouldEndEditing:textView]; } return true; } @@ -161,10 +145,7 @@ [self showOrHidePlaceholderForTextView:textView]; if ([self.delegate respondsToSelector:@selector(textViewDidEndEditing:)]) { [self.delegate textViewDidEndEditing:textView]; - } - - } - (void) showOrHidePlaceholderForTextView:(UITextView *) textView { @@ -185,14 +166,12 @@ view.clipsToBounds = YES; view.translatesAutoresizingMaskIntoConstraints = NO; view.layer.cornerRadius = CornerRadiusLarge; - view.textView.delegateForUIChange = view; view.textView.translatesAutoresizingMaskIntoConstraints = NO; - view.placeHolderLabel.text = placeholder; view.placeHolderLabel.translatesAutoresizingMaskIntoConstraints = NO; view.placeHolderLabel.textColor = [UIColor mfLightGrayColor]; - + // Disable SmartQuotes if (@available(iOS 11.0, *)) { view.textView.smartQuotesType = UITextSmartQuotesTypeNo; @@ -204,11 +183,10 @@ return view; } - #pragma mark - bordered textview - (void)makeBordersForTextView { - - [SeparatorView separatorAddToView:self position:SeparatorPositionBot]; + SeparatorView *bottomLine = [SeparatorView separatorAddToView:self position:SeparatorPositionBot]; + self.bottomLine = bottomLine; self.placeHolderLabel.font = [MFStyler fontB3]; [self.textView setFont:[MFStyler fontB2]]; [self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)]; @@ -225,7 +203,6 @@ [self.borderPath addLineToPoint:CGPointMake(frame.origin.x, frame.origin.y)]; [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y)]; [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)]; - self.borderPath.lineWidth = 1; UIColor *strokeColor; @@ -234,11 +211,9 @@ self.bottomLine.backgroundColor = [UIColor mfPumpkinColor]; } else { strokeColor = [UIColor mfSilver]; - self.bottomLine.backgroundColor = [UIColor mfSilver]; + self.bottomLine.backgroundColor = [UIColor blackColor]; } - [strokeColor setStroke]; - [self.borderPath stroke]; } @@ -246,7 +221,7 @@ [super drawRect:rect]; [self.borderPath removeAllPoints]; if (!self.hideBorder) { - self.layer.cornerRadius = 0; + self.layer.cornerRadius = 0; [self addBezierPathForBorders]; } }