Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vonovak/react-native-simple-toast
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.0
Choose a base ref
...
head repository: vonovak/react-native-simple-toast
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.2.0
Choose a head ref
  • 3 commits
  • 5 files changed
  • 3 contributors

Commits on Dec 24, 2023

  1. feat(ios): keyboard avoidance (#73)

    * feat: keyboard avoid
    
    * feat: keyboard avoidance gravity bottom only
    
    ---------
    
    Co-authored-by: Maksim Efimov <maksim.efimov@sbermarket.ru>
    mgefimov and Maksim Efimov authored Dec 24, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    15b5251 View commit details
  2. docs: keyboard avoidance

    vonovak committed Dec 24, 2023
    Copy the full SHA
    9ebf942 View commit details
  3. chore: release 3.2.0

    vonovak committed Dec 24, 2023
    Copy the full SHA
    a76718a View commit details
Showing with 53 additions and 13 deletions.
  1. +2 −0 README.md
  2. +3 −11 ios/RNSimpleToast.mm
  3. +2 −0 ios/RNToastView.h
  4. +45 −1 ios/RNToastView.m
  5. +1 −1 package.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ React Native Toast component for both Android and iOS. It just lets iOS users ha

✅ renders on top of `Modal`s and `Alert`s

✅ avoids keyboard

✅ customizable styling

## Screenshots
14 changes: 3 additions & 11 deletions ios/RNSimpleToast.mm
Original file line number Diff line number Diff line change
@@ -108,7 +108,9 @@ - (void)_show:(NSString *)msg
dispatch_async(dispatch_get_main_queue(), ^{
RNToastViewController *controller = [RNToastViewController new];
[controller show];
UIView *view = [self getToastView:controller];
BOOL kbdAvoidEnabled = [CSToastPositionBottom isEqualToString:positionString];
UIView *view = [[RNToastView alloc] initWithFrame:controller.toastWindow.bounds kbdHeight:self->_kbdHeight kbdAvoidEnabled:kbdAvoidEnabled];
[controller.toastWindow addSubview:view];
UIView __weak *weakView = view;

UIView *toast = [view toastViewForMessage:msg title:nil image:nil style:style];
@@ -162,16 +164,6 @@ - (CGPoint)rnToast_centerPointForPosition:(NSString *)gravity withToast:(UIView
return CGPointMake(view.bounds.size.width / 2.0, (view.bounds.size.height - (toast.frame.size.height / 2.0)) - bottomPadding);
}

- (UIView *)getToastView:(RNToastViewController *)ctrl {
UIView *rootView = ctrl.toastWindow;
CGRect bounds = rootView.bounds;
bounds.size.height -= _kbdHeight;

UIView *view = [[RNToastView alloc] initWithFrame:bounds];
[rootView addSubview:view];
return view;
}

#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params {
2 changes: 2 additions & 0 deletions ios/RNToastView.h
Original file line number Diff line number Diff line change
@@ -2,4 +2,6 @@

@interface RNToastView : UIView

- (instancetype)initWithFrame:(CGRect)frame kbdHeight:(CGFloat)kbdHeight kbdAvoidEnabled:(BOOL) kbdAvoidEnabled;

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

@implementation RNToastView
@implementation RNToastView {
CGRect originalFrame;
}

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

- (instancetype)initWithFrame:(CGRect)frame kbdHeight: (CGFloat)kbdHeight kbdAvoidEnabled: (BOOL)kbdAvoidEnabled {
originalFrame = frame;
if (kbdAvoidEnabled) {
frame.size.height -= kbdHeight;
}
if (self = [super initWithFrame:frame]) {
if (kbdAvoidEnabled) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
}
return self;
}

- (void)keyboardWillShow:(NSNotification *)notification {
CGSize keyboardSize = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGFloat height = keyboardSize.height;
CGRect frame = originalFrame;
frame.size.height -= height;
[self setFrame: frame];
}

- (void)keyboardWillHide:(NSNotification *)notification {
[self setFrame: originalFrame];
}


- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}

@end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-simple-toast",
"version": "3.1.0",
"version": "3.2.0",
"description": "test",
"main": "lib/commonjs/index",
"module": "lib/module/index",