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

This synthetic event is reused for performance reasons #451

Open
mMarcos208 opened this issue Sep 16, 2022 · 37 comments
Open

This synthetic event is reused for performance reasons #451

mMarcos208 opened this issue Sep 16, 2022 · 37 comments

Comments

@mMarcos208
Copy link

mMarcos208 commented Sep 16, 2022

ERROR Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property nativeEvent on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https://reactjs.org/link/event-pooling for more information.
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: null is not an object (evaluating '_ref2.nativeEvent.layout')

Reproduce

<Modalize
       modalHeight={600}
       alwaysOpen={130}
       withHandle
       modalStyle={homeModalizeStyles.modalStyle}
       HeaderComponent={position === 'initial' ? <HomeFooter /> : <HomeHeader />}
       FooterComponent={position === 'top' && <HomeFooter />}
       handleStyle={homeModalizeStyles.handleStyle}
       childrenStyle={homeModalizeStyles.childrenStyle}
       onPositionChange={setPosition}
       panGestureComponentEnabled
       flatListProps={{
         data: menu,
         keyExtractor: (item) => item.key,
         showsVerticalScrollIndicator: false,
         numColumns: 3,
         renderItem: ({item}) => {
           return (
             <View style={homeModalizeStyles.alignCenter}>
               <TouchableWithoutFeedback onPress={item.onPress}>
                 <View style={homeModalizeStyles.iconRounded}>
                   {item.isIcon ? (
                     <Icon name={item.icon} size={16} color={colors.black} />
                   ) : (
                     <MaterialCommunityIcons name={item.icon} color={colors.black} size={18} />
                   )}
                 </View>
               </TouchableWithoutFeedback>
               <View style={homeModalizeStyles.labelContainer}>
                 <Text style={homeModalizeStyles.label}>{item.title}</Text>
                 <Text style={homeModalizeStyles.label}>{item.subTitle}</Text>
               </View>
             </View>
           )
         },
       }}
     />

Dependencies:

  • react-native-modalize 2.1.1
  • react-native 0.70.1
  • react-native-gesture-handler ^2.6.1
  • react-native-navigation: not using
@Tanujgarg
Copy link

Tanujgarg commented Sep 21, 2022

I'm having the same problem after updating to 0.70.1.

@AleksandrKarashev

This comment was marked as spam.

@ignaciosantise
Copy link

having the same problem after upgrading to 0.70.3

@mattgle

This comment was marked as spam.

@Acetyld

This comment was marked as spam.

@willLopesz

This comment was marked as spam.

@ckswopnera

This comment was marked as spam.

@ElGuapo322

This comment was marked as spam.

@ckswopnera
Copy link

I downgrade the expo version to 46.0.0 and the error is gone

@mMarcos208
Copy link
Author

@ckswopnera downgrade isn't option. I'm not using expo. downgrade version cause error in Xcode and another things.

@tacianoscur
Copy link

same here.
react-native: 0.70.3
react-native-gesture-handler: ^2.8.0
react-native-modalize: ^2.1.1

@tacianoscur
Copy link

btw on android I can't scroll down to close modal, only by calling .close() function.
don't know if it's related

@willLopesz
Copy link

in my case, this error only occurs when I remove the adjustToContentHeight property, if anyone else can test if this is it?!

@mMarcos208
Copy link
Author

@willLopesz what version of gesture-handler? In my case, I'm not using adjustToContentHeight prop

@tacianoscur
Copy link

I’m not using adjustToContentHeight and still getting the error

@mMarcos208
Copy link
Author

Guys,

In my investigations I found a bug in the onLayout prop of the KeyboardAvoidingView component, which was corrected and merged here:

facebook/react-native#32608

In this lib it is used here in the code:

const AnimatedKeyboardAvoidingView = Animated.createAnimatedComponent(KeyboardAvoidingView);

According to that comment the problems with the Animation.

facebook/react-native#28775 (comment)

I removed it and posted it on my github.

Can anyone help me test?

react-native-modalize: https://github.com/mMarcos208/react-native-modalize

