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

Component Not working with react-native 0.63 #443

Open
meabed opened this issue Jul 12, 2020 · 51 comments
Open

Component Not working with react-native 0.63 #443

meabed opened this issue Jul 12, 2020 · 51 comments

Comments

@meabed
Copy link

meabed commented Jul 12, 2020

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
Copy link
Contributor

codler commented Jul 12, 2020

I have forked the repo to fix this issue.

npm i @codler/react-native-keyboard-aware-scroll-view

@meabed
Copy link
Author

meabed commented Jul 12, 2020

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

@walterholohan
Copy link

@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
Copy link
Author

meabed commented Jul 13, 2020

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

@lukasa1993
Copy link

is this repo dead we need to move to fork ?

@rborn
Copy link
Collaborator

rborn commented Jul 14, 2020

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

@lukasa1993
Copy link

how can we help?

@rborn
Copy link
Collaborator

rborn commented Jul 14, 2020

@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 #442

@lukasa1993
Copy link

it wasnt pushed to npm

@rborn
Copy link
Collaborator

rborn commented Jul 14, 2020

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

@walterholohan
Copy link

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

@rborn
Copy link
Collaborator

rborn commented Jul 14, 2020

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

@Bardiamist
Copy link

Bardiamist commented Jul 15, 2020

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

@aliasger-rashid
Copy link

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

@rborn
Copy link
Collaborator

rborn commented Jul 16, 2020

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

@BapuHirave
Copy link

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

@rborn
Copy link
Collaborator

rborn commented Jul 16, 2020

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

@CyrusZei
Copy link

CyrusZei commented Jul 18, 2020

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

@galizhan
Copy link

Any updates?

@billnbell
Copy link

Please publish to NPM!!

@garganurag893
Copy link

Any updates?

@acerbastimur
Copy link

Any updates ?

@lukasa1993
Copy link

lukasa1993 commented Jul 21, 2020

why this took so long any problems?

@Alaa-Ben
Copy link

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
Copy link

well i am but still strange :D

@CyrusZei
Copy link

CyrusZei commented Jul 21, 2020

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
Copy link

jsellam commented Jul 21, 2020

No update on npm ?

@ede-sous
Copy link

Still no update on npm ?

@Pompedup
Copy link

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

@CyrusZei
Copy link

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

@lukewlms
Copy link

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
Copy link

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
Copy link

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

facebook/react-native@d2f314a

@putupadang
Copy link

downgrade RN version will be fastest solution 🤣

@luutruong
Copy link

@putupadang It's true. lmao

@Arslan106
Copy link

any update????? please help

@CyrusZei
Copy link

CyrusZei commented Jul 26, 2020

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
Copy link

Johbrun commented Jul 29, 2020

Thanks @CyrusZei , it works ! 🎉

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

@CyrusZei
Copy link

Yeah true, removed it from the wrong place 😂

@aeirola
Copy link

aeirola commented Jul 31, 2020

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
Copy link

okwast commented Aug 4, 2020

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
Copy link

kholood-ea commented Aug 16, 2020

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
Copy link

CyrusZei commented Aug 16, 2020 via email

@kholood-ea
Copy link

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
Copy link

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

@wmonecke
Copy link

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
Copy link

wmonecke commented Oct 15, 2020

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: facebook/react-native#27526

@tschanz-pcv
Copy link

@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
Copy link

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
Copy link

v0.9.2 worked and our form showed up again

@magrinj
Copy link

magrinj commented May 16, 2021

Hello everyone,

Just created a hook to handle keyboard input like this lib does, but working more efficiently with bottom tabs, and even if ScrollView is not in full screen, feel free to take a look:

yarn add react-native-use-input-scroll-handler

https://github.com/JMagrin/use-input-scroll-handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests