feat:iOS support toast gravity
This commit is contained in:
parent
748bac8bc1
commit
2d0570c09f
@ -14,7 +14,7 @@ class ModalDemo extends Panel {
|
||||
textAlignment: Gravity.Center,
|
||||
height: 50,
|
||||
}),
|
||||
label('toast'),
|
||||
label('toast on bottom'),
|
||||
label('Click me').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
@ -26,6 +26,31 @@ class ModalDemo extends Panel {
|
||||
modal(context).toast('This is a toast.')
|
||||
}
|
||||
} as IText),
|
||||
label('toast on top'),
|
||||
label('Click me').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
bgColor: colors[0],
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
layoutConfig: layoutConfig().exactly(),
|
||||
onClick: () => {
|
||||
modal(context).toast('This is a toast.', Gravity.Top)
|
||||
}
|
||||
} as IText),
|
||||
|
||||
label('toast on center'),
|
||||
label('Click me').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
bgColor: colors[0],
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
layoutConfig: layoutConfig().exactly(),
|
||||
onClick: () => {
|
||||
modal(context).toast('This is a toast.', Gravity.Center)
|
||||
}
|
||||
} as IText),
|
||||
]).apply({
|
||||
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||
gravity: Gravity.Center,
|
||||
|
@ -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