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

Add Simple component for keyboard avoiding #154

Closed
beqramo opened this issue May 17, 2023 · 8 comments · Fixed by #229
Closed

Add Simple component for keyboard avoiding #154

beqramo opened this issue May 17, 2023 · 8 comments · Fixed by #229
Assignees
Labels
📚 components Anything related to the exported components of this library feature request 👀 Request new functionality of the library KeyboardAvoidingView 🧪 Anything related to KeyboardAvoidingView component

Comments

@beqramo
Copy link

beqramo commented May 17, 2023

Is your feature request related to a problem? Please describe.
Hi,
In most of the cases in app we just want to move button on top if it is open or something like that.
So it is missing base component that will do this thing. it isn't handy to build animation again and again for simply placing button on top.

Because of that, I would suggest adding base Component that will do simple avoiding like the below:

import React from 'react';
import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller';
import Animated,  { interpolate, useAnimatedStyle, Extrapolation }  from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

interface IKeyboardAwareComponent {
  children: React.ReactNode;
  withBottomInset: boolean;
}


function KeyboardAwareComponent({ children, withBottomInset, ...rest }: IKeyboardAwareComponent) {
  const { height } = useReanimatedKeyboardAnimation();
  const { bottom } = useSafeAreaInsets();

  const styles = useAnimatedStyle(() => {
    const paddingBottom = withBottomInset ? interpolate(
      height.value,
      [0, bottom],
      [bottom, 0],
      Extrapolation.IDENTITY,
    ) : 0;
    
    return {
      transform: [{ translateY: height.value }],
      paddingBottom,
    };
  }, [bottom]);

  return (
    <Animated.View style={styles} {...rest}>
      {children}
    </Animated.View>
  );
}

export default KeyboardAwareComponent;

This solution will work only if it is a fixed button, without any scroll.
Depending on where you will put the relative position in the parent component it most likely will work in most cases.
Sorry I didn't answer other paragraphs and I removed it.

Thank you.
Great library btw.

@kirillzyusko
Copy link
Owner

@beqramo maybe it makes sense to replicate default components, such as KeyboardAvoidingView/KeyboardAwareScrollView?

@kirillzyusko kirillzyusko added the feature request 👀 Request new functionality of the library label May 17, 2023
@beqramo
Copy link
Author

beqramo commented May 17, 2023

@kirillzyusko I updated the codes. there were some stupid mistakes :).
Replicate in what term? For the example above component will do the same thing as KeyboardAvoidingView exactly. but as KeyboardAvoidingView doesn't work always, this will work

@beqramo
Copy link
Author

beqramo commented May 17, 2023

Oh you mean to add as an improvement, moving the input field with the keyboard if it is going to be behind?

@kirillzyusko
Copy link
Owner

kirillzyusko commented May 17, 2023

@beqramo With the support of this library you can achieve better animations of KeyboardAvoidingView or any other component. You can checkout example app and find how KeyboardAwareScrollView was implemented and compare it with react-native-keyboard-aware-scroll-view package, for example.

I thought about adding basic components into the package, but I need to allocate time for that 😅

@beqramo
Copy link
Author

beqramo commented May 17, 2023

Yes, this lib is amazing. I am indicating some missing components that instead of in the example file can be inside the package itself.
I dropped one of the simplest component that can be exported from the lib.
Nothig special is written above just instead of everyone to create custom component of base the functionality everyone can use exported component from this lib

@kirillzyusko kirillzyusko changed the title Add Simple component for keyboard awoiding Add Simple component for keyboard avoiding May 17, 2023
@Noitham
Copy link

Noitham commented Aug 19, 2023

I agree with @beqramo, would be awesome to have some components replacing the KeyboardAvoidingView/KeyboardAwareScrollView using this library. 🙌

@kirillzyusko
Copy link
Owner

@Noitham for sure I'll add them, but a little bit later. Right now want to close some old GH issues, enhance API a little bit and after that I'll develop these KeyboardAvoidingView/KeyboardAwareScrollView views - just need some time.

By the way - contributions are always welcome! If you have a desire to add them to the library - you can open PR and after a review I'll merge it 🙂

@kirillzyusko kirillzyusko added the 📚 components Anything related to the exported components of this library label Sep 7, 2023
@kirillzyusko kirillzyusko mentioned this issue Sep 7, 2023
1 task
kirillzyusko added a commit that referenced this issue Sep 7, 2023
## 📜 Description

Added `KeyboardAvoidingView` based on `useKeyboardHandler` hook.

## 💡 Motivation and Context

It was requested functionality and I agree that similar components
should be provided out-of-box.

As a first component I decided to re-implement `KeyboardAvoidingView`,
because the implementation is very easy 👀

Later I'm planning to add more components, so stay tuned 😎 

Closes
#154

## 📢 Changelog

<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->

### JS
- added `KeyboardAvoidingView`;
- added corresponding example app.

### Docs
- added section about `KeyboardAvoidingView`;
- added lottie that shows visual difference between implementations.

## 🤔 How Has This Been Tested?

Tested on:
- Xiaomi Redmi Note 5 Pro;
- Pixel 7 Pro;
- iPhone 14 Pro (iOS 16.5, iOS 17) <- simulator;
- iPhone 6s (iOS 15.6).

## 📸 Screenshots (if appropriate):


https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/0fc849d4-4c15-41ab-875f-f49c555256f3

## 📝 Checklist

- [x] CI successfully passed
@kirillzyusko
Copy link
Owner

@beqramo you can use KeyboardAvoidingView with behavior="position" to achieve the same effect described in your issue. This component will be available in 1.7.0

@kirillzyusko kirillzyusko added the KeyboardAvoidingView 🧪 Anything related to KeyboardAvoidingView component label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 components Anything related to the exported components of this library feature request 👀 Request new functionality of the library KeyboardAvoidingView 🧪 Anything related to KeyboardAvoidingView component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants