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

Accordion active section does not expand on initial render

Open ravindraguptacapgemini opened this issue 1 year ago • 18 comments

@oblador I am using the latest version of the library 1.6.2 with React Native 0.75.3, When the Accordion is rendered for the first time it does not expand the activeSection, attaching link for reproducer app https://snack.expo.dev/@ravindragupta_intelex/react-native-collapsible-demo

ravindraguptacapgemini avatar Nov 14 '24 11:11 ravindraguptacapgemini

After updating to Expo@52, I encountered the same issue.

czy0729 avatar Nov 14 '24 11:11 czy0729

Yep, I'm experiencing this issue as well

benjaminharringtonrose avatar Nov 26 '24 12:11 benjaminharringtonrose

I have the same issue after upgrading react-native to v74 and android sdk to 34

Ali-Oliaee avatar Dec 12 '24 08:12 Ali-Oliaee

yup, same here after Expo@52

CristianMihai26 avatar Dec 12 '24 13:12 CristianMihai26

Same.

"react-native-collapsible": "^1.6.2",
"react-native": "0.73.10",

adstr123 avatar Jan 07 '25 13:01 adstr123

Also happens with Collapsible without Accordion. Expo 52.

augusthjerrild avatar Jan 29 '25 14:01 augusthjerrild

see #479, downgrading to 1.6.1 worked for me.

donni106 avatar Jan 31 '25 15:01 donni106

see #479

Actually, I changed it a long time ago. Although it works, the unfolding animation is still clearly problematic.

czy0729 avatar Jan 31 '25 15:01 czy0729

I am also facing the same, with RN 0.77 (new arch). Going back to 1.6.1 is not an ideal solution as 1.6.2 fixes some new arch bugs

pranshuchittora avatar Feb 04 '25 01:02 pranshuchittora

I have the same issue with Collapsible and Accordion. @oblador are there plans to fix this? This issue is rendering this package useless due to the terrible user experience

jadonhansen avatar Feb 17 '25 06:02 jadonhansen

same issue here. so annoying to use now

jwitthaus avatar Apr 04 '25 20:04 jwitthaus

@oblador this is really a major blocker with newer react native version, could you please respond with any timeline to release a fix. Thanks.

ravindraguptacapgemini avatar Apr 08 '25 09:04 ravindraguptacapgemini

@jadonhansen have you found any fix for the issue?

ravindraguptacapgemini avatar Apr 08 '25 09:04 ravindraguptacapgemini

Root Cause & Solution

The issues with Collapsible/Accordion started when this code change was introduced in PR #475:

- const style = hasKnownHeight && { overflow: 'hidden', height: height }
+ const style = { overflow: 'hidden', height: hasKnownHeight ? height : 0 }

This change forces a height of 0 when the height is not yet known, which causes the initial render issues and broke initially open collapsibles (as noted by @VNDRN in PR #475). The solution is simple - use unset instead of 0:

- const style = { overflow: 'hidden', height: hasKnownHeight ? height : 0 }
+ const style = { overflow: 'hidden', height: hasKnownHeight ? height : 'unset' }

This allows the content to naturally flow and be visible on initial render, while still maintaining the animation capabilities for subsequent interactions.

I can submit a PR with this fix if needed @oblador. This should resolve the issues reported in #485 without requiring complex height calculations or state management.

msultanic avatar Apr 09 '25 13:04 msultanic

@msultanic, I have made a patch using your suggested fix. This is a fantastic workaround until the author makes an official fix. Thank you!

TheRealMikeD avatar May 01 '25 19:05 TheRealMikeD

@msultanic "unset" is not valid CSS in RN so probably better to use undefined which has worked from my testing

Harry-Johnston avatar Oct 06 '25 16:10 Harry-Johnston

Works great with undefined. const style = { overflow: 'hidden', height: hasKnownHeight ? height : undefined }

GEMI avatar Nov 10 '25 15:11 GEMI

Downgrading to 1.6.1 worked for me.

cesarlima-plank avatar Nov 28 '25 18:11 cesarlima-plank