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 BottomSheetBackdrop "falsey" defaults #793

Merged
merged 4 commits into from
Apr 22, 2022

Conversation

jakobo
Copy link
Contributor

@jakobo jakobo commented Dec 23, 2021

This is a change to how BottomSheetBackdrop handles its falsey defaults. Values such as 0 and false will automatically assume their fallback values instead of allowing their literal 0 or false to be applied. There is a reproducible Snak in #779 which shows the problem.

https://snack.expo.dev/@jakobo/bottomsheetbackdrop---appearsonindex-bug

Motivation

The fix is to ensure that the provided value was truly undefined before assigning the default. This patch uses nullish coalesce ?? to achieve that. The following code will never render a backdrop.

const renderBackdrop = useCallback(
  props => (
    <BottomSheetBackdrop
      {...props}
      disappearsOnIndex={-1}
      appearsOnIndex={0}
    />
  ),
  []
);

Under the hood, BottomSheetBackdrop will assign 1 for appearsOnIndex because JS treats 0 as false-like.

Contributing Guidelines ✅

  • Prefer small pull requests focused on one change.
  • Verify that linters and tests are passing.
    • note There were additional unrelated prettier errors which were fixed in the second commit
  • Review the documentation to make sure it looks good.
  • Follow the pull request template when opening a pull request.
  • For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.

@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@jakobo
Copy link
Contributor Author

jakobo commented Jan 23, 2022

@gorhom, let me know if there's anything I can do to help get this PR approved. I'll continue to rebase as necessary since the changes are scoped to mostly the Backdrop component

Coercion of 0 and false result in defaults being accidentally assigned
to the BottomSheetBackdrop's props. This fix uses the null coalesce
operator ?? to use either a user supplied value or fall back to the
built-in default.

Resolves gorhom#779
Fixed errors found by running `yarn typescript` and `yarn lint` to fix
errors that could not be automatically fixed.
@jakobo jakobo force-pushed the jakobo/779/BottomSheetBackdrop_defaults branch from 439b4d4 to 73e8cb2 Compare January 25, 2022 01:58
@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@jakobo
Copy link
Contributor Author

jakobo commented Feb 24, 2022

Rebase verification (and un-stale): Current branch jakobo/779/BottomSheetBackdrop_defaults is up to date.

@IngyuTae
Copy link

Hi, @gorhom Do you have any plan on this PR?

@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@jakobo
Copy link
Contributor Author

jakobo commented Apr 13, 2022

@gorhom (ping) The fix is 3 Stalebots old. Would love to land this.

@gorhom gorhom self-requested a review April 21, 2022 07:52
@gorhom gorhom added the v4 Written in Reanimated v2 label Apr 21, 2022
@gorhom
Copy link
Owner

gorhom commented Apr 21, 2022

hi @jakobo, thanks for submitting this PR, i left one comment regarding the name convention for the props.

@gorhom gorhom self-assigned this Apr 21, 2022
…SheetBackdrop_defaults

* upstream/master:
  chore: updated react native portal library
  fix: always update container height to avoid races. (gorhom#919)(by @elan)
@jakobo
Copy link
Contributor Author

jakobo commented Apr 22, 2022

Applied the requested changes, @gorhom. Let me know if there's any other changes. 🎉

@jakobo jakobo requested a review from gorhom April 22, 2022 19:18
Copy link
Owner

@gorhom gorhom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jakobo for updating the naming! this will be release on the next patch release

@gorhom gorhom merged commit 7e00dd2 into gorhom:master Apr 22, 2022
@jakobo jakobo deleted the jakobo/779/BottomSheetBackdrop_defaults branch May 9, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v4 Written in Reanimated v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants