Skip to content

Commit 9f8bceb

Browse files
committed
Merge branch 'master' of github.com:toursprung/TSMessages
2 parents f336c83 + c98c6cf commit 9f8bceb

27 files changed

+677
-625
lines changed

Classes/TSMessage.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ typedef enum {
9696
withCallback:(void (^)())callback
9797
atPosition:(TSMessageNotificationPosition)messagePosition;
9898

99+
/** Shows a notification message in a specific view controller
100+
@param viewController The view controller to show the notification in.
101+
@param title The title of the notification view
102+
@param message The message that is displayed underneath the title
103+
@param type The notification type (Message, Warning, Error, Success)
104+
@param duration The duration of the notification being displayed
105+
@param callback The block that should be executed, when the user tapped on the message
106+
@param buttonTitle The title for button (optional)
107+
@param buttonCallback The block that should be executed, when the user tapped on the button
108+
@param position The position of the message on the screen
109+
*/
110+
+ (void)showNotificationInViewController:(UIViewController *)viewController
111+
withTitle:(NSString *)title
112+
withMessage:(NSString *)message
113+
withType:(TSMessageNotificationType)type
114+
withDuration:(NSTimeInterval)duration
115+
withCallback:(void (^)())callback
116+
withButtonTitle:(NSString *)buttonTitle
117+
withButtonCallback:(void (^)())buttonCallback
118+
atPosition:(TSMessageNotificationPosition)messagePosition;
119+
99120

100121
/** Shows a predefined error message, that is displayed, when this action requires an internet connection */
101122
+ (void)showInternetError;

Classes/TSMessage.m

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ + (void)showNotificationInViewController:(UIViewController *)viewController
105105
withDuration:(NSTimeInterval)duration
106106
withCallback:(void (^)())callback
107107
atPosition:(TSMessageNotificationPosition)messagePosition
108+
{
109+
[self showNotificationInViewController:viewController
110+
withTitle:title
111+
withMessage:message
112+
withType:type
113+
withDuration:duration
114+
withCallback:callback
115+
withButtonTitle:nil
116+
withButtonCallback:nil
117+
atPosition:messagePosition];
118+
}
119+
120+
121+
+ (void)showNotificationInViewController:(UIViewController *)viewController
122+
withTitle:(NSString *)title
123+
withMessage:(NSString *)message
124+
withType:(TSMessageNotificationType)type
125+
withDuration:(NSTimeInterval)duration
126+
withCallback:(void (^)())callback
127+
withButtonTitle:(NSString *)buttonTitle
128+
withButtonCallback:(void (^)())buttonCallback
129+
atPosition:(TSMessageNotificationPosition)messagePosition
108130
{
109131
for (TSMessageView *n in [TSMessage sharedMessage].messages)
110132
{
@@ -121,6 +143,8 @@ + (void)showNotificationInViewController:(UIViewController *)viewController
121143
withDuration:duration
122144
inViewController:viewController
123145
withCallback:callback
146+
withButtonTitle:buttonTitle
147+
withButtonCallback:buttonCallback
124148
atPosition:messagePosition];
125149

126150
[[TSMessage sharedMessage].messages addObject:v];
@@ -161,6 +185,8 @@ - (id)init
161185

162186
- (void)fadeInCurrentNotification
163187
{
188+
if ([self.messages count] == 0) return;
189+
164190
notificationActive = YES;
165191

166192
TSMessageView *currentView = [self.messages objectAtIndex:0];
@@ -195,7 +221,7 @@ - (void)fadeInCurrentNotification
195221
}
196222

197223
CGPoint toPoint;
198-
if (currentView.messsagePosition == TSMessageNotificationPositionTop)
224+
if (currentView.messagePosition == TSMessageNotificationPositionTop)
199225
{
200226
toPoint = CGPointMake(currentView.center.x,
201227
[[self class] navigationbarBottomOfViewController:currentView.viewController] + verticalOffset + CGRectGetHeight(currentView.frame) / 2.0);
@@ -233,7 +259,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView
233259
object:currentView];
234260

235261
CGPoint fadeOutToPoint;
236-
if (currentView.messsagePosition == TSMessageNotificationPositionTop)
262+
if (currentView.messagePosition == TSMessageNotificationPositionTop)
237263
{
238264
fadeOutToPoint = CGPointMake(currentView.center.x, -CGRectGetHeight(currentView.frame) / 2.0);;
239265
}
@@ -252,7 +278,11 @@ - (void)fadeOutNotification:(TSMessageView *)currentView
252278
{
253279
[currentView removeFromSuperview];
254280

255-
[self.messages removeObjectAtIndex:0];
281+
if ([self.messages count] > 0)
282+
{
283+
[self.messages removeObjectAtIndex:0];
284+
}
285+
256286
notificationActive = NO;
257287

258288
if ([self.messages count] > 0)

ExampleProject/Example/TSSecondViewController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
@property (weak, nonatomic) IBOutlet UISwitch *descriptionToggle;
1414
@property (weak, nonatomic) IBOutlet UISwitch *longDurationToggle;
15+
@property (weak, nonatomic) IBOutlet UISwitch *onBottomToggle;
1516

1617

1718
- (IBAction)didTapError:(id)sender;
1819
- (IBAction)didTapWarning:(id)sender;
1920
- (IBAction)didTapMessage:(id)sender;
2021
- (IBAction)didTapSuccess:(id)sender;
22+
- (IBAction)didTapButtonidsender:(id)sender;
2123

2224
@end

ExampleProject/Example/TSSecondViewController.m

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ - (IBAction)didTapError:(id)sender
2020
NSString *notificationDescription = (self.descriptionToggle.on ?
2121
NSLocalizedString(@"The internet connection seems to be down. Please check that!", nil) :
2222
nil);
23+
2324
CGFloat duration = (self.longDurationToggle.on ? TSSecondViewControllerLongDuration : 0.0);
2425

2526
[TSMessage showNotificationInViewController:self
@@ -32,7 +33,8 @@ - (IBAction)didTapError:(id)sender
3233
withTitle:NSLocalizedString(@"You dismisses it", nil)
3334
withMessage:nil
3435
withType:TSMessageNotificationTypeSuccess];
35-
}];
36+
}
37+
atPosition:self.onBottomToggle.on];
3638
}
3739

