Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tap to dismiss #64

Merged
merged 7 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ios/RNSimpleToast.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "UIView+Toast.h"
#import "RNToastViewController.h"
#import <React/RCTConvert.h>
#import "RNToastView.h"

static double defaultPositionId = 2.0;

Expand All @@ -26,7 +27,7 @@ @implementation RNSimpleToast {
- (instancetype)init {
if (self = [super init]) {
_kbdHeight = 0;
[CSToastManager setTapToDismissEnabled:NO];
[CSToastManager setTapToDismissEnabled:YES];
[CSToastManager setQueueEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
Expand Down Expand Up @@ -163,8 +164,7 @@ - (UIView *)getToastView:(RNToastViewController *)ctrl {
CGRect bounds = rootView.bounds;
bounds.size.height -= _kbdHeight;

UIView *view = [[UIView alloc] initWithFrame:bounds];
view.userInteractionEnabled = NO;
UIView *view = [[RNToastView alloc] initWithFrame:bounds];
[rootView addSubview:view];
return view;
}
Expand Down
5 changes: 5 additions & 0 deletions ios/RNToastView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>

@interface RNToastView : UIView

@end
11 changes: 11 additions & 0 deletions ios/RNToastView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import "RNToastView.h"

@implementation RNToastView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
id hitView = [super hitTest:point withEvent:event];
if (hitView == self) return nil;
else return hitView;
}

@end
10 changes: 3 additions & 7 deletions ios/RNToastViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#import "RNToastViewController.h"
#import <React/RCTUtils.h>
#import "RNToastWindow.h"

@implementation RNToastViewController

Expand All @@ -12,17 +13,12 @@ - (UIWindow *)toastWindow
if (_toastWindow == nil) {
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
if (keyWindow) {
_toastWindow = [[UIWindow alloc] initWithFrame:keyWindow.bounds];
_toastWindow = [[RNToastWindow alloc] initWithFrame:keyWindow.bounds];
} else {
// keyWindow is nil, so we cannot create and initialize _toastWindow
NSLog(@"Unable to create alert window: keyWindow is nil");
}
}

if (_toastWindow) {
_toastWindow.windowLevel = UIWindowLevelAlert + 1;
_toastWindow.userInteractionEnabled = NO;
}
}

return _toastWindow;
Expand All @@ -48,7 +44,7 @@ - (UIWindow *)getUIWindowFromScene
for (UIScene *scene in RCTSharedApplication().connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive &&
[scene isKindOfClass:[UIWindowScene class]]) {
return [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
return [[RNToastWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions ios/RNToastWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>

@interface RNToastWindow : UIWindow

@end
25 changes: 25 additions & 0 deletions ios/RNToastWindow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#import "RNToastWindow.h"

@implementation RNToastWindow

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.windowLevel = UIWindowLevelAlert + 1;
}
return self;
}

- (instancetype)initWithWindowScene:(UIWindowScene *)windowScene {
if (self = [super initWithWindowScene:windowScene]) {
self.windowLevel = UIWindowLevelAlert + 1;
}
return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
id hitView = [super hitTest:point withEvent:event];
if (hitView == self) return nil;
else return hitView;
}

@end