Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature can display a recipient field. #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions JCDialPad/JCDialPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@optional
- (BOOL)dialPad:(JCDialPad *)dialPad shouldInsertText:(NSString *)text forButtonPress:(JCPadButton *)button;
- (BOOL)dialPad:(JCDialPad *)dialPad shouldInsertText:(NSString *)text forLongButtonPress:(JCPadButton *)button;
- (void)dialPad:(JCDialPad *)dialPad didChanged:(NSString *)rawText;

@end

Expand All @@ -24,6 +25,8 @@
@property (nonatomic, strong) UIButton *deleteButton;
@property (nonatomic, strong) UITextField *digitsTextField;

@property (nonatomic, strong) NSString *recipient;

@property (weak, nonatomic) id<JCDialPadDelegate> delegate;

/**
Expand Down
40 changes: 38 additions & 2 deletions JCDialPad/JCDialPad.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface JCDialPad()
@property (nonatomic, strong) UIView* contentView;
@property (nonatomic, strong) UIView* backgroundBlurringView;
@property (nonatomic, strong) NBAsYouTypeFormatter *numFormatter;
@property (nonatomic, strong) UILabel *recipientLabel;

@end

Expand Down Expand Up @@ -78,8 +79,14 @@ - (void)initializeProperties
self.digitsTextField.textColor = [self.mainColor colorWithAlphaComponent:0.9];

self.formatTextToPhoneNumber = YES;
self.regionCode = @"US";
self.rawText = @"";

self.recipientLabel = [[UILabel alloc] init];
self.recipientLabel.textAlignment = NSTextAlignmentCenter;
self.recipientLabel.backgroundColor = [UIColor clearColor];
self.recipientLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:11.0];
self.recipientLabel.textColor = [self.mainColor colorWithAlphaComponent:0.9];
self.recipientLabel.alpha = 0.0f;
}

#pragma mark -
Expand Down Expand Up @@ -156,6 +163,18 @@ - (void)setBackgroundView:(UIView *)backgroundView
}
}

- (void)setRecipient:(NSString *)recipient
{
[UIView animateWithDuration:0.2f animations:^{
self.recipientLabel.alpha = 0.0f;
} completion:^(BOOL finished) {
self.recipientLabel.text = recipient;
[UIView animateWithDuration:0.2f animations:^{
self.recipientLabel.alpha = 1.0f;
}];
}];
}

#pragma mark - Helper Methods
- (void)didTapButton:(UIButton *)sender
{
Expand Down Expand Up @@ -215,13 +234,21 @@ - (void)appendText:(NSString *)text
self.digitsTextField.text = formatted;

[self toggleDeleteButtonVisible:YES animated:YES];

if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) {
[_delegate dialPad:self didChanged:_rawText];
}
}
}

- (void)didTapDeleteButton:(UIButton *)sender
{
if (!self.rawText.length)
if (!self.rawText.length) {
if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) {
[_delegate dialPad:self didChanged:_rawText];
}
return;
}

_rawText = [self.rawText substringToIndex:self.rawText.length - 1];
NSString *formatted = self.rawText;
Expand All @@ -233,11 +260,17 @@ - (void)didTapDeleteButton:(UIButton *)sender
if (!self.rawText.length) {
[self toggleDeleteButtonVisible:NO animated:YES];
}
if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) {
[_delegate dialPad:self didChanged:_rawText];
}
}

- (void)didHoldDeleteButton:(UIGestureRecognizer *)holdRec
{
self.rawText = @"";
if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) {
[_delegate dialPad:self didChanged:_rawText];
}
}

#pragma mark - Layout Methods
Expand Down Expand Up @@ -266,6 +299,9 @@ - (void)layoutTitleArea

self.deleteButton.frame = CGRectMake(self.digitsTextField.right + 2, self.digitsTextField.center.y - 10, top + 28, 20);
[self.contentView addSubview:self.deleteButton];

self.recipientLabel.frame = CGRectMake(self.digitsTextField.x, self.digitsTextField.bottom, self.digitsTextField.width, 10.0f);
[self.contentView addSubview:self.recipientLabel];
}

- (void)layoutButtons
Expand Down
21 changes: 15 additions & 6 deletions JCDialPadDemo/JCDialPadDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

/* Begin PBXFileReference section */
22C029B1E7A346D2ADBE703D /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
295EA24F3F21109D11BD04E4 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
5C701019DB74FB49ED98DA43 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
86F9242A1936B772007C3772 /* JCDialPadDemoAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JCDialPadDemoAppDelegate.h; path = "JCDialPadDemo/Application Bootstrap/JCDialPadDemoAppDelegate.h"; sourceTree = SOURCE_ROOT; };
86F9242B1936B772007C3772 /* JCDialPadDemoAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JCDialPadDemoAppDelegate.m; path = "JCDialPadDemo/Application Bootstrap/JCDialPadDemoAppDelegate.m"; sourceTree = SOURCE_ROOT; };
86F9242D1936B7A6007C3772 /* ExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExampleViewController.h; path = "JCDialPadDemo/Your Modules/ExampleViewController.h"; sourceTree = SOURCE_ROOT; };
Expand All @@ -52,7 +54,6 @@
9C79B0F0188A184A00D465D8 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
9C79B18A188A1A7100D465D8 /* JCDialPadDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JCDialPadDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9C9F7AB5188A40A1004B0B6D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -89,7 +90,7 @@
9C79B0DD188A184A00D465D8 /* JCDialPadDemo */,
9C79B0D6188A184A00D465D8 /* Frameworks */,
9C79B0D5188A184A00D465D8 /* Products */,
C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */,
D59200BEA0F8424C8E921E53 /* Pods */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -122,7 +123,6 @@
9C79B109188A18A100D465D8 /* Your Modules */,
9C79B0DE188A184A00D465D8 /* Supporting Files */,
);
name = JCDialPadDemo;
path = JCDialPadDemo;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -155,6 +155,15 @@
path = "Your Modules";
sourceTree = "<group>";
};
D59200BEA0F8424C8E921E53 /* Pods */ = {
isa = PBXGroup;
children = (
295EA24F3F21109D11BD04E4 /* Pods.debug.xcconfig */,
5C701019DB74FB49ED98DA43 /* Pods.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -276,7 +285,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n";
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -384,7 +393,7 @@
};
9C79B101188A184A00D465D8 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */;
baseConfigurationReference = 295EA24F3F21109D11BD04E4 /* Pods.debug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -400,7 +409,7 @@
};
9C79B102188A184A00D465D8 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */;
baseConfigurationReference = 5C701019DB74FB49ED98DA43 /* Pods.release.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
Expand Down
10 changes: 10 additions & 0 deletions JCDialPadDemo/JCDialPadDemo/Your Modules/ExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ - (void)viewDidLoad

self.view.buttons = [[JCDialPad defaultButtons] arrayByAddingObjectsFromArray:@[self.twilioButton, self.callButton]];
self.view.delegate = self;
self.view.recipient = @"Press 000 see how it works";

UIImageView* backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallpaper"]];
backgroundView.contentMode = UIViewContentModeScaleAspectFill;
Expand Down Expand Up @@ -67,6 +68,15 @@ - (BOOL)dialPad:(JCDialPad *)dialPad shouldInsertText:(NSString *)text forButton
return YES;
}

- (void)dialPad:(JCDialPad *)dialPad didChanged:(NSString *)rawText
{
if ([rawText isEqualToString:@"000"] == YES) {
dialPad.recipient = @"Daniel KIM";
} else {
dialPad.recipient = @"";
}
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
Expand Down