@huszy
Copy link

huszy commented Nov 20, 2022

Hi,
We are using the following patch in our project while it's getting fixed. It persists the original event before the LayoutAnimation occurs. It's far from perfect but works for us.

diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
index 6a343d8..474b2ec 100644
--- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
+++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
@@ -111,6 +111,10 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
       this._initialFrameHeight = this._frame.height;
     }
 
+    if (this.props.onLayout) {
+      event.persist();
+    }
+
     if (wasFrameNull) {
       await this._updateBottomIfNecessary();
     }

@rakane
Copy link

rakane commented Dec 13, 2022

Hi, We are using the following patch in our project while it's getting fixed. It persists the original event before the LayoutAnimation occurs. It's far from perfect but works for us.

diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
index 6a343d8..474b2ec 100644
--- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
+++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
@@ -111,6 +111,10 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
       this._initialFrameHeight = this._frame.height;
     }
 
+    if (this.props.onLayout) {
+      event.persist();
+    }
+
     if (wasFrameNull) {
       await this._updateBottomIfNecessary();
     }

For me this patch causes the error is no longer being thrown. However the modal can only be closed with close(), not via swipe.

Edit: I accidentally was missing the GestureHandlerRootView in my main App.tsx file. Adding fixed the issue with swipe events not working.

@evald24
Copy link

evald24 commented Dec 16, 2022

I have a similar problem. There is no re-rendering of elements inside a modal on Android =(

react: 18.1.0
react-native: 0.70.6
react-native-modalize: 2.1.1
react-native-portalize: 1.0.7
react-native-gesture-handler: 2.8.0

@rizkhal
Copy link

rizkhal commented Dec 19, 2022

add adjustToContentHeight props with true value and set height using childrenStyle props

@mariomurrent-softwaresolutions

add adjustToContentHeight props with true value and set height using childrenStyle props

But what if i dont want to set the height fixed?

@RaimisonMorais
Copy link

I'm using Expo.
I went to "node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js"

where is:
if (this.props.onLayout) {
this.props.onLayout(event);
}

replaces to:
if (this.props.onLayout) {
event.persist();
//this.props.onLayout(event);
}

It worked here!!

@dukizwe
Copy link

dukizwe commented Jan 28, 2023

same problem here. does anyone manage to fix this ?

@jnoleau
Copy link

jnoleau commented Feb 16, 2023

add adjustToContentHeight props with true value and set height using childrenStyle props

hacky but working and fixed height is preserved.

for example replace

<Modalize
  modalHeight={370}
  ...
/>

with

<Modalize
  adjustToContentHeight
  childrenStyle={{ height: 370 }}
  ...
/>

@Vitor-SO
Copy link

@RaimisonMorais

the error stoped but the modal dont open if i press back button and try open the modal again.

@devsales
Copy link

devsales commented Apr 5, 2023

add adjustToContentHeight props with true value and set height using childrenStyle props

hacky but working and fixed height is preserved.

for example replace

<Modalize
  modalHeight={370}
  ...
/>

with

<Modalize
  adjustToContentHeight
  childrenStyle={{ height: 370 }}
  ...
/>

Thanks, works for me too! The snapPoint prop is no longer needed and has to be left empty.

@gilceniosantos
Copy link

mesmo aqui. react-native: 0.70.3 react-native-gesture-handler: ^2.8.0 react-native-modalize:^2.1.1

btw no android não consigo rolar para baixo para fechar o modal, apenas chamou .close()a função. não sei se está relacionado

Basta fazer isto em seu App.js

<GestureHandlerRootView style={{ flex: 1 }}> <View/> </GestureHandlerRootView>

@kmsayem12
Copy link

add adjustToContentHeight props with true value and set height using childrenStyle props

hacky but working and fixed height is preserved.

for example replace

<Modalize
  modalHeight={370}
  ...
/>

with

<Modalize
  adjustToContentHeight
  childrenStyle={{ height: 370 }}
  ...
/>

@jnoleau Thank you. Work for me

@chrisedington
Copy link

add adjustToContentHeight props with true value and set height using childrenStyle props

hacky but working and fixed height is preserved.

for example replace

<Modalize
  modalHeight={370}
  ...
/>

with

<Modalize
  adjustToContentHeight
  childrenStyle={{ height: 370 }}
  ...
/>

This also solves a bit of a memory/performance issue related to the initial problem.

@GabrielMerigo
Copy link

add adjustToContentHeight props with true value and set height using childrenStyle props

this worked for me!

@ngdbao
Copy link

ngdbao commented Feb 25, 2024

add adjustToContentHeight props with true value and set height using childrenStyle props

hacky but working and fixed height is preserved.

for example replace

<Modalize
  modalHeight={370}
  ...
/>

with

<Modalize
  adjustToContentHeight
  childrenStyle={{ height: 370 }}
  ...
/>

It indeed ending error log, but this way prevents scrollable-gesture in child flatlist

@danieljimol
Copy link

Hi, We are using the following patch in our project while it's getting fixed. It persists the original event before the LayoutAnimation occurs. It's far from perfect but works for us.

diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
index 6a343d8..474b2ec 100644
--- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
+++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
@@ -111,6 +111,10 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
       this._initialFrameHeight = this._frame.height;
     }
 
+    if (this.props.onLayout) {
+      event.persist();
+    }
+
     if (wasFrameNull) {
       await this._updateBottomIfNecessary();
     }

For me this patch causes the error is no longer being thrown. However the modal can only be closed with close(), not via swipe.

Edit: I accidentally was missing the GestureHandlerRootView in my main App.tsx file. Adding fixed the issue with swipe events not working.

This worked for me, thanks.

@Areeb0206
Copy link

add adjustToContentHeight props with true value and set height using childrenStyle props

hacky but working and fixed height is preserved.

for example replace

<Modalize
  modalHeight={370}
  ...
/>

with

<Modalize
  adjustToContentHeight
  childrenStyle={{ height: 370 }}
  ...
/>

what about scrolling?

@Areeb0206
Copy link

I utilized a promise to coerce the module to believe that avoidKeyboardLikeIOS is true on modal rendering, and then flipped to false, resulting in the desired performance on Android.

const returnTrueThenFalse = () => new Promise(resolve => setTimeout(() => resolve(false), 1000));
const handleAvoidKeyboardLikeIOS = () => { return isIOS ? true : (returnTrueThenFalse().then() as unknown as boolean); };
avoidKeyboardLikeIOS={handleAvoidKeyboardLikeIOS()}

Scrolling will operate in one direction. If you were scrolling, you can travel both directions, but when you want to scroll to the top, it won't.

@Areeb0206
Copy link

onClose={() => {}}
withReactModal={true}

add these props
scrolling will work and the error will be removed
"expo": "~51.0.28",
"react-native-modalize": "^2.1.1",
"react-native": "0.74.5",

@Areeb0206
Copy link

Areeb0206 commented Aug 15, 2024

I utilized a promise to coerce the module to believe that avoidKeyboardLikeIOS is true on modal rendering, and then flipped to false, resulting in the desired performance on Android.

const returnTrueThenFalse = () => new Promise(resolve => setTimeout(() => resolve(false), 1000)); const handleAvoidKeyboardLikeIOS = () => { return isIOS ? true : (returnTrueThenFalse().then() as unknown as boolean); }; avoidKeyboardLikeIOS={handleAvoidKeyboardLikeIOS()}

Scrolling will operate in one direction. If you were scrolling, you can travel both directions, but when you want to scroll to the top, it won't.

this will remove error,

onClose={() => {}}
withReactModal={true}

"expo": "~51.0.28",
"react-native-modalize": "^2.1.1",
"react-native": "0.74.5",

and this will enable scrolling

@codeserk
Copy link

any solution for this? nothing in the thread seems to work for my case:
I have a FlatList, so I really need to remove adjustToContentHeight because otherwise the behavior is quite broken if I try to scroll up(model gets closed instead of scrolling in the flat list) - and with the adjustToContentHeight off + static height I have this error/warning?

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