Skip to content

Commit

Permalink
Add new option for the Toast that show the toast view forever.
Browse files Browse the repository at this point in the history
  • Loading branch information
HituziANDO committed Mar 25, 2020
1 parent 8f9b255 commit 44b4a69
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 19 deletions.
2 changes: 1 addition & 1 deletion MKAPopupKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MKAPopupKit"
s.version = "2.1.0"
s.version = "2.2.0"
s.summary = "Simple and customizable popup view."
s.description = <<-DESC
MKAPopupKit is simple and customizable popup view for iOS.
Expand Down
4 changes: 2 additions & 2 deletions MKAPopupKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.2;
MARKETING_VERSION = 2.2.0;
PRODUCT_BUNDLE_IDENTIFIER = jp.hituzi.MKAPopupKit;
PRODUCT_NAME = MKAPopupKit;
SKIP_INSTALL = YES;
Expand All @@ -366,7 +366,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.2;
MARKETING_VERSION = 2.2.0;
PRODUCT_BUNDLE_IDENTIFIER = jp.hituzi.MKAPopupKit;
PRODUCT_NAME = MKAPopupKit;
SKIP_INSTALL = YES;
Expand Down
2 changes: 1 addition & 1 deletion MKAPopupKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
23 changes: 21 additions & 2 deletions MKAPopupKit/MKAToast.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,23 @@ UIKIT_EXTERN const CGFloat MKAToastDefaultHeight;
/**
* A default short display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastShortTime;
UIKIT_EXTERN const NSTimeInterval MKAToastShortTime DEPRECATED_MSG_ATTRIBUTE("Use `MKAToastTimeShort` instead.");
/**
* A default long display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;
UIKIT_EXTERN const NSTimeInterval MKAToastLongTime DEPRECATED_MSG_ATTRIBUTE("Use `MKAToastTimeLong` instead.");
/**
* A default short display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastTimeShort;
/**
* A default long display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastTimeLong;
/**
* A toast view is displayed forever (until `hide` method is called).
*/
UIKIT_EXTERN const NSTimeInterval MKAToastTimeForever;

/**
* MKAToast is the view that disappears automatically after displaying a short message for a few seconds.
Expand All @@ -94,6 +106,10 @@ UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;
* A label.
*/
@property (nonatomic, readonly) UILabel *label;
/**
* Tells whether the toast view is showing.
*/
@property (nonatomic, readonly) BOOL isShowing;

/**
* Creates a toast view with default style.
Expand Down Expand Up @@ -132,6 +148,9 @@ UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;
* Shows the toast view with the animation in configured time. After fading out, it is separated from the parent view.
*/
- (void)show;
/**
*/
- (void)hide;

