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

Version 1.6.2 stops working on react-native 0.74.5

Open outaTiME opened this issue 1 year ago • 20 comments

Hello there, a while ago I updated to the new version and it stopped working on react-native 0.74.5, I do not know if it is something expected but at the moment I left forced to the previous version that still works perfectly.

v1.6.1 v1.6.2
CleanShot 2024-08-27 at 20 23 20 CleanShot 2024-08-27 at 20 24 25

See how in the new version (1.6.2) as soon as the screen loads nothing is displayed and should do as seen on version 1.6.1.

Note: ignoring the warning below is a behavior of my application.

outaTiME avatar Aug 27 '24 23:08 outaTiME

Hmm, probably caused by https://github.com/oblador/react-native-collapsible/pull/475

Do you have a small reproduction of this issue?

oblador avatar Aug 28 '24 12:08 oblador

Same for me I had to downgrade to 1.6.1 for it to work again

18jad avatar Aug 28 '24 14:08 18jad

Same issue for me 1.6.2 is no longer working with Expo 51

nlarif avatar Aug 29 '24 14:08 nlarif

Same Issue for me

thehellmaker avatar Aug 30 '24 07:08 thehellmaker

Same issue for me. It occurred after I updated to Expo 51 SDK (react native 0.74). The issue is exactly the same as the OP. The view is not rendered initially (when 'collapsed' is set to false), you must set it to true then to false for it to show the content.

Abdulazeez-98 avatar Aug 31 '24 14:08 Abdulazeez-98

Same issue with 1.6.1. if collapsed is default to true, content is not expanded. This was working before upgrading to react-native 0.74.5

oliviercperrier avatar Sep 05 '24 21:09 oliviercperrier

Had to rollback to 1.5.2. (You might lose some features). NOTE: Expanding and collapsing very quickly will throw an error: this.contentHandle.getNode() is not a function. The ref is basically is the reference to Animated.View, for which getNode() does not work anymore. Instead you can call .measure(...) directly on the ref. So, you should patch the package. From: image To: image

nijatkazimliPG avatar Sep 06 '24 13:09 nijatkazimliPG

Same issue for me on react-native 0.73.9 with 1.6.2. 1.6.1 works well.

ElicaInc avatar Sep 08 '24 13:09 ElicaInc

RCA:

In https://github.com/oblador/react-native-collapsible/blob/038f436c9bdb8f7876fc2d4e98d0553737889da7/Collapsible.js#L191

Height will be 0 if hasKnownHeight is false. But hasKnownHeight is true only when users expand options (collapsed change from true to false)

https://github.com/oblador/react-native-collapsible/blob/038f436c9bdb8f7876fc2d4e98d0553737889da7/Collapsible.js#L45

In case the collapse is false initially, we should show the content, but we don’t have the logic to measure content -> hasKnownHeight is false -> height is 0

Solution:

We should trigger _toggleCollapsed in componentDidMount or _handleLayoutChange if this.props.collapsed is false

  componentDidMount(){
    if(!this.props.collapsed){
      this._toggleCollapsed(this.props.collapsed)
    }
  }

truph01 avatar Sep 09 '24 07:09 truph01

@oblador What do you think about my solution above?

truph01 avatar Sep 10 '24 10:09 truph01

Same issue.

Kreshnik avatar Sep 12 '24 14:09 Kreshnik

In case the collapse is false initially, we should show the content, but we don’t have the logic to measure content

@truph01 I agree with the RCA, initially we don't have a logic to measure the content height and due to that height will remain 0 initially.

componentDidMount(){
 if(!this.props.collapsed){
   this._toggleCollapsed(this.props.collapsed)
 }
}

As proposed I think either we need to call function _toggleCollapsed or we can call _measureContent to avoid animation.

@truph01 can you plz raise a PR, @oblador will review it there.

Pujan92 avatar Sep 14 '24 12:09 Pujan92

@oblador @Pujan92 PR is ready to review

truph01 avatar Sep 17 '24 02:09 truph01

RCA:

In

https://github.com/oblador/react-native-collapsible/blob/038f436c9bdb8f7876fc2d4e98d0553737889da7/Collapsible.js#L191

Height will be 0 if hasKnownHeight is false. But hasKnownHeight is true only when users expand options (collapsed change from true to false)

https://github.com/oblador/react-native-collapsible/blob/038f436c9bdb8f7876fc2d4e98d0553737889da7/Collapsible.js#L45

In case the collapse is false initially, we should show the content, but we don’t have the logic to measure content -> hasKnownHeight is false -> height is 0

Solution:

We should trigger _toggleCollapsed in componentDidMount or _handleLayoutChange if this.props.collapsed is false

  componentDidMount(){
    if(!this.props.collapsed){
      this._toggleCollapsed(this.props.collapsed)
    }
  }

Thank you so much.

hvq1919 avatar Sep 23 '24 10:09 hvq1919

Here is a diff based on the PR @Pujan92 was kind enough to file.

index dc4d3b8..d69d1e7 100644
--- a/node_modules/react-native-collapsible/Collapsible.js
+++ b/node_modules/react-native-collapsible/Collapsible.js
@@ -53,6 +53,12 @@ export default class Collapsible extends Component {
 
   contentHandle = null;
 
+  componentDidMount() {
+    if (!this.props.collapsed) {
+      this._measureContent((height) => this.state.height.setValue(height));
+    }
+  }
+
   _handleRef = (ref) => {
     this.contentHandle = ref;
   };```

sentry0 avatar Sep 29 '24 18:09 sentry0

In my case, I encountered a crash when rotating the device to landscape mode under specific circumstances. The crash occurred if I opened a modal from the page where the accordion component is used, and the modal supports landscape orientation. To prevent this, I had to add an additional check to the patch. Without this fix, rotating the device while the modal is open causes the app to crash.

+  componentDidMount() {
+    if (!this.props.collapsed) {
+      this._measureContent((height) => height != null && this.state.height.setValue(height));
+    }
+  }
+

acidealista avatar Oct 16 '24 08:10 acidealista

Experiencing the same with 1.6.2 and RN 0.72.3 and Expo 49.0.5. Downgrading to 1.6.1 worked for me.

Not sure why @oblador is ignoring this PR though...

jadonhansen avatar Oct 30 '24 20:10 jadonhansen

@oblador please plan to merge the PR. Thanks

ravindraguptacapgemini avatar Nov 27 '24 12:11 ravindraguptacapgemini

I've created a fork with the fix. You can just use the following line in your package.json

    "react-native-collapsible": "github:sheff3rd/react-native-collapsible#master",

I took this comment as a base: https://github.com/oblador/react-native-collapsible/pull/480#discussion_r1763553225

Kudos to @Pujan92 and @truph01 for working on the fix

technoch1ef avatar Dec 30 '24 16:12 technoch1ef

componentDidMount() {
+    if (!this.props.collapsed) {
+      this._measureContent((height) => this.state.height.setValue(height));
+    }
+  }

Works for me, thanks! I was encountering this issue on RN 73 with V1.6.2 of this lib.

People can use patch-package to retain this change across installs 👍

adstr123 avatar Jan 07 '25 14:01 adstr123