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

feat(keyboard): Add keyboardAnimationDuration to KeyboardInfo #523

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ void onKeyboardEvent(String event, int size) {
switch (event) {
case Keyboard.EVENT_KB_WILL_SHOW:
case Keyboard.EVENT_KB_DID_SHOW:
String data = "{ 'keyboardHeight': " + size + " }";
// Convert Handler().postDelayed() 350ms to 0.35s
String data = "{ 'keyboardHeight': " + size + ", 'keyboardAnimationDuration': " + 0.35 + " }";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for contributing this. Is 350 a constant on Android?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PluginMethod
    public void show(final PluginCall call) {
        execute(
            () ->
                new Handler()
                    .postDelayed(
                        () -> {
                            implementation.show();
                            call.resolve();
                        },
                        350
                    )
        );
    }

350 is method param long delayMillis

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I meant: on Android, is 350 milliseconds always the time it takes for the keyboard animation to complete. I'm wondering why that number is hard-coded.

Thank you.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be speaking out of ignorance here, but is this value only useful on iOS? Perhaps the android part of this should be removed, and the docs should specify this as an iOS only value for the plugin?

bridge.triggerWindowJSEvent(event, data);
kbData.put("keyboardHeight", size);
kbData.put("keyboardAnimationDuration", 0.35);
notifyListeners(event, kbData);
break;
case Keyboard.EVENT_KB_WILL_HIDE:
Expand Down
12 changes: 8 additions & 4 deletions keyboard/ios/Plugin/Keyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ - (void)onKeyboardWillShow:(NSNotification *)notification
[self setKeyboardHeight:height delay:duration];
[self resetScrollView];

NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d, 'keyboardAnimationDuration': %f}", (int)height, (double)duration];
[self.bridge triggerWindowJSEventWithEventName:@"keyboardWillShow" data:data];
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]};
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height], @"keyboardAnimationDuration": [NSNumber numberWithDouble:duration]};
[self notifyListeners:@"keyboardWillShow" data:kbData];
}

Expand All @@ -146,11 +146,15 @@ - (void)onKeyboardDidShow:(NSNotification *)notification
CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double height = rect.size.height;

double duration = [[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]+0.2;

[self resetScrollView];

NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height];
NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d, 'keyboardAnimationDuration': %f}", (int)height, (double)duration];

[self.bridge triggerWindowJSEventWithEventName:@"keyboardDidShow" data:data];
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]};
NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height], @"keyboardAnimationDuration": [NSNumber numberWithDouble:duration]};

[self notifyListeners:@"keyboardDidShow" data:kbData];
}

Expand Down
7 changes: 7 additions & 0 deletions keyboard/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export interface KeyboardInfo {
* @since 1.0.0
*/
keyboardHeight: number;

/**
* Animation duration of the keyboard.
*
* @since 1.0.0
*/
keyboardAnimationDuration: number;
}

export interface KeyboardStyleOptions {
Expand Down