react-native-modalize icon indicating copy to clipboard operation
react-native-modalize copied to clipboard

This synthetic event is reused for performance reasons

Open mMarcos208 opened this issue 3 years ago • 37 comments

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

mMarcos208 avatar Sep 16 '22 14:09 mMarcos208

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

Tanujgarg avatar Sep 21 '22 11:09 Tanujgarg

same

AleksandrKarashev avatar Oct 06 '22 11:10 AleksandrKarashev

having the same problem after upgrading to 0.70.3

ignaciosantise avatar Oct 24 '22 18:10 ignaciosantise

same

mattgle avatar Nov 01 '22 19:11 mattgle

Same here!

Acetyld avatar Nov 01 '22 19:11 Acetyld

Same here, did anyone manage to solve it?

willLopesz avatar Nov 08 '22 20:11 willLopesz

same here

ckswopnera avatar Nov 09 '22 12:11 ckswopnera

Same

ElGuapo322 avatar Nov 09 '22 12:11 ElGuapo322

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

ckswopnera avatar Nov 11 '22 04:11 ckswopnera

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

mMarcos208 avatar Nov 11 '22 11:11 mMarcos208

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

tacianoscur avatar Nov 11 '22 23:11 tacianoscur

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

tacianoscur avatar Nov 11 '22 23:11 tacianoscur

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

willLopesz avatar Nov 16 '22 16:11 willLopesz

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

mMarcos208 avatar Nov 16 '22 18:11 mMarcos208

I’m not using adjustToContentHeight and still getting the error

tacianoscur avatar Nov 16 '22 19:11 tacianoscur

Guys,

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

https://github.com/facebook/react-native/issues/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.

https://github.com/facebook/react-native/issues/28775#issuecomment-668831226

I removed it and posted it on my github.

Can anyone help me test?

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

mMarcos208 avatar Nov 18 '22 15:11 mMarcos208

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();
     }

huszy avatar Nov 20 '22 22:11 huszy

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.

rakane avatar Dec 13 '22 22:12 rakane

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

evald24 avatar Dec 16 '22 07:12 evald24

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

rizkhal avatar Dec 19 '22 07:12 rizkhal

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

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

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!!

RaimisonMorais avatar Jan 19 '23 20:01 RaimisonMorais

same problem here. does anyone manage to fix this ?

dukizwe avatar Jan 28 '23 06:01 dukizwe

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 avatar Feb 16 '23 09:02 jnoleau

@RaimisonMorais

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

Vitor-SO avatar Feb 20 '23 14:02 Vitor-SO

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.

devsales avatar Apr 05 '23 11:04 devsales

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>

gilceniosantos avatar May 06 '23 03:05 gilceniosantos

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

kmsayem12 avatar Jun 19 '23 07:06 kmsayem12

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.

chrisedington avatar Aug 11 '23 08:08 chrisedington

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

this worked for me!

GabrielMerigo avatar Jan 04 '24 18:01 GabrielMerigo