3840
- (IBAction)didTapWarning:(id)sender
@@ -48,7 +50,9 @@ - (IBAction)didTapWarning:(id)sender
4850
withTitle:notificationTitle
4951
withMessage:notificationDescription
5052
withType:TSMessageNotificationTypeWarning
51-
withDuration:duration];
53+
withDuration:duration
54+
withCallback:nil
55+
atPosition:self.onBottomToggle.on];
5256
}
5357

5458
- (IBAction)didTapMessage:(id)sender
@@ -64,7 +68,9 @@ - (IBAction)didTapMessage:(id)sender
6468
withTitle:notificationTitle
6569
withMessage:notificationDescription
6670
withType:TSMessageNotificationTypeMessage
67-
withDuration:duration];
71+
withDuration:duration
72+
withCallback:nil
73+
atPosition:self.onBottomToggle.on];
6874
}
6975

7076
- (IBAction)didTapSuccess:(id)sender
@@ -80,7 +86,34 @@ - (IBAction)didTapSuccess:(id)sender
8086
withTitle:notificationTitle
8187
withMessage:notificationDescription
8288
withType:TSMessageNotificationTypeSuccess
83-
withDuration:duration];
89+
withDuration:duration
90+
withCallback:nil
91+
atPosition:self.onBottomToggle.on];
92+
}
93+
94+
- (IBAction)didTapButtonidsender:(id)sender
95+
{
96+
NSString *notificationTitle = NSLocalizedString(@"New version available", nil);
97+
NSString *notificationDescription = (self.descriptionToggle.on ?
98+
NSLocalizedString(@"Please update our app. This is some neutral notification.", nil) :
99+
nil);
100+
101+
CGFloat duration = (self.longDurationToggle.on ? TSSecondViewControllerLongDuration : 0.0);
102+
103+
[TSMessage showNotificationInViewController:self
104+
withTitle:notificationTitle
105+
withMessage:notificationDescription
106+
withType:TSMessageNotificationTypeMessage
107+
withDuration:duration
108+
withCallback:nil
109+
withButtonTitle:@"Update" // that's the title of the added button
110+
withButtonCallback:^{
111+
[TSMessage showNotificationInViewController:self
112+
withTitle:NSLocalizedString(@"Button tapped!", nil)
113+
withMessage:nil
114+
withType:TSMessageNotificationTypeSuccess];
115+
}
116+
atPosition:self.onBottomToggle.on];
84117
}
85118