/**
* Shows a toast view with the animation in default time. After fading out, it is separated from the parent view.
Expand Down
29 changes: 23 additions & 6 deletions MKAPopupKit/MKAToast.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ - (id)copyWithZone:(nullable NSZone *)zone {

const NSTimeInterval MKAToastShortTime = 3.0;
const NSTimeInterval MKAToastLongTime = 5.0;
const NSTimeInterval MKAToastTimeShort = 3.0;
const NSTimeInterval MKAToastTimeLong = 5.0;
const NSTimeInterval MKAToastTimeForever = -1.0;

@interface MKAToast ()

Expand Down Expand Up @@ -107,7 +110,7 @@ - (instancetype)initWithText:(NSString *)text style:(MKAToastStyleConfiguration
if (self = [super initWithFrame:frame]) {
// Sets default values.
_animationDuration = kDefaultAnimationDuration;
_time = MKAToastShortTime;
_time = MKAToastTimeShort;
_delay = 0;
self.backgroundColor = styleConfig.backgroundColor;

Expand All @@ -132,13 +135,19 @@ - (instancetype)initWithText:(NSString *)text style:(MKAToastStyleConfiguration

// Hides characters that protrude.
self.clipsToBounds = YES;

self.alpha = 0;
}

return self;
}

#pragma mark - public method

- (BOOL)isShowing {
return self.alpha == 1.f;
}

- (instancetype)withTag:(NSInteger)tag {
self.tag = tag;
return self;
Expand Down Expand Up @@ -182,18 +191,26 @@ - (void)show {
self.alpha = 1.f;
}
completion:^(BOOL b) {
[NSTimer scheduledTimerWithTimeInterval:self.time
target:self
selector:@selector(hide:)
userInfo:nil
repeats:NO];
if (self.time != MKAToastTimeForever) {
[NSTimer scheduledTimerWithTimeInterval:self.time
target:self
selector:@selector(hide:)
userInfo:nil
repeats:NO];
}

if ([self.delegate respondsToSelector:@selector(toastDidAppear:)]) {
[self.delegate toastDidAppear:self];
}
}];
}

- (void)hide {
if (self.time == MKAToastTimeForever) {
[self hide:nil];
}
}

+ (void)showText:(NSString *)text {
[[MKAToast toastWithText:text] show];
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ config.font = UIFont.systemFont(ofSize: 17.0, weight: .bold)
MKAToast("Something error occurred!", style: config)
.withDelegate(self)
.withTag(1)
.withTime(MKAToastLongTime)
.withTime(MKAToastTimeLong)
.withAnimationDuration(0.5)
.withDelay(0.5)
.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,23 @@ UIKIT_EXTERN const CGFloat MKAToastDefaultHeight;
/**
* A default short display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastShortTime;
UIKIT_EXTERN const NSTimeInterval MKAToastShortTime DEPRECATED_MSG_ATTRIBUTE("Use `MKAToastTimeShort` instead.");
/**
* A default long display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;
UIKIT_EXTERN const NSTimeInterval MKAToastLongTime DEPRECATED_MSG_ATTRIBUTE("Use `MKAToastTimeLong` instead.");
/**
* A default short display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastTimeShort;
/**
* A default long display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastTimeLong;
/**
* A toast view is displayed forever (until `hide` method is called).
*/
UIKIT_EXTERN const NSTimeInterval MKAToastTimeForever;

/**
* MKAToast is the view that disappears automatically after displaying a short message for a few seconds.
Expand All @@ -94,6 +106,10 @@ UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;
* A label.
*/
@property (nonatomic, readonly) UILabel *label;
/**
* Tells whether the toast view is showing.
*/
@property (nonatomic, readonly) BOOL isShowing;

/**
* Creates a toast view with default style.
Expand Down Expand Up @@ -132,6 +148,9 @@ UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;
* Shows the toast view with the animation in configured time. After fading out, it is separated from the parent view.
*/
- (void)show;
/**
*/
- (void)hide;

/**
* Shows a toast view with the animation in default time. After fading out, it is separated from the parent view.
Expand Down
Binary file modified Sample/MKAPopupSample/Framework/MKAPopupKit.framework/Info.plist
Binary file not shown.
Binary file modified Sample/MKAPopupSample/Framework/MKAPopupKit.framework/MKAPopupKit
Binary file not shown.
15 changes: 11 additions & 4 deletions Sample/MKAPopupSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extension UIView {
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var tableView: UITableView!
private var toastForever: MKAToast?
private let popupList = ["Text Content View Popup",
"Web Content View Popup",
"Image Content View Popup",
Expand Down Expand Up @@ -148,16 +149,22 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega
MKAToast("Something error occurred!", style: config)
.withDelegate(self)
.withTag(1)
.withTime(MKAToastLongTime)
.withTime(MKAToastTimeLong)
.withAnimationDuration(0.5)
.withDelay(0.5)
.show()
case 10:
// Show the toast view using cached style.
MKAToast("Success!", forKey: "Success")
if let isShowing = toastForever?.isShowing, isShowing {
toastForever?.hide()
return
}
// Create the toast view using cached style.
toastForever = MKAToast("Success!", forKey: "Success")
.withDelegate(self)
.withTag(2)
.show()
.withTime(MKAToastTimeForever)
// Show the toast view forever (until `hide()` method is called).
toastForever?.show()
default:
break
}
Expand Down

0 comments on commit 44b4a69

Please sign in to comment.