Skip to content

Commit

Permalink
Merge branch 'master' of github.com:toursprung/TSMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
KrauseFx committed May 8, 2013
2 parents f336c83 + c98c6cf commit 9f8bceb
Show file tree
Hide file tree
Showing 27 changed files with 677 additions and 625 deletions.
21 changes: 21 additions & 0 deletions Classes/TSMessage.h
Expand Up @@ -96,6 +96,27 @@ typedef enum {
withCallback:(void (^)())callback
atPosition:(TSMessageNotificationPosition)messagePosition;

/** Shows a notification message in a specific view controller
@param viewController The view controller to show the notification in.
@param title The title of the notification view
@param message The message that is displayed underneath the title
@param type The notification type (Message, Warning, Error, Success)
@param duration The duration of the notification being displayed
@param callback The block that should be executed, when the user tapped on the message
@param buttonTitle The title for button (optional)
@param buttonCallback The block that should be executed, when the user tapped on the button
@param position The position of the message on the screen
*/
+ (void)showNotificationInViewController:(UIViewController *)viewController
withTitle:(NSString *)title
withMessage:(NSString *)message
withType:(TSMessageNotificationType)type
withDuration:(NSTimeInterval)duration
withCallback:(void (^)())callback
withButtonTitle:(NSString *)buttonTitle
withButtonCallback:(void (^)())buttonCallback
atPosition:(TSMessageNotificationPosition)messagePosition;


/** Shows a predefined error message, that is displayed, when this action requires an internet connection */
+ (void)showInternetError;
Expand Down
36 changes: 33 additions & 3 deletions Classes/TSMessage.m
Expand Up @@ -105,6 +105,28 @@ + (void)showNotificationInViewController:(UIViewController *)viewController
withDuration:(NSTimeInterval)duration
withCallback:(void (^)())callback
atPosition:(TSMessageNotificationPosition)messagePosition
{
[self showNotificationInViewController:viewController
withTitle:title
withMessage:message
withType:type
withDuration:duration
withCallback:callback
withButtonTitle:nil
withButtonCallback:nil
atPosition:messagePosition];
}


+ (void)showNotificationInViewController:(UIViewController *)viewController
withTitle:(NSString *)title
withMessage:(NSString *)message
withType:(TSMessageNotificationType)type
withDuration:(NSTimeInterval)duration
withCallback:(void (^)())callback
withButtonTitle:(NSString *)buttonTitle
withButtonCallback:(void (^)())buttonCallback
atPosition:(TSMessageNotificationPosition)messagePosition
{
for (TSMessageView *n in [TSMessage sharedMessage].messages)
{
Expand All @@ -121,6 +143,8 @@ + (void)showNotificationInViewController:(UIViewController *)viewController
withDuration:duration
inViewController:viewController
withCallback:callback
withButtonTitle:buttonTitle
withButtonCallback:buttonCallback
atPosition:messagePosition];

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

- (void)fadeInCurrentNotification
{
if ([self.messages count] == 0) return;

notificationActive = YES;

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

CGPoint toPoint;
if (currentView.messsagePosition == TSMessageNotificationPositionTop)
if (currentView.messagePosition == TSMessageNotificationPositionTop)
{
toPoint = CGPointMake(currentView.center.x,
[[self class] navigationbarBottomOfViewController:currentView.viewController] + verticalOffset + CGRectGetHeight(currentView.frame) / 2.0);
Expand Down Expand Up @@ -233,7 +259,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView
object:currentView];

CGPoint fadeOutToPoint;
if (currentView.messsagePosition == TSMessageNotificationPositionTop)
if (currentView.messagePosition == TSMessageNotificationPositionTop)
{
fadeOutToPoint = CGPointMake(currentView.center.x, -CGRectGetHeight(currentView.frame) / 2.0);;
}
Expand All @@ -252,7 +278,11 @@ - (void)fadeOutNotification:(TSMessageView *)currentView
{
[currentView removeFromSuperview];

[self.messages removeObjectAtIndex:0];
if ([self.messages count] > 0)
{
[self.messages removeObjectAtIndex:0];
}

notificationActive = NO;

if ([self.messages count] > 0)
Expand Down
2 changes: 2 additions & 0 deletions ExampleProject/Example/TSSecondViewController.h
Expand Up @@ -12,11 +12,13 @@

@property (weak, nonatomic) IBOutlet UISwitch *descriptionToggle;
@property (weak, nonatomic) IBOutlet UISwitch *longDurationToggle;
@property (weak, nonatomic) IBOutlet UISwitch *onBottomToggle;


- (IBAction)didTapError:(id)sender;
- (IBAction)didTapWarning:(id)sender;
- (IBAction)didTapMessage:(id)sender;
- (IBAction)didTapSuccess:(id)sender;
- (IBAction)didTapButtonidsender:(id)sender;

@end
41 changes: 37 additions & 4 deletions ExampleProject/Example/TSSecondViewController.m
Expand Up @@ -20,6 +20,7 @@ - (IBAction)didTapError:(id)sender
NSString *notificationDescription = (self.descriptionToggle.on ?
NSLocalizedString(@"The internet connection seems to be down. Please check that!", nil) :
nil);

CGFloat duration = (self.longDurationToggle.on ? TSSecondViewControllerLongDuration : 0.0);

[TSMessage showNotificationInViewController:self
Expand All @@ -32,7 +33,8 @@ - (IBAction)didTapError:(id)sender
withTitle:NSLocalizedString(@"You dismisses it", nil)
withMessage:nil
withType:TSMessageNotificationTypeSuccess];
}];
}
atPosition:self.onBottomToggle.on];
}

- (IBAction)didTapWarning:(id)sender
Expand All @@ -48,7 +50,9 @@ - (IBAction)didTapWarning:(id)sender
withTitle:notificationTitle
withMessage:notificationDescription
withType:TSMessageNotificationTypeWarning
withDuration:duration];
withDuration:duration
withCallback:nil
atPosition:self.onBottomToggle.on];
}

- (IBAction)didTapMessage:(id)sender
Expand All @@ -64,7 +68,9 @@ - (IBAction)didTapMessage:(id)sender
withTitle:notificationTitle
withMessage:notificationDescription
withType:TSMessageNotificationTypeMessage
withDuration:duration];
withDuration:duration
withCallback:nil
atPosition:self.onBottomToggle.on];
}

- (IBAction)didTapSuccess:(id)sender
Expand All @@ -80,7 +86,34 @@ - (IBAction)didTapSuccess:(id)sender
withTitle:notificationTitle
withMessage:notificationDescription
withType:TSMessageNotificationTypeSuccess
withDuration:duration];
withDuration:duration
withCallback:nil
atPosition:self.onBottomToggle.on];
}

- (IBAction)didTapButtonidsender:(id)sender
{
NSString *notificationTitle = NSLocalizedString(@"New version available", nil);
NSString *notificationDescription = (self.descriptionToggle.on ?
NSLocalizedString(@"Please update our app. This is some neutral notification.", nil) :
nil);

CGFloat duration = (self.longDurationToggle.on ? TSSecondViewControllerLongDuration : 0.0);

[TSMessage showNotificationInViewController:self
withTitle:notificationTitle
withMessage:notificationDescription
withType:TSMessageNotificationTypeMessage
withDuration:duration
withCallback:nil
withButtonTitle:@"Update" // that's the title of the added button
withButtonCallback:^{
[TSMessage showNotificationInViewController:self
withTitle:NSLocalizedString(@"Button tapped!", nil)
withMessage:nil
withType:TSMessageNotificationTypeSuccess];
}
atPosition:self.onBottomToggle.on];
}

