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

Cannot read property 'layout' of null

Open abdullahIsa opened this issue 2 years ago • 29 comments

Hello i am getting this error.

"react-native": "0.70.4" "react-native-modalize": "^2.1.1"

image

abdullahIsa avatar Nov 02 '22 16:11 abdullahIsa

Same problem.

"react-native": "0.70.5", "react-native-modalize": "^2.1.1",

jersonpl avatar Nov 07 '22 18:11 jersonpl

same here

RalissonMattias avatar Nov 11 '22 10:11 RalissonMattias

Same problem.

"react-native": "0.70.5", "react-native-modalize": "^2.1.1",

Ilannildo avatar Nov 11 '22 13:11 Ilannildo

Yep also getting this issue:

"react-native-modalize": "^2.0.13",
"react-native": "0.70.5",

alexfoxy avatar Nov 15 '22 12:11 alexfoxy

I'm having the same problem, but it 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

same here,

"react-native": "0.70.5", "react-native-modalize": "^2.1.1",

filipepalheta avatar Nov 22 '22 15:11 filipepalheta

@willLopesz I see the same behaviour.

cedricjacobs avatar Nov 23 '22 22:11 cedricjacobs

@willLopesz I just tested this. The warning only occurs when I use modelHeight instead of adjustToContentHeight. It also occurs when I use neither of these props. Once I set adjustToContentHeight to true, the warning disappears.

"react-native": "0.70.6",
"react-native-modalize": "^2.0.13",

EDIT: And it only happens on Android for me. I have Hermes activated, too.

aryella-lacerda avatar Nov 30 '22 13:11 aryella-lacerda

@aryella-lacerda Exactly what happens to me, android only, but I need to limit the height because it is a flatlist, did anyone manage to solve it?

willLopesz avatar Dec 01 '22 16:12 willLopesz

Any solution for this warning? @jeremybarbet

Kirangaira avatar Dec 26 '22 10:12 Kirangaira

Same problem with no solution. I tried to define AdjustToContentHeight, but it is bad when there is a SearchBar. By setting avoidKeyboardLikeIOS it passes the screen height in android. @jeremybarbet

"react-native": "0.70.6", "react-native-modalize":"^2.1.1",

nathangabriel27 avatar Jan 09 '23 15:01 nathangabriel27

Any solution to avoid this warning when using modalHeight? @jeremybarbet

Kirangaira avatar Jan 18 '23 05:01 Kirangaira

any news here

MarouaniALA avatar Feb 26 '23 15:02 MarouaniALA

I'm not sure what it does but adding avoidKeyboardLikeIOS={true} removed the warning

Sheharyar566 avatar Feb 27 '23 06:02 Sheharyar566

It happens because of the following code:

if (!avoidKeyboardLikeIOS && !adjustToContentHeight) {
    keyboardAvoidingViewProps.onLayout = handleModalizeContentLayout;
}

And the handleModalizeContentLayout has an unhandled promise rejection

const handleModalizeContentLayout = ({ nativeEvent: { layout } }) => {
    const value = Math.min(layout.height + (!adjustToContentHeight || keyboardHeight ? layout.y : 0), endHeight -
        react_native_1.Platform.select({
            ios: 0,
            android: keyboardHeight,
            default: 0,
        }));
    setModalHeightValue(value);
};

You are getting that warning, what's the solution, make false the condition in the if sentence, how? by making avoidKeyboardLikeIOS or adjustToContentHeight true.

amerllica avatar Mar 01 '23 23:03 amerllica

@amerllica você criou pr?

carlosdavid0 avatar Apr 27 '23 14:04 carlosdavid0

I'm facing the same issue.

mmkhmk avatar May 16 '23 07:05 mmkhmk

Esto funciona para mi 😃 <Modalize disableScrollIfPossible={false} adjustToContentHeight={true}> {children} </Modalize>

mcvictormurillo avatar May 16 '23 12:05 mcvictormurillo

I don't know how much healthy it is but I used a promise to force the modilize to think that avoidKeyboardLikeIOS is true on rendering of modal and after switch to false and my perfomance on Android remains as I want.

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

vvv-sss avatar May 27 '23 18:05 vvv-sss

Same here, this can be particularly problematic to work around when using many inputs in the component.

germanao avatar Jun 11 '23 16:06 germanao

i still get this error on Android, the content of my Modelize change ( i have accordion inside Modalize to show/hide long text content so height change) and i use onLayout to compute children height. adjustToContentHeight not working to add scroll on the fly.


import React, {useState, forwardRef} from 'react';
import {Dimensions, View, Platform} from 'react-native';

import {Modalize} from 'react-native-modalize';
import {Portal} from 'react-native-portalize';

const {height: windowHeight} = Dimensions.get('window');

/**
 * Modalize is a scrollview by default, but it doesn't work on android when we don't
 * put height in pixels with adjustToContentHeight={true} parameter
 *
 * this component compute child height and set modalHeight
 */
const ModalizeAdjustToContentHeight = forwardRef((props, ref) => {
  const [childHeight, setChildHeight] = useState(0);
  const [modalHeight, setModalHeight] = useState(0);
  const {adjustToContentHeight, footerHeaderHeight, children, ...mprops} =
    props;
  const enableComputedHeight = adjustToContentHeight && Platform.OS !== 'ios';

  const handleOnLayoutChange = (height: number) => {
    const m = footerHeaderHeight
      ? windowHeight - footerHeaderHeight
      : windowHeight;
    const mh = Math.min(height, m);

    setModalHeight(mh);
    setChildHeight(height);
  };

  const renderContent = () => {
    if (Platform.OS === 'ios') {
      return (
        <Portal>
          <Modalize
            {...mprops}
            ref={ref}
            adjustToContentHeight={adjustToContentHeight}>
            {children}
          </Modalize>
        </Portal>
      );
    }
    return (
      <Portal>
        <Modalize
          {...mprops}
          ref={ref}
          adjustToContentHeight={false}
          childrenStyle={
            enableComputedHeight && childHeight !== 0
              ? {height: childHeight}
              : null
          }
          modalHeight={modalHeight}>
          <View
            onLayout={(event: any) => {
              if (enableComputedHeight) {
                const {height} = event?.nativeEvent?.layout;
                handleOnLayoutChange(height);
              }
            }}>
            {children}
          </View>
        </Modalize>
      </Portal>
    );
  };

  return renderContent();
});

export default ModalizeAdjustToContentHeight;

alainib avatar Jul 26 '23 09:07 alainib

It would be nice if someone of the contributors for this api could make after 4 months bug localization a PR to fix this in the code base. Thanks!

lortschi avatar Aug 01 '23 09:08 lortschi

Hello, I have the same problem. I really hope receive the answer . Thanks so much :<

tuanngocptn avatar Sep 15 '23 18:09 tuanngocptn

Same here. Cannot use the workaround with scrollable height with inputs.

Orijinn-github avatar Oct 02 '23 10:10 Orijinn-github

Same here. Is this lib still being maintained by anyone?

AndreCosta101 avatar Oct 28 '23 02:10 AndreCosta101

I stopped at this error

I added the react-native-gesture-handler library to the project and called it in app.ts like this

`import React, { useEffect, useRef, useState } from "react"; import Routes from "./src/Routes/index.routes"; import { GestureHandlerRootView } from "react-native-gesture-handler";

export default function App() {

return ( <GestureHandlerRootView style={{ flex: 1 }} > <Routes /> </GestureHandlerRootView> ); }`

carlosdavid0 avatar Oct 28 '23 17:10 carlosdavid0

If anyone still searching, you can use modalHeight option but you should set avoidKeyboardLikeIOS={true} and keyboardAvoidingBehavior={isIos() ? undefined : 'height'}

MarouaniALA avatar Jan 21 '24 21:01 MarouaniALA

I stopped at this error

I added the react-native-gesture-handler library to the project and called it in app.ts like this

`import React, { useEffect, useRef, useState } from "react"; import Routes from "./src/Routes/index.routes"; import { GestureHandlerRootView } from "react-native-gesture-handler";

export default function App() {

return ( <GestureHandlerRootView style={{ flex: 1 }} > ); }`

It works

Vimal1464 avatar Feb 04 '24 10:02 Vimal1464

same as well for me im running 0.71.17 was having unresponsive modal in android and my hermes is is enabled

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

this works but the warning is still there

arnoldc avatar Apr 01 '24 03:04 arnoldc