99#import " RCTBridgeModule.h"
1010#import " UIView+Toast.h"
1111
12- NSInteger const LRDRCTSimpleToastBottomOffset = 28 ;
12+ NSInteger const LRDRCTSimpleToastBottomOffset = 40 ;
1313double const LRDRCTSimpleToastShortDuration = 3.0 ;
1414double const LRDRCTSimpleToastLongDuration = 5.0 ;
15+ NSInteger const LRDRCTSimpleToastGravityBottom = 1 ;
16+ NSInteger const LRDRCTSimpleToastGravityCenter = 2 ;
17+ NSInteger const LRDRCTSimpleToastGravityTop = 3 ;
1518
1619@interface LRDRCTSimpleToast : NSObject <RCTBridgeModule>
1720@end
@@ -23,28 +26,44 @@ @implementation LRDRCTSimpleToast
2326- (NSDictionary *)constantsToExport {
2427 return @{
2528 @" SHORT" : [NSNumber numberWithDouble: LRDRCTSimpleToastShortDuration],
26- @" LONG" : [NSNumber numberWithDouble: LRDRCTSimpleToastLongDuration]
29+ @" LONG" : [NSNumber numberWithDouble: LRDRCTSimpleToastLongDuration],
30+ @" BOTTOM" : [NSNumber numberWithInteger: LRDRCTSimpleToastGravityBottom],
31+ @" CENTER" : [NSNumber numberWithInteger: LRDRCTSimpleToastGravityCenter],
32+ @" TOP" : [NSNumber numberWithInteger: LRDRCTSimpleToastGravityTop]
2733 };
2834}
2935
3036RCT_EXPORT_METHOD (show:(NSString *)msg duration:(double )duration {
31- [self _show: msg duration: duration];
37+ [self _show: msg duration: duration gravity: LRDRCTSimpleToastGravityBottom ];
3238});
3339
34- - (void )_show : (NSString *)msg duration : (NSTimeInterval )duration {
40+ RCT_EXPORT_METHOD (showWithGravity:(NSString *)msg duration:(double )duration gravity:(nonnull NSNumber *)gravity{
41+ [self _show: msg duration: duration gravity: gravity.intValue];
42+ });
43+
44+ - (void )_show : (NSString *)msg duration : (NSTimeInterval )duration gravity : (NSInteger )gravity {
3545 dispatch_async (dispatch_get_main_queue (), ^{
3646 UIView *root = [[[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ] view ];
3747 CGRect bound = root.bounds ;
38- if (bound.size .height > LRDRCTSimpleToastBottomOffset) {
39- bound.size .height -= LRDRCTSimpleToastBottomOffset;
48+ if (bound.size .height > LRDRCTSimpleToastBottomOffset*2 ) {
49+ bound.origin .y += LRDRCTSimpleToastBottomOffset;
50+ bound.size .height -= LRDRCTSimpleToastBottomOffset*2 ;
4051 }
4152 UIView *view = [[UIView alloc ] initWithFrame: bound];
4253 view.userInteractionEnabled = NO ;
4354 [root addSubview: view];
4455 UIView __weak *blockView = view;
56+ id position;
57+ if (gravity == LRDRCTSimpleToastGravityTop) {
58+ position = CSToastPositionTop;
59+ } else if (gravity == LRDRCTSimpleToastGravityCenter) {
60+ position = CSToastPositionCenter;
61+ } else {
62+ position = CSToastPositionBottom;
63+ }
4564 [view makeToast: msg
4665 duration: duration
47- position: [CSToastManager defaultPosition ]
66+ position: position
4867 title: nil
4968 image: nil
5069 style: nil
0 commit comments