feat:iOS support toast gravity
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Doric/Doric.h>
|
||||
#import "DoricModalPlugin.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
@@ -27,7 +28,11 @@ @implementation DoricModalPlugin
|
||||
|
||||
- (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
showToast(dic[@"msg"]);
|
||||
__block DoricGravity gravity = BOTTOM;
|
||||
[dic[@"gravity"] also:^(NSNumber *it) {
|
||||
gravity = (DoricGravity) [it integerValue];
|
||||
}];
|
||||
showToast(dic[@"msg"], gravity);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricLayouts.h"
|
||||
|
||||
void DoricLog(NSString *_Nonnull format, ...);
|
||||
|
||||
@@ -36,7 +37,4 @@ NSBundle *_Nonnull DoricBundle(void);
|
||||
#define DC_UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||
#endif
|
||||
|
||||
void showToastInView(NSString *_Nonnull text, UIView *_Nonnull superView);
|
||||
|
||||
|
||||
void showToast(NSString *_Nonnull text);
|
||||
void showToast(NSString *_Nonnull text, DoricGravity gravity);
|
@@ -48,10 +48,8 @@ void DoricLog(NSString *_Nonnull format, ...) {
|
||||
}
|
||||
|
||||
|
||||
void showToastInView(NSString *text, UIView *superView) {
|
||||
if (!superView) {
|
||||
return;
|
||||
}
|
||||
void showToast(NSString *text, DoricGravity gravity) {
|
||||
UIView *superView = [UIApplication sharedApplication].windows.lastObject;
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
label.font = [UIFont systemFontOfSize:20.f];
|
||||
label.text = text;
|
||||
@@ -63,15 +61,17 @@ void showToastInView(NSString *text, UIView *superView) {
|
||||
label.width += 30;
|
||||
label.height += 10;
|
||||
label.layer.cornerRadius = label.height / 2;
|
||||
label.bottom = superView.height - 20;
|
||||
label.centerX = superView.width / 2;
|
||||
if ((gravity & BOTTOM) == BOTTOM) {
|
||||
label.bottom = superView.height - 20;
|
||||
} else if ((gravity & TOP) == TOP) {
|
||||
label.top = 108;
|
||||
} else {
|
||||
label.centerY = (superView.height - 88) / 2;
|
||||
}
|
||||
|
||||
[superView addSubview:label];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[label removeFromSuperview];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void showToast(NSString *text) {
|
||||
showToastInView(text, [UIApplication sharedApplication].windows.lastObject);
|
||||
}
|
Reference in New Issue
Block a user