Skip to content

Commit

Permalink
Added Toast view
Browse files Browse the repository at this point in the history
  • Loading branch information
HituziANDO committed Mar 18, 2020
1 parent 48b20eb commit 8f9b255
Show file tree
Hide file tree
Showing 18 changed files with 787 additions and 39 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.0.2"
s.version = "2.1.0"
s.summary = "Simple and customizable popup view."
s.description = <<-DESC
MKAPopupKit is simple and customizable popup view for iOS.
Expand Down
8 changes: 8 additions & 0 deletions MKAPopupKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
5E95716722572AC4009C37CA /* MKAPopupKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E95716522572AC4009C37CA /* MKAPopupKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
5E95719E22578B38009C37CA /* MKAPopup.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E95719C22578B38009C37CA /* MKAPopup.h */; settings = {ATTRIBUTES = (Public, ); }; };
5E95719F22578B38009C37CA /* MKAPopup.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E95719D22578B38009C37CA /* MKAPopup.m */; };
5ED705DE24218064003EBC0A /* MKAToast.h in Headers */ = {isa = PBXBuildFile; fileRef = 5ED705DC24218064003EBC0A /* MKAToast.h */; settings = {ATTRIBUTES = (Public, ); }; };
5ED705E324218070003EBC0A /* MKAToast.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED705E124218070003EBC0A /* MKAToast.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -32,6 +34,8 @@
5E95716622572AC4009C37CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5E95719C22578B38009C37CA /* MKAPopup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MKAPopup.h; sourceTree = "<group>"; };
5E95719D22578B38009C37CA /* MKAPopup.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MKAPopup.m; sourceTree = "<group>"; };
5ED705DC24218064003EBC0A /* MKAToast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKAToast.h; sourceTree = "<group>"; };
5ED705E124218070003EBC0A /* MKAToast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKAToast.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -68,6 +72,8 @@
5E95719C22578B38009C37CA /* MKAPopup.h */,
5E95719D22578B38009C37CA /* MKAPopup.m */,
5E95716522572AC4009C37CA /* MKAPopupKit.h */,
5ED705DC24218064003EBC0A /* MKAToast.h */,
5ED705E124218070003EBC0A /* MKAToast.m */,
);
path = MKAPopupKit;
sourceTree = "<group>";
Expand All @@ -81,6 +87,7 @@
files = (
5E95716722572AC4009C37CA /* MKAPopupKit.h in Headers */,
5E95719E22578B38009C37CA /* MKAPopup.h in Headers */,
5ED705DE24218064003EBC0A /* MKAToast.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -175,6 +182,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5ED705E324218070003EBC0A /* MKAToast.m in Sources */,
5E95719F22578B38009C37CA /* MKAPopup.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
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.0.2</string>
<string>2.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
1 change: 1 addition & 0 deletions MKAPopupKit/MKAPopupKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ FOUNDATION_EXPORT const unsigned char MKAPopupKitVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <MKAPopupKit/PublicHeader.h>

#import "MKAPopup.h"
#import "MKAToast.h"
176 changes: 176 additions & 0 deletions MKAPopupKit/MKAToast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//
// MKAPopupKit
//
// Copyright (c) 2020-present Hituzi Ando. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/**
* A default value of a toast view's width.
*/
UIKIT_EXTERN const CGFloat MKAToastDefaultWidth;
/**
* A default value of a toast view's height.
*/
UIKIT_EXTERN const CGFloat MKAToastDefaultHeight;

/**
* A default background color of a toast view.
*/
#define MKAToastDefaultBackgroundColor [[UIColor grayColor] colorWithAlphaComponent:.95f]
/**
* A default text color.
*/
#define MKAToastDefaultTextColor [UIColor whiteColor]
/**
* A default font.
*/
#define MKAToastDefaultFont [UIFont systemFontOfSize:15.f weight:UIFontWeightRegular]

@interface MKAToastStyleConfiguration : NSObject <NSCopying>
/**
* A toast view's width.
*/
@property (nonatomic) CGFloat width;
/**
* A toast view's height.
*/
@property (nonatomic) CGFloat height;
/**
* A background color of a toast view.
*/
@property (nonatomic) UIColor *backgroundColor;
/**
* A text color.
*/
@property (nonatomic) UIColor *textColor;
/**
* A font.
*/
@property (nonatomic) UIFont *font;

@end

@protocol MKAToastDelegate;

/**
* A default short display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastShortTime;
/**
* A default long display time for a toast view.
*/
UIKIT_EXTERN const NSTimeInterval MKAToastLongTime;

/**
* MKAToast is the view that disappears automatically after displaying a short message for a few seconds.
* It is inspired by Android's Toast.
*/
@interface MKAToast : UIView
/**
* A label.
*/
@property (nonatomic, readonly) UILabel *label;

/**
* Creates a toast view with default style.
*/
+ (instancetype)toastWithText:(NSString *)text NS_SWIFT_NAME(init(_:));
/**
* Creates a toast view with given style.
*/
+ (instancetype)toastWithText:(NSString *)text style:(MKAToastStyleConfiguration *)styleConfig NS_SWIFT_NAME(init(_:style:));
/**
* Creates a toast view with cached style by given key.
*/
+ (instancetype)toastWithText:(NSString *)text forKey:(NSString *)key NS_SWIFT_NAME(init(_:forKey:));

/**
* Sets a tag.
*/
- (instancetype)withTag:(NSInteger)tag;
/**
* Sets a delegate.
*/
- (instancetype)withDelegate:(nullable id <MKAToastDelegate>)delegate;
/**
* Sets an animation duration of fade-in and fade-out in seconds.
*/
- (instancetype)withAnimationDuration:(NSTimeInterval)duration;
/**
* Sets a display time in seconds.
*/
- (instancetype)withTime:(NSTimeInterval)time;
/**
* Sets a delay in seconds that the toast view is shown after it.
*/
- (instancetype)withDelay:(NSTimeInterval)delay;
/**
* Shows the toast view with the animation in configured time. After fading out, it is separated from the parent view.
*/
- (void)show;

/**
* Shows a toast view with the animation in default time. After fading out, it is separated from the parent view.
*/
+ (void)showText:(NSString *)text NS_SWIFT_UNAVAILABLE("In Swift, use `MKAToast(_:)show()` instead.");
/**
* Sets a default style configuration.
*/
+ (void)setDefaultStyleConfiguration:(MKAToastStyleConfiguration *)config;
/**
* Adds a style configuration to the cache.
*/
+ (void)addStyleConfiguration:(MKAToastStyleConfiguration *)config forKey:(NSString *)key NS_SWIFT_NAME(add(styleConfiguration:forKey:));
/**
* Removes a style configuration from the cache.
*/
+ (void)removeStyleConfigurationForKey:(NSString *)key;

@end

@protocol MKAToastDelegate <NSObject>
@optional
/**
* Called just before a toast view appears.
*/
- (void)toastWillAppear:(MKAToast *)toast;
/**
* Called immediately after a toast view disappears.
*/
- (void)toastDidAppear:(MKAToast *)toast;
/**
* Called just before a toast view disappears.
*/
- (void)toastWillDisappear:(MKAToast *)toast;
/**
* Called immediately after a toast view disappears.
*/
- (void)toastDidDisappear:(MKAToast *)toast;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 8f9b255

Please sign in to comment.