86119
@end

ExampleProject/Example/en.lproj/MainStoryboard.storyboard

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@
6767
<action selector="didTapSuccess:" destination="3" eventType="touchUpInside" id="rWm-Jy-YTy"/>
6868
</connections>
6969
</button>
70+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zxX-aS-md3">
71+
<constraints>
72+
<constraint firstAttribute="width" constant="94" id="pbV-pu-MEc"/>
73+
</constraints>
74+
<fontDescription key="fontDescription" name="Helvetica-Bold" family="Helvetica" pointSize="15"/>
75+
<state key="normal" title="With Button">
76+
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
77+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
78+
</state>
79+
<connections>
80+
<action selector="didTapButtonidsender:" destination="3" eventType="touchUpInside" id="ls1-OQ-NgN"/>
81+
</connections>
82+
</button>
7083
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jym-Ua-n2C"/>
7184
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Show detailed description?" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FPK-Wl-rdR">
7285
<constraints>
@@ -82,35 +95,49 @@
8295
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
8396
<nil key="highlightedColor"/>
8497
</label>
98+
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="ZMy-CK-HBD"/>
99+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="On bottom" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dhC-fE-thf">
100+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
101+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
102+
<nil key="highlightedColor"/>
103+
</label>
85104
</subviews>
86105
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
87106
<constraints>
88107
<constraint firstItem="pne-hG-1yy" firstAttribute="baseline" secondItem="zLn-b7-lUs" secondAttribute="baseline" type="default" id="0Ng-pt-uug"/>
89108
<constraint firstItem="zLn-b7-lUs" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="30" id="21Z-az-IcV"/>
90-
<constraint firstAttribute="bottom" secondItem="mRD-99-HfF" secondAttribute="bottom" constant="29" id="4KU-XY-45n"/>
91-
<constraint firstItem="hxl-lo-RFJ" firstAttribute="baseline" secondItem="hAh-Ka-NMA" secondAttribute="baseline" type="default" id="8Aq-nS-eVz"/>
109+
<constraint firstItem="ZMy-CK-HBD" firstAttribute="top" secondItem="yRk-dI-W7x" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="9do-Fs-GPw"/>
92110
<constraint firstAttribute="trailing" secondItem="pne-hG-1yy" secondAttribute="trailing" constant="31" id="Ckh-NS-Qam"/>
93-
<constraint firstAttribute="trailing" secondItem="mRD-99-HfF" secondAttribute="trailing" constant="9" id="Ieb-rT-oW7"/>
111+
<constraint firstItem="dhC-fE-thf" firstAttribute="top" secondItem="yRk-dI-W7x" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="DOY-wr-SIA"/>
94112
<constraint firstItem="mRD-99-HfF" firstAttribute="leading" secondItem="Jym-Ua-n2C" secondAttribute="leading" type="default" id="Jg3-kp-JfQ"/>
95113
<constraint firstItem="yRk-dI-W7x" firstAttribute="trailing" secondItem="FPK-Wl-rdR" secondAttribute="trailing" type="default" id="KAM-F1-5NQ"/>
96114
<constraint firstItem="hAh-Ka-NMA" firstAttribute="top" secondItem="zLn-b7-lUs" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="NtF-hL-mCL"/>
115+
<constraint firstItem="ZMy-CK-HBD" firstAttribute="leading" secondItem="mRD-99-HfF" secondAttribute="leading" type="default" id="O2O-jE-jMb"/>
97116
<constraint firstItem="hAh-Ka-NMA" firstAttribute="leading" secondItem="zLn-b7-lUs" secondAttribute="leading" type="default" id="Sj2-i2-NcJ"/>
117+
<constraint firstItem="zxX-aS-md3" firstAttribute="baseline" secondItem="hAh-Ka-NMA" secondAttribute="baseline" type="default" id="Wfu-ui-kpW"/>
98118
<constraint firstItem="hxl-lo-RFJ" firstAttribute="leading" secondItem="pne-hG-1yy" secondAttribute="leading" type="default" id="XAh-cB-KET"/>
99119
<constraint firstItem="FPK-Wl-rdR" firstAttribute="top" secondItem="hAh-Ka-NMA" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="ZWR-6Y-k4Z"/>
120+
<constraint firstItem="dhC-fE-thf" firstAttribute="trailing" secondItem="yRk-dI-W7x" secondAttribute="trailing" type="default" id="Zyb-ml-AWg"/>
100121
<constraint firstItem="yRk-dI-W7x" firstAttribute="top" secondItem="FPK-Wl-rdR" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="cEK-7v-fge"/>
101122
<constraint firstItem="mRD-99-HfF" firstAttribute="top" secondItem="FPK-Wl-rdR" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="fWr-aj-GiM"/>
102123
<constraint firstItem="Jym-Ua-n2C" firstAttribute="top" secondItem="hxl-lo-RFJ" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="hYe-jW-8wv"/>
103124
<constraint firstItem="hAh-Ka-NMA" firstAttribute="trailing" secondItem="zLn-b7-lUs" secondAttribute="trailing" type="default" id="ibP-5N-5Ux"/>
104125
<constraint firstItem="hxl-lo-RFJ" firstAttribute="trailing" secondItem="pne-hG-1yy" secondAttribute="trailing" type="default" id="kYf-Q6-6Ht"/>
126+
<constraint firstAttribute="trailing" secondItem="Jym-Ua-n2C" secondAttribute="trailing" constant="9" id="lz6-UD-e8x"/>
105127
<constraint firstItem="yRk-dI-W7x" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="njH-Eq-WVY"/>
128+
<constraint firstItem="zLn-b7-lUs" firstAttribute="top" secondItem="17" secondAttribute="top" constant="83" id="qSb-jb-8PK"/>
129+
<constraint firstItem="zxX-aS-md3" firstAttribute="centerX" secondItem="17" secondAttribute="centerX" type="default" id="qjr-Ys-6q4"/>
106130
<constraint firstItem="FPK-Wl-rdR" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="tDB-Oa-POw"/>
131+
<constraint firstItem="zxX-aS-md3" firstAttribute="baseline" secondItem="hxl-lo-RFJ" secondAttribute="baseline" type="default" id="wdC-mc-FUR"/>
132+
<constraint firstItem="dhC-fE-thf" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="y7N-AF-Xnj"/>
107133
</constraints>
108134
</view>
109135
<tabBarItem key="tabBarItem" title="Second" image="second" id="6"/>
110136
<simulatedScreenMetrics key="simulatedDestinationMetrics"/>
111137
<connections>
112138
<outlet property="descriptionToggle" destination="Jym-Ua-n2C" id="Yqd-zD-AtZ"/>
113139
<outlet property="longDurationToggle" destination="mRD-99-HfF" id="OWe-0n-0CY"/>
140+
<outlet property="onBottomToggle" destination="ZMy-CK-HBD" id="ioz-3J-iwb"/>
114141
</connections>
115142
</viewController>
116143
<placeholder placeholderIdentifier="IBFirstResponder" id="12" sceneMemberID="firstResponder"/>
@@ -146,11 +173,14 @@
146173
<class className="TSSecondViewController" superclassName="UIViewController">
147174
<source key="sourceIdentifier" type="project" relativePath="./Classes/TSSecondViewController.h"/>
148175
<relationships>
176+
<relationship kind="action" name="didTapButtonidsender:"/>
149177
<relationship kind="action" name="didTapError:"/>
150178
<relationship kind="action" name="didTapMessage:"/>
151179
<relationship kind="action" name="didTapSuccess:"/>
152180
<relationship kind="action" name="didTapWarning:"/>
153181
<relationship kind="outlet" name="descriptionToggle" candidateClass="UISwitch"/>
182+
<relationship kind="outlet" name="longDurationToggle" candidateClass="UISwitch"/>
183+
<relationship kind="outlet" name="onBottomToggle" candidateClass="UISwitch"/>
154184
</relationships>
155185
</class>
156186
</classes>

0 commit comments

Comments
 (0)