Skip to content

Commit

Permalink
* Added method to dismiss the currently active notification
Browse files Browse the repository at this point in the history
  • Loading branch information
KrauseFx committed May 24, 2013
1 parent 620dcc5 commit e5ab6fc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Classes/TSMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ typedef enum {
atPosition:(TSMessageNotificationPosition)messagePosition;


/** Fades out the currently displayed notification. If another notification is in the queue,
the next one will be displayed automatically
@return YES if the currently displayed notification could be hidden. NO if no notification
was currently displayed.
*/
+ (BOOL)dismissActiveNotification;



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

Expand Down
18 changes: 18 additions & 0 deletions Classes/TSMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ - (void)fadeInCurrentNotification
{
currentView.center = toPoint;
currentView.alpha = TSMessageViewAlpha;
} completion:^(BOOL finished) {
currentView.messageIsFullyDisplayed = YES;
}];


Expand All @@ -254,6 +256,7 @@ - (void)fadeInCurrentNotification

- (void)fadeOutNotification:(TSMessageView *)currentView
{
currentView.messageIsFullyDisplayed = NO;
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(fadeOutNotification:)
object:currentView];
Expand Down Expand Up @@ -292,6 +295,21 @@ - (void)fadeOutNotification:(TSMessageView *)currentView
}];
}

+ (BOOL)dismissActiveNotification
{
if ([[TSMessage sharedMessage].messages count] == 0) return NO;

dispatch_async(dispatch_get_main_queue(), ^
{
TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0];
if (currentMessage.messageIsFullyDisplayed)
{
[[TSMessage sharedMessage] fadeOutNotification:currentMessage];
}
});
return YES;
}

#pragma mark class Methods to subclass

+ (UIViewController *)defaultViewController
Expand Down
1 change: 1 addition & 0 deletions ExampleProject/Example/TSSecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
- (IBAction)didTapMessage:(id)sender;
- (IBAction)didTapSuccess:(id)sender;
- (IBAction)didTapButtonidsender:(id)sender;
- (IBAction)didTapDismissCurrentMessage:(id)sender;

@end
5 changes: 5 additions & 0 deletions ExampleProject/Example/TSSecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,9 @@ - (IBAction)didTapButtonidsender:(id)sender
atPosition:self.onBottomToggle.on];
}

- (IBAction)didTapDismissCurrentMessage:(id)sender
{
[TSMessage dismissActiveNotification];
}

@end
19 changes: 17 additions & 2 deletions ExampleProject/Example/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@
<action selector="didTapButtonidsender:" destination="3" eventType="touchUpInside" id="ls1-OQ-NgN"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dp9-zc-ECU">
<constraints>
<constraint firstAttribute="width" constant="94" id="F7g-aC-cAn"/>
</constraints>
<fontDescription key="fontDescription" name="Helvetica-Bold" family="Helvetica" pointSize="15"/>
<state key="normal" title="Dismiss">
<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="didTapDismissCurrentMessage:" destination="3" eventType="touchUpInside" id="Sat-xm-rkM"/>
</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 @@ -104,16 +117,18 @@
</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 firstItem="pne-hG-1yy" firstAttribute="leading" secondItem="dp9-zc-ECU" secondAttribute="trailing" constant="8" symbolic="YES" type="default" id="4vs-ax-0fo"/>
<constraint firstItem="dp9-zc-ECU" firstAttribute="baseline" secondItem="pne-hG-1yy" secondAttribute="baseline" type="default" id="8Ln-Vo-oyx"/>
<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 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="dp9-zc-ECU" firstAttribute="leading" secondItem="17" secondAttribute="leading" constant="114" id="R8C-Hl-LLc"/>
<constraint firstItem="hAh-Ka-NMA" firstAttribute="leading" secondItem="zLn-b7-lUs" secondAttribute="leading" type="default" id="Sj2-i2-NcJ"/>
<constraint firstItem="dp9-zc-ECU" firstAttribute="baseline" secondItem="zLn-b7-lUs" secondAttribute="baseline" type="default" id="TMX-P2-mnb"/>
<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"/>
Expand Down
3 changes: 3 additions & 0 deletions Views/TSMessageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
/** The duration of the displayed message. If it is 0.0, it will automatically be calculated */
@property (nonatomic, assign) CGFloat duration;

/** The position of the message (top or bottom) */
@property (nonatomic, assign) TSMessageNotificationPosition messagePosition;

@property (nonatomic, assign) BOOL messageIsFullyDisplayed;

/** Inits the notification view. Do not call this from outside this library.
@param title The title of the notification view
@param content The subtitle/content of the notification view (optional)
Expand Down

0 comments on commit e5ab6fc

Please sign in to comment.