Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ensure array children #74

Merged
merged 3 commits into from
Jan 30, 2021
Merged

Fix ensure array children #74

merged 3 commits into from
Jan 30, 2021

Conversation

PedroBern
Copy link
Owner

@PedroBern PedroBern commented Jan 30, 2021

an alternative to #69

@alexpchin what you think?

Close #72
Close #68

documentation

// add unique key to each child
React.Children.toArray(children)

@PedroBern PedroBern mentioned this pull request Jan 30, 2021
@PedroBern PedroBern added the preview Trigger expo preview action label Jan 30, 2021
@github-actions
Copy link

The Expo app for the example from this branch is ready!

expo.io/@pedrobern/react-native-collapsible-tab-view-demos?release-channel=pr-74

@alexpchin
Copy link
Contributor

@PedroBern

I'm liking this. However, this is still saying that there has to be more than one element in children?

Another example where there might only be one child is. potentially, is if someone wanted to use this package to render a header with the snap, or diffClamp but without a TabBar - perhaps a Searchbox ontop of results? If we allow one child, then they can re-use the same page structure in the app as a page with more than one tab?

I personally have a use-case in my app (which I know is unusual) where there are multiple user types but the most basic only has one tab as they don't have enough content. However, because of the way the profile page is structured (like Instagram), the user's profile image and details are rendered above the tabs?

@PedroBern
Copy link
Owner Author

PedroBern commented Jan 30, 2021

I'm liking this. However, this is still saying that there has to be more than one element in children?

No, it accepts 1 or more 👍

if (React.Children.count(children) === 0) {
  throw new Error('CollapsibleTabs must have at least one child.')
}

The problem would be with 0 children, but that's not the use case you are saying

@alexpchin
Copy link
Contributor

alexpchin commented Jan 30, 2021 via email

@PedroBern
Copy link
Owner Author

yes you are right, it throws an error with only 1 child! I will investigate now

@PedroBern PedroBern force-pushed the fix-ensure-array-children branch from d7fba55 to 01419a1 Compare January 30, 2021 21:35
@PedroBern
Copy link
Owner Author

PedroBern commented Jan 30, 2021

@alexpchin now it's working the problem was with the indicator component. Works with 1 child, but I would recommend using "scrollable tabs" otherwise it will be one big tab.

@alexpchin
Copy link
Contributor

I've just pulled the latest version. However, I currrently see:

Screenshot 2021-01-30 at 21 52 37

With the type error being:

(property) Container: React.FC<CollapsibleProps<TabNames, MaterialTabBarProps<TabNames>>>
This JSX tag's 'children' prop expects type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>[] | ... 6 more ... | (ReactElement<...>[] & ReactPortal)' which requires multiple children, but only a single child was provided.ts(2745)

And:

Screenshot 2021-01-30 at 21 57 14

Is it working for you?

@PedroBern
Copy link
Owner Author

here is working, but there is this typescript error, I will fix now

WhatsApp Image 2021-01-30 at 19 38 11

@PedroBern
Copy link
Owner Author

I was having this error before, maybe you are not with the latest version, I rebased and forced push

@PedroBern PedroBern force-pushed the fix-ensure-array-children branch from 01419a1 to 95be6c2 Compare January 30, 2021 22:42
@PedroBern
Copy link
Owner Author

PedroBern commented Jan 30, 2021

@alexpchin just rebased and forced push again with the typescript fixes, can you test it?

@PedroBern PedroBern merged commit c137810 into main Jan 30, 2021
@PedroBern
Copy link
Owner Author

I merged, if you see any errors, let me know

@PedroBern PedroBern deleted the fix-ensure-array-children branch February 10, 2021 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Trigger expo preview action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Two children with the same key undefined In a Bare React Native App Ensure that children exists
2 participants