Forcing onLayout on React Native view
You can have a unique key based on the content. whenever a key attribute of a component changes it is forcing a re-render.
Method this.calculateDimensions
needs to have some kind of indication, that it should be called again and fire re-render. I would recommend to use for its state or memo.
Let me show you an example with React Hooks. I'm setting for component onLayout
, which using callback onComponentLayout. onComponentLayout
has state componentHeight
, which fire re-render whenever it's changed. So I'm able to change it dynamically if componentHeight is missing.
...const onComponentLayout = useCallback(({nativeEvent: {layout}}) => { !componentHeight && setComponentHeight(layout.height);}, [componentHeight, setComponentHeight]);...return (... <Component onLayout={onComponentLayout} />...)