@end
36 changes: 33 additions & 3 deletions ExampleProject/Example/en.lproj/MainStoryboard.storyboard
Expand Up @@ -67,6 +67,19 @@
<action selector="didTapSuccess:" destination="3" eventType="touchUpInside" id="rWm-Jy-YTy"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zxX-aS-md3">
<constraints>
<constraint firstAttribute="width" constant="94" id="pbV-pu-MEc"/>
</constraints>
<fontDescription key="fontDescription" name="Helvetica-Bold" family="Helvetica" pointSize="15"/>
<state key="normal" title="With Button">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="didTapButtonidsender:" destination="3" eventType="touchUpInside" id="ls1-OQ-NgN"/>
</connections>
</button>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jym-Ua-n2C"/>
<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">
<constraints>
Expand All @@ -82,35 +95,49 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="ZMy-CK-HBD"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="On bottom" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dhC-fE-thf">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="pne-hG-1yy" firstAttribute="baseline" secondItem="zLn-b7-lUs" secondAttribute="baseline" type="default" id="0Ng-pt-uug"/>
<constraint firstItem="zLn-b7-lUs" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="30" id="21Z-az-IcV"/>
<constraint firstAttribute="bottom" secondItem="mRD-99-HfF" secondAttribute="bottom" constant="29" id="4KU-XY-45n"/>
<constraint firstItem="hxl-lo-RFJ" firstAttribute="baseline" secondItem="hAh-Ka-NMA" secondAttribute="baseline" type="default" id="8Aq-nS-eVz"/>
<constraint firstItem="ZMy-CK-HBD" firstAttribute="top" secondItem="yRk-dI-W7x" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="9do-Fs-GPw"/>
<constraint firstAttribute="trailing" secondItem="pne-hG-1yy" secondAttribute="trailing" constant="31" id="Ckh-NS-Qam"/>
<constraint firstAttribute="trailing" secondItem="mRD-99-HfF" secondAttribute="trailing" constant="9" id="Ieb-rT-oW7"/>
<constraint firstItem="dhC-fE-thf" firstAttribute="top" secondItem="yRk-dI-W7x" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="DOY-wr-SIA"/>
<constraint firstItem="mRD-99-HfF" firstAttribute="leading" secondItem="Jym-Ua-n2C" secondAttribute="leading" type="default" id="Jg3-kp-JfQ"/>
<constraint firstItem="yRk-dI-W7x" firstAttribute="trailing" secondItem="FPK-Wl-rdR" secondAttribute="trailing" type="default" id="KAM-F1-5NQ"/>
<constraint firstItem="hAh-Ka-NMA" firstAttribute="top" secondItem="zLn-b7-lUs" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="NtF-hL-mCL"/>
<constraint firstItem="ZMy-CK-HBD" firstAttribute="leading" secondItem="mRD-99-HfF" secondAttribute="leading" type="default" id="O2O-jE-jMb"/>
<constraint firstItem="hAh-Ka-NMA" firstAttribute="leading" secondItem="zLn-b7-lUs" secondAttribute="leading" type="default" id="Sj2-i2-NcJ"/>
<constraint firstItem="zxX-aS-md3" firstAttribute="baseline" secondItem="hAh-Ka-NMA" secondAttribute="baseline" type="default" id="Wfu-ui-kpW"/>
<constraint firstItem="hxl-lo-RFJ" firstAttribute="leading" secondItem="pne-hG-1yy" secondAttribute="leading" type="default" id="XAh-cB-KET"/>
<constraint firstItem="FPK-Wl-rdR" firstAttribute="top" secondItem="hAh-Ka-NMA" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="ZWR-6Y-k4Z"/>
<constraint firstItem="dhC-fE-thf" firstAttribute="trailing" secondItem="yRk-dI-W7x" secondAttribute="trailing" type="default" id="Zyb-ml-AWg"/>
<constraint firstItem="yRk-dI-W7x" firstAttribute="top" secondItem="FPK-Wl-rdR" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="cEK-7v-fge"/>
<constraint firstItem="mRD-99-HfF" firstAttribute="top" secondItem="FPK-Wl-rdR" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="fWr-aj-GiM"/>
<constraint firstItem="Jym-Ua-n2C" firstAttribute="top" secondItem="hxl-lo-RFJ" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="hYe-jW-8wv"/>
<constraint firstItem="hAh-Ka-NMA" firstAttribute="trailing" secondItem="zLn-b7-lUs" secondAttribute="trailing" type="default" id="ibP-5N-5Ux"/>
<constraint firstItem="hxl-lo-RFJ" firstAttribute="trailing" secondItem="pne-hG-1yy" secondAttribute="trailing" type="default" id="kYf-Q6-6Ht"/>
<constraint firstAttribute="trailing" secondItem="Jym-Ua-n2C" secondAttribute="trailing" constant="9" id="lz6-UD-e8x"/>
<constraint firstItem="yRk-dI-W7x" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="njH-Eq-WVY"/>
<constraint firstItem="zLn-b7-lUs" firstAttribute="top" secondItem="17" secondAttribute="top" constant="83" id="qSb-jb-8PK"/>
<constraint firstItem="zxX-aS-md3" firstAttribute="centerX" secondItem="17" secondAttribute="centerX" type="default" id="qjr-Ys-6q4"/>
<constraint firstItem="FPK-Wl-rdR" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="tDB-Oa-POw"/>
<constraint firstItem="zxX-aS-md3" firstAttribute="baseline" secondItem="hxl-lo-RFJ" secondAttribute="baseline" type="default" id="wdC-mc-FUR"/>
<constraint firstItem="dhC-fE-thf" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="y7N-AF-Xnj"/>
</constraints>
</view>
<tabBarItem key="tabBarItem" title="Second" image="second" id="6"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="descriptionToggle" destination="Jym-Ua-n2C" id="Yqd-zD-AtZ"/>
<outlet property="longDurationToggle" destination="mRD-99-HfF" id="OWe-0n-0CY"/>
<outlet property="onBottomToggle" destination="ZMy-CK-HBD" id="ioz-3J-iwb"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="12" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -146,11 +173,14 @@
<class className="TSSecondViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/TSSecondViewController.h"/>
<relationships>
<relationship kind="action" name="didTapButtonidsender:"/>
<relationship kind="action" name="didTapError:"/>
<relationship kind="action" name="didTapMessage:"/>
<relationship kind="action" name="didTapSuccess:"/>
<relationship kind="action" name="didTapWarning:"/>
<relationship kind="outlet" name="descriptionToggle" candidateClass="UISwitch"/>
<relationship kind="outlet" name="longDurationToggle" candidateClass="UISwitch"/>
<relationship kind="outlet" name="onBottomToggle" candidateClass="UISwitch"/>
</relationships>
</class>
</classes>
Expand Down

0 comments on commit 9f8bceb

Please sign in to comment.