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

Use custom view for TSMessage (model and view) #134

Open
wants to merge 5 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
20 changes: 20 additions & 0 deletions ExampleProject/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

/* Begin PBXBuildFile section */
0C9D527520AF4EAA93E80BC5 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A64AE23935D5499BAF0AC8C1 /* libPods.a */; };
4C67F9E218F6C38700021ADD /* closeIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C67F9E018F6C38700021ADD /* closeIcon.png */; };
4C67F9E318F6C38700021ADD /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4C67F9E118F6C38700021ADD /* [email protected] */; };
4CCFEF4318EF06FF00CDFE92 /* TSMessageCustomItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCFEF4218EF06FF00CDFE92 /* TSMessageCustomItem.m */; };
4CCFEF4618EF09C100CDFE92 /* TSMessageCustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCFEF4518EF09C100CDFE92 /* TSMessageCustomView.m */; };
CA0B97051719CD6800E06F84 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA0B97041719CD6800E06F84 /* UIKit.framework */; };
CA0B97071719CD6800E06F84 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA0B97061719CD6800E06F84 /* Foundation.framework */; };
CA0B97091719CD6800E06F84 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA0B97081719CD6800E06F84 /* CoreGraphics.framework */; };
Expand All @@ -23,6 +27,12 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4C67F9E018F6C38700021ADD /* closeIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = closeIcon.png; sourceTree = "<group>"; };
4C67F9E118F6C38700021ADD /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
4CCFEF4118EF06FF00CDFE92 /* TSMessageCustomItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSMessageCustomItem.h; sourceTree = "<group>"; };
4CCFEF4218EF06FF00CDFE92 /* TSMessageCustomItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageCustomItem.m; sourceTree = "<group>"; };
4CCFEF4418EF09C100CDFE92 /* TSMessageCustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSMessageCustomView.h; sourceTree = "<group>"; };
4CCFEF4518EF09C100CDFE92 /* TSMessageCustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageCustomView.m; sourceTree = "<group>"; };
8B33F75B47A447C8B36A0061 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
A64AE23935D5499BAF0AC8C1 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
CA0B97011719CD6800E06F84 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -98,13 +108,19 @@
CA0B97261719CD6800E06F84 /* TSDemoViewController.h */,
CA0B97271719CD6800E06F84 /* TSDemoViewController.m */,
CA0B970B1719CD6800E06F84 /* Supporting Files */,
4CCFEF4118EF06FF00CDFE92 /* TSMessageCustomItem.h */,
4CCFEF4218EF06FF00CDFE92 /* TSMessageCustomItem.m */,
4CCFEF4418EF09C100CDFE92 /* TSMessageCustomView.h */,
4CCFEF4518EF09C100CDFE92 /* TSMessageCustomView.m */,
);
path = Example;
sourceTree = "<group>";
};
CA0B970B1719CD6800E06F84 /* Supporting Files */ = {
isa = PBXGroup;
children = (
4C67F9E018F6C38700021ADD /* closeIcon.png */,
4C67F9E118F6C38700021ADD /* [email protected] */,
CA0B970C1719CD6800E06F84 /* Example-Info.plist */,
CA0B970D1719CD6800E06F84 /* InfoPlist.strings */,
CA0B97101719CD6800E06F84 /* main.m */,
Expand Down Expand Up @@ -170,8 +186,10 @@
buildActionMask = 2147483647;
files = (
CA0B970F1719CD6800E06F84 /* InfoPlist.strings in Resources */,
4C67F9E318F6C38700021ADD /* [email protected] in Resources */,
CA0B97171719CD6800E06F84 /* Default.png in Resources */,
CA0B97191719CD6800E06F84 /* [email protected] in Resources */,
4C67F9E218F6C38700021ADD /* closeIcon.png in Resources */,
CA0B971B1719CD6800E06F84 /* [email protected] in Resources */,
CA0B971E1719CD6800E06F84 /* MainStoryboard.storyboard in Resources */,
CAA3C9E817C3CD180085E06E /* AlternativeDesign.json in Resources */,
Expand Down Expand Up @@ -204,6 +222,8 @@
files = (
CA0B97111719CD6800E06F84 /* main.m in Sources */,
CA0B97151719CD6800E06F84 /* TSAppDelegate.m in Sources */,
4CCFEF4618EF09C100CDFE92 /* TSMessageCustomView.m in Sources */,
4CCFEF4318EF06FF00CDFE92 /* TSMessageCustomItem.m in Sources */,
CA0B97281719CD6800E06F84 /* TSDemoViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>78E13C39-DCE2-42E8-B56F-F65483531CDC</string>
<string>DAF402E2-1D5F-4FCC-BC4E-54E674A41828</string>
<key>IDESourceControlProjectName</key>
<string>Example</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>A82D8531-0480-4292-B9CA-F43F680C1C78</key>
<string>https://github.com/mRs-/TSMessages.git</string>
<key>2462041E-2250-43D4-B8B0-7C9802F94EB6</key>
<string>https://github.com/XBeg9/TSMessages.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>ExampleProject/Example.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>A82D8531-0480-4292-B9CA-F43F680C1C78</key>
<key>2462041E-2250-43D4-B8B0-7C9802F94EB6</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/mRs-/TSMessages.git</string>
<string>https://github.com/XBeg9/TSMessages.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>A82D8531-0480-4292-B9CA-F43F680C1C78</string>
<string>2462041E-2250-43D4-B8B0-7C9802F94EB6</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>A82D8531-0480-4292-B9CA-F43F680C1C78</string>
<string>2462041E-2250-43D4-B8B0-7C9802F94EB6</string>
<key>IDESourceControlWCCName</key>
<string>TSMessages</string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions ExampleProject/Example/TSDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#import <UIKit/UIKit.h>
#import "TSMessageView.h"

@interface TSDemoViewController : UIViewController <TSMessageViewProtocol>

@interface TSDemoViewController : UIViewController

- (IBAction)didTapError:(id)sender;
- (IBAction)didTapWarning:(id)sender;
Expand All @@ -24,5 +23,6 @@
- (IBAction)didTapText:(id)sender;
- (IBAction)didTapCustomDesign:(id)sender;
- (IBAction)didTapNavbarHidden:(id)sender;
- (IBAction)didTapCustomView:(id)sender;

@end
15 changes: 12 additions & 3 deletions ExampleProject/Example/TSDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "TSDemoViewController.h"
#import "TSMessage.h"
#import "TSMessageView.h"
#import "TSMessageCustomItem.h"

@implementation TSDemoViewController

Expand Down Expand Up @@ -162,9 +163,16 @@ - (IBAction)didTapCustomDesign:(id)sender
}





- (IBAction)didTapCustomView:(id)sender {
TSMessageCustomItem *item = [TSMessageCustomItem itemWithTitle:@"Test" subtitle:@"description" type:TSMessageNotificationTypeSuccess inViewController:self tapHandler:^(TSMessageCustomItem *item) {
NSLog(@"Message did pressed");
} iconHandler:^(TSMessageCustomItem *item) {
NSLog(@"Icon did pressed");
} disclosureView:nil disclosureHandler:^(TSMessageCustomItem *item) {
NSLog(@"Disclosure view did pressed");
}];
[TSMessage showNotificationMessageWithItem:item];
}

- (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewController
{
Expand All @@ -174,4 +182,5 @@ - (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewControlle
- (IBAction)didTapNavbarHidden:(id)sender {
self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
}

@end
25 changes: 25 additions & 0 deletions ExampleProject/Example/TSMessageCustomItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// TSMessageCustomItem.h
// Example
//
// Created by Fedya Skitsko on 4/4/14.
// Copyright (c) 2014 Toursprung. All rights reserved.
//

#import "TSMessageItem.h"

@interface TSMessageCustomItem : TSMessageItem

@property (copy, readwrite, nonatomic) void (^disclosureSelectionHandler)(id item);
@property (copy, readwrite, nonatomic) UIView *disclosureView;

+ (instancetype)itemWithTitle:(NSString *)title
subtitle:(NSString *)subtitle
type:(TSMessageNotificationType)notificationType
inViewController:(UIViewController *)viewController
tapHandler:(void(^)(TSMessageCustomItem *item))tapHandler
iconHandler:(void(^)(TSMessageCustomItem *item))iconHandler
disclosureView:(UIView *)disclosureView
disclosureHandler:(void(^)(TSMessageCustomItem *item))disclosureHandler;

@end
34 changes: 34 additions & 0 deletions ExampleProject/Example/TSMessageCustomItem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// TSMessageCustomItem.m
// Example
//
// Created by Fedya Skitsko on 4/4/14.
// Copyright (c) 2014 Toursprung. All rights reserved.
//

#import "TSMessageCustomItem.h"
#import "TSMessageCustomView.h"

@implementation TSMessageCustomItem

+ (instancetype)itemWithTitle:(NSString *)title
subtitle:(NSString *)subtitle
type:(TSMessageNotificationType)notificationType
inViewController:(UIViewController *)viewController
tapHandler:(void(^)(TSMessageCustomItem *item))tapHandler
iconHandler:(void(^)(TSMessageCustomItem *item))iconHandler
disclosureView:(UIView *)disclosureView
disclosureHandler:(void(^)(TSMessageCustomItem *item))disclosureHandler {

TSMessageCustomItem *item = [[TSMessageCustomItem alloc] initWithTitle:title subtitle:subtitle image:[UIImage imageNamed:@"closeIcon"] type:notificationType duration:3.0 inViewController:viewController atPosition:TSMessageNotificationPositionBottom canBeDismissedByUser:YES tapHandler:tapHandler iconHandler:iconHandler];
item.disclosureView = disclosureView;
item.disclosureSelectionHandler = disclosureHandler;

return item;
}

- (Class)classForView {
return [TSMessageCustomView class];
}

@end
16 changes: 16 additions & 0 deletions ExampleProject/Example/TSMessageCustomView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TSMessageCustomView.h
// Example
//
// Created by Fedya Skitsko on 4/4/14.
// Copyright (c) 2014 Toursprung. All rights reserved.
//

#import "TSMessageView.h"
#import "TSMessageCustomItem.h"

@interface TSMessageCustomView : TSMessageView

@property (nonatomic, strong) TSMessageCustomItem *item;

@end
76 changes: 76 additions & 0 deletions ExampleProject/Example/TSMessageCustomView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// TSMessageCustomView.m
// Example
//
// Created by Fedya Skitsko on 4/4/14.
// Copyright (c) 2014 Toursprung. All rights reserved.
//

#import "TSMessageCustomView.h"

@interface TSMessageCustomView()

@property (nonatomic) UIButton *closeButton;

@end

@implementation TSMessageCustomView

#pragma mark - Setters / Getters

- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setImage:[UIImage imageNamed:@"closeIcon"] forState:UIControlStateNormal];
_closeButton.frame = CGRectMake(0, 0, 20, 20);
[_closeButton addTarget:self action:@selector(closeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}

#pragma mark - Initialization

- (id)initWithItem:(TSMessageItem *)item
{
if (self = [super initWithItem:item])
{
[self setup];
}
return self;
}

+ (CGFloat)heightWithItem:(TSMessageCustomItem *)item {
CGFloat calculatedHeight = [super heightWithItem:item];

return calculatedHeight;
}

#pragma mark - Lifecycle

- (void)setup {
[super setup];

[self.iconImageView removeFromSuperview];

self.textSpaceLeft = 17.5f;
[self addSubview:self.closeButton];
self.alpha = 0.9f;
}

-(void)layoutSubviews {
[super layoutSubviews];

_closeButton.frame = CGRectMake(CGRectGetWidth(self.frame) - self.textSpaceLeft - CGRectGetWidth(_closeButton.frame), roundf((CGRectGetHeight(self.frame) - CGRectGetHeight(_closeButton.frame))/2), _closeButton.frame.size.width, _closeButton.frame.size.height);
}

#pragma mark - Actions

- (void)closeButtonPressed {
NSLog(@"closeButtonPressed");

if (self.item.disclosureSelectionHandler) {
self.item.disclosureSelectionHandler(self.item);
}
}

@end
Binary file added ExampleProject/Example/closeIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExampleProject/Example/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions ExampleProject/Example/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="udN-k3-MmQ">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="udN-k3-MmQ">
<dependencies>
<deployment defaultVersion="1552" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--Demo View Controller - Second-->
Expand Down Expand Up @@ -98,6 +98,15 @@
<action selector="didTapBottom:" destination="3" eventType="touchUpInside" id="dd2-RK-6oH"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="t4r-6f-ntc">
<rect key="frame" x="20" y="292" width="89" height="30"/>
<state key="normal" title="Custom view">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="didTapCustomView:" destination="3" eventType="touchUpInside" id="UTc-s4-i9V"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cQR-ea-6Bc">
<rect key="frame" x="220" y="410" width="80" height="30"/>
<state key="normal" title="Long">
Expand Down Expand Up @@ -249,4 +258,4 @@
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
</document>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ExampleProject/Pods/Headers/TSMessages/TSMessageItem.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading