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

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

Fix elements not rendering on v0.63.0 #441

Closed Esxiel closed 3 years ago

Esxiel commented 4 years ago

Fixes issue on #429 ...while also still supporting the HOC usage

Fausto95 commented 4 years ago

I've tried to apply the same fix, but seems to not be working

Esxiel commented 4 years ago

This addresses the issue where in v0.63.0 you get a warning of Functions are not valid as a React child ... and nothing within the KeyboardAwareScrollView renders. Full warning description

Can you define not working? Is the same warning still showing up? Or did the warning disappear but your elements are not rendering? Or perhaps you mean the HOC isn't working?

Fausto95 commented 4 years ago

It's not rendering the elements.

davidgovea commented 4 years ago

Working here!

I'm using this change via patch-package

patches/react-native-keyboard-aware-scroll-view+0.9.1.patch

diff --git a/node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js b/node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
index 4bf0ed0..c17e886 100644
--- a/node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
+++ b/node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js
@@ -545,8 +545,10 @@ function KeyboardAwareHOC(
 // Allow to pass options, without breaking change, and curried for composition
 // listenToKeyboardEvents(ScrollView);
 // listenToKeyboardEvents(options)(Comp);
-const listenToKeyboardEvents = (configOrComp: any) => {
-  if (typeof configOrComp === 'object') {
+const listenToKeyboardEvents = (configOrComp: React.ReactElement | KeyboardAwareHOCProps) => {
+  if (configOrComp?.displayName === "ScrollView") {
+    return KeyboardAwareHOC(configOrComp)
+  } else if (typeof configOrComp === 'object') {
     return (Comp: Function) => KeyboardAwareHOC(Comp, configOrComp)
   } else {
     return KeyboardAwareHOC(configOrComp)

Thank you @Esxiel !

Esxiel commented 4 years ago

Thank you for notifying me that it works, I thought there was a use-case that I broke or something. @Fausto95 can't say for sure why it's not working for you, but if you don't/didn't have the Functions are not valid as a React child ... problem, then the problem you're facing is probably a different one.

Perhaps styling problems? I had faced similar problems of elements not rendering simply due to my mistake on the styling...

codler commented 4 years ago

I have forked the repo to fix this issue.


npm i @codler/react-native-keyboard-aware-scroll-view
patrickschmelter commented 4 years ago

working for me too

rborn commented 4 years ago

@Esxiel @codler thanks for your PRs

Is it safe to consider that this PR is a duplicate of https://github.com/APSL/react-native-keyboard-aware-scroll-view/pull/442 (merged now) ?

Thanks