APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.24k stars 643 forks source link

Component Not working with react-native 0.63 #443

Open meabed opened 3 years ago

meabed commented 3 years ago

Hey! First thank you for the awesome component 🙏 Then :) After upgrading to latest react-native 0.63 - it stopped rendering at all - when downgrading back works fine - I am not sure it could be something with the deprecation of react-native apis. It would great if this could fixed soon 👍

Thank you again ❤️

codler commented 3 years ago

I have forked the repo to fix this issue.


npm i @codler/react-native-keyboard-aware-scroll-view
meabed commented 3 years ago

Thanks @codler :) i have tested - its rendering 👍 but not scrolling ;) any special params need to passed? Good job <3

walterholohan commented 3 years ago

@meabed I just used the forked repo in my project and everything is working fine. Maybe is something to do with one of the children in the view.

meabed commented 3 years ago

Thanks a lot :) it works like a charm - I was missing some flex styles 😀

lukasa1993 commented 3 years ago

is this repo dead we need to move to fork ?

rborn commented 3 years ago

@lukasa1993 nope, just starting to help with it :)

lukasa1993 commented 3 years ago

how can we help?

rborn commented 3 years ago

@lukasa1993 can you test master with RN 0.63 (I didn't upgrade yet my project) and if it works I'll push for an npm publish :)

I just merged https://github.com/APSL/react-native-keyboard-aware-scroll-view/pull/442

lukasa1993 commented 3 years ago

it wasnt pushed to npm

rborn commented 3 years ago

@lukasa1993 I know, you need to install the git version

walterholohan commented 3 years ago

@codler added a few commits to his forked repo. Would be good to get all his changes in image

rborn commented 3 years ago

@codler whenever you want, please make a PR :)

Bardiamist commented 3 years ago

Hmm in my implementation seems scrollResponderScrollNativeHandleToKeyboard works wrong sometime in React native 0.63.x. Need to investigate more.

aliasger-rashid commented 3 years ago

Its not available on npm. How to use the latest 0.9.2 version ?

rborn commented 3 years ago

npm install https://github.com/APSL/react-native-keyboard-aware-scroll-view#v0.9.2

BapuHirave commented 3 years ago

@rborn @codler and thanks for your efforts. @rborn are you planning to publish (0.92) it to npm ?

rborn commented 3 years ago

@bhirave I don't have rights to publish, we need to wait for @alvaromb

CyrusZei commented 3 years ago

any updates on this? This feels like a perfect example of why you assign more than one who can publish.

galizhan commented 3 years ago

Any updates?

billnbell commented 3 years ago

Please publish to NPM!!

garganurag893 commented 3 years ago

Any updates?

acerbastimur commented 3 years ago

Any updates ?

lukasa1993 commented 3 years ago

why this took so long any problems?

Alaa-Ben commented 3 years ago

If I understand correctly, there's only one person who have the right to publish to npm, and he's not available for the moment. If you really want to use the latest release, you could just target the tag in your package.json. (https://github.com/APSL/react-native-keyboard-aware-scroll-view#v0.9.2)

lukasa1993 commented 3 years ago

well i am but still strange :D

CyrusZei commented 3 years ago

I have moved away from this component and are using the one that comes directly from react-native instead since for me this has become a liability issue and I made my own keyboard avoid component that works really great.

I have used this component that the author did and I liked for a long time so shout out to the author.

jsellam commented 3 years ago

No update on npm ?

ede-sous commented 3 years ago

Still no update on npm ?

Pompedup commented 3 years ago

I have the same issue, could you update npm asap please ?

CyrusZei commented 3 years ago

I don't think to spam the comments will make the author fix this faster. Just have some patience guys

lukewlms commented 3 years ago

We were able to completely remove this dependency in latest RN just by wrapping any ScrollView in KeyboardAvoidingView. This is working beautifully and got rid of longstanding bugs we had with this library.

The only real trick was ensuring header height is accounted for, which can be done this way if using @react-navigation/stack:

import { useHeaderHeight } from "@react-navigation/stack";

export function useKeyboardAvoidingViewProps(): KeyboardAvoidingViewProps {
  const headerHeight = useHeaderHeight();
  return {
    behavior: "padding",
    // https://stackoverflow.com/questions/48420468/keyboardavoidingview-not-working-properly
    keyboardVerticalOffset: headerHeight,
  };
}

Then just spread those props into KeyboardAvoidingView.

curiousdustin commented 3 years ago

Using @codler's fork, the component does render for me, but when I try to use the ref.props methods, props is undefined.

What is going on here?

curiousdustin commented 3 years ago

Seems possibly related to RN 0.63 change: Make ScrollView use forwardRef

https://github.com/facebook/react-native/commit/d2f314af75b63443db23e131aaf93c2d064e4f44

putupadang commented 3 years ago

downgrade RN version will be fastest solution 🤣

luutruong commented 3 years ago

@putupadang It's true. lmao

Arslan106 commented 3 years ago

any update????? please help

CyrusZei commented 3 years ago

honestly, you don't need this library at all.

I created my own component that works like a charm so create two components

create a file called KeyboardAvoid.tsx and add the code below:

import React from 'react';
import { KeyboardAvoidingView, Platform, KeyboardAvoidingViewProps } from 'react-native';

interface IKeyboardAvoid extends KeyboardAvoidingViewProps {
    children: React.ReactNode;
}

const KeyboardAvoid = ({ children }: IKeyboardAvoid) => {
    return (
        <KeyboardAvoidingView
            behavior={Platform.OS == 'ios' ? 'padding' : 'height'}
            style={{
                display: 'flex',
                justifyContent: 'center',
                flexDirection: 'column',
                backgroundColor: '#ffffff',
                flex: 1
            }}
        >
            {children}
        </KeyboardAvoidingView>
    );
};

export default KeyboardAvoid;

then create another file called RootContainer and add the code below :

import React from 'react';
import styled from 'styled-components/native';
import { ViewProperties, ScrollView } from 'react-native';

interface IContainerProps extends ViewProperties {
    children: React.ReactNode;
    bgColor?: string;
}

const Container = styled.View`
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
    background-color: ${(props: IContainerProps) => (props.bgColor ? props.bgColor : '#ffffff')};
`;

const RootContainer = ({ bgColor, children, ...rest }: IContainerProps) => {
    return (
        <ScrollView
            keyboardShouldPersistTaps="handled"
            keyboardDismissMode="on-drag"
            contentContainerStyle={{
                display: 'flex',
                flexGrow: 1,
                justifyContent: 'center'
            }}
        >
            <Container bgColor={bgColor} {...rest}>
                {children}
            </Container>
        </ScrollView>
    );
};

export default RootContainer;

Then for every new screen that you make you just need to add the RootContainer component at the root of that component.

then you need to add the KeyboardAvoid at the root level inside of your App component. That is all you have to do. I am using styled-components for this

Johbrun commented 3 years ago

Thanks @CyrusZei , it works ! 🎉

Just a suggestion : the line import styled from 'styled-components/native'; must be in RootContainer.tsxfile, and not KeyboardAvoid.tsx

CyrusZei commented 3 years ago

Yeah true, removed it from the wrong place 😂

aeirola commented 3 years ago

In case someone missed it, 0.9.2 has now been published to npm (https://www.npmjs.com/package/react-native-keyboard-aware-scroll-view/v/0.9.2). Seems to work for me with rn 0.63.2

okwast commented 3 years ago

Seems possibly related to RN 0.63 change: Make ScrollView use forwardRef

facebook/react-native@d2f314a

Yeah, that makes a lot of sense. Also calling the methods directly on the ref without the .props works fine, but it gives a type error then.

However as far as I understood ref and innerRef as now equal making innerRef obsolete. So just take the ref from the KeyboardAwareScrollView and then call the methods on that. Type wise that is even nicer as you don't have to work with the JSX.Element anymore.

kholood-ea commented 3 years ago

another simple solution that could be a good alternative for using this library and needs no external dependency :

import {Keyboard,KeyboardAvoidingView,TouchableWithoutFeedback} from 'react-native';

  const [shiftkeyboard, setShiftkeyboard] = React.useState(false);

//wrap the whole component screen with this 
          return(
             <>
             <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
            <KeyboardAvoidingView style={styles.container} behavior='position' enabled={shiftkeyboard} >
             <TextInput
                style={......}
                keyboardType="phone-pad"
                placeholder="......."
                onFocus={() => setShiftkeyboard(true)}
             />
               </KeyboardAvoidingView>
               </TouchableWithoutFeedback>
                </>
                 )
CyrusZei commented 3 years ago

Did you just make a hooks keyboard 😁

On Sun, 16 Aug 2020 at 13:46, kholood notifications@github.com wrote:

another simple solution that could be a good alternative for using this library and needs no external dependency :

import {Keyboard,KeyboardAvoidingView,TouchableWithoutFeedback} from 'react-native';

const [shiftkeyboard, setShiftkeyboard] = React.useState(false);

//wrap the whole component screen with this

return(

<>

<TextInput

style={......}

keyboardType="phone-pad"

placeholder="......."

onFocus={() => setShiftkeyboard(true)}

/>

</>

)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/APSL/react-native-keyboard-aware-scroll-view/issues/443#issuecomment-674516642, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGR3T3EFYUSCHEGEUTJO53SA7BKJANCNFSM4OXZUW7A .

-- With regards Cyrus_Zei [ Developer + Designer = Unicorn]

kholood-ea commented 3 years ago

Did you just make a hooks keyboard 😁 On Sun, 16 Aug 2020 at 13:46, kholood @.**> wrote: another simple solution that could be a good alternative for using this library and needs no external dependency : import {Keyboard,KeyboardAvoidingView,TouchableWithoutFeedback} from 'react-native'; const [shiftkeyboard, setShiftkeyboard] = React.useState(false); //wrap the whole component screen with this return( <> <TextInput style={......} keyboardType="phone-pad" placeholder="......." onFocus={() => setShiftkeyboard(true)} /> </> ) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#443 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGR3T3EFYUSCHEGEUTJO53SA7BKJANCNFSM4OXZUW7A . -- With regards Cyrus_Zei [ Developer + Designer = Unicorn*]

thanks for making me realize my comment is displayed wrong 😅, good solution up there 👍🏻

eporomaa commented 3 years ago

@CyrusZei From what I can see your solution does not scroll to selected text fields?

wmonecke commented 3 years ago

We were able to completely remove this dependency in latest RN just by wrapping any ScrollView in KeyboardAvoidingView. This is working beautifully and got rid of longstanding bugs we had with this library.

The only real trick was ensuring header height is accounted for, which can be done this way if using @react-navigation/stack:

import { useHeaderHeight } from "@react-navigation/stack";

export function useKeyboardAvoidingViewProps(): KeyboardAvoidingViewProps {
  const headerHeight = useHeaderHeight();
  return {
    behavior: "padding",
    // https://stackoverflow.com/questions/48420468/keyboardavoidingview-not-working-properly
    keyboardVerticalOffset: headerHeight,
  };
}

Then just spread those props into KeyboardAvoidingView.

KeyboardAvoidingView is incredibly buggy in Android. Are you sure you tested on different devices with different Android API?

wmonecke commented 3 years ago

honestly, you don't need this library at all.

I created my own component that works like a charm so create two components

create a file called KeyboardAvoid.tsx and add the code below:

import React from 'react';
import { KeyboardAvoidingView, Platform, KeyboardAvoidingViewProps } from 'react-native';

interface IKeyboardAvoid extends KeyboardAvoidingViewProps {
  children: React.ReactNode;
}

const KeyboardAvoid = ({ children }: IKeyboardAvoid) => {
  return (
      <KeyboardAvoidingView
          behavior={Platform.OS == 'ios' ? 'padding' : 'height'}
          style={{
              display: 'flex',
              justifyContent: 'center',
              flexDirection: 'column',
              backgroundColor: '#ffffff',
              flex: 1
          }}
      >
          {children}
      </KeyboardAvoidingView>
  );
};

export default KeyboardAvoid;

then create another file called RootContainer and add the code below :

import React from 'react';
import styled from 'styled-components/native';
import { ViewProperties, ScrollView } from 'react-native';

interface IContainerProps extends ViewProperties {
  children: React.ReactNode;
  bgColor?: string;
}

const Container = styled.View`
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  background-color: ${(props: IContainerProps) => (props.bgColor ? props.bgColor : '#ffffff')};
`;

const RootContainer = ({ bgColor, children, ...rest }: IContainerProps) => {
  return (
      <ScrollView
          keyboardShouldPersistTaps="handled"
          keyboardDismissMode="on-drag"
          contentContainerStyle={{
              display: 'flex',
              flexGrow: 1,
              justifyContent: 'center'
          }}
      >
          <Container bgColor={bgColor} {...rest}>
              {children}
          </Container>
      </ScrollView>
  );
};

export default RootContainer;

Then for every new screen that you make you just need to add the RootContainer component at the root of that component.

then you need to add the KeyboardAvoid at the root level inside of your App component. That is all you have to do. I am using styled-components for this

I highly doubt this works like a charm. KeyboardAvoidingView is very buggy on Android and you clearly still need to test your app on different Android APIs. I am actually trying to implement KASV to avoid KeyboardAvoidingView.

Here is a screenshot of a KeyboardAvoidingView on Android (Pixel 4, API 29, android:softInputMode:adjustResize)

Screenshot 2020-10-15 at 11 39 29

You can clearly see KAV is not taking into account the software nav buttons.

Ref: https://github.com/facebook/react-native/issues/27526

tschanz-pcv commented 3 years ago

@wmonecke Thanks for confirming. I also decided to create a custom KeyboardAvoidingScrollView going after reading the "encouraging" comments here but have been getting increasingly frustrated on Android.

On iOS it worked great and with listening for keyboardWillShow (NOT ...Did...) events I can even toggle if scrolling is enabled or not on views which only need to be scrollable when the keyboard shows.

On Android it "works" with the mentioned configs, like setting keyboardVerticalOffset to 0 and not setting behavior at all. But then again I've only tested against one Android device/API. But I also had android:windowSoftInputMode="adjustResize" set so maybe that just took over and all the KeyboardAvoiding stuff didn't work at all.

My main problem is that I would love to somehow get the extraScrollHeight to work on Android. On iOS it's easily achievable using either contentInset or with marginBottom & overflow: 'visible' on the ScrollView but I have no clue on how to achieve a similar feature on Android without breaking it. I can do a negative top margin which "works" in the sense that it looks like an offset but then you can't scroll to the top anymore as that part is of course cut off while the keyboard is open. If anyone has a tip on how to get something similar to extraScrollHeight on Android I would be very happy to hear about it :)

MorenoMdz commented 3 years ago

Anybody does know exactly why it doesnt work in Android with the latest (0.93) release? Is it because of the indowSoftInputMode or some other setting? Neither the native KeyboardAvoidingView works as well in both platforms for some reason.

Streeterxs commented 3 years ago

v0.9.2 worked and our form showed up again