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: View component supports non-full screen use cases #981

Merged
merged 3 commits into from Nov 21, 2022

Conversation

kmannislands
Copy link
Contributor

Why

Resolves #944

What

Since the upstream fix to @react-three/fiber has been released in v8.1.0, this takes advantage of the position information to get View working as expected in non-fullscreen use cases.

Additionally, a warning is logged (using console.warn) if an older version of react-three-fiber is detected. I couldn't find any existing logging infrastructure for this type of dev mode warning at a glance so I opted to keep it simple. Please advise if there is a better approach here.

Checklist

  • Documentation updated
  • Storybook entry added
  • Ready to be merged

@vercel
Copy link

vercel bot commented Jul 12, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
drei ✅ Ready (Inspect) Visit Preview Jul 28, 2022 at 9:10PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 12, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d0f6751:

Sandbox Source
stoic-waterfall-rbq5v3 Configuration
Ground reflections and video textures Configuration
arc-x-pmndrs-colors Configuration
View skissor (forked) Issue #944

@kmannislands
Copy link
Contributor Author

Handling seems correct with latest react-three-fiber: https://codesandbox.io/s/view-skissor-forked-cxyur1?file=/src/App.js

Confirmed that the warning message is logged with older versions but the bottom two views have gone missing: https://codesandbox.io/s/view-skissor-forked-249ngx

I'll investigate

@FarazzShaikh
Copy link
Member

FarazzShaikh commented Jul 13, 2022

The bug in the old version box is that the isOffscreen calculation requires the bottom value to be before it is converted to the positiveYUpBottom form

drei/src/web/View.tsx

Lines 44 to 46 in c7fa011

const { left, right, top, bottom, width, height } = rect.current
const isOffscreen = bottom < 0 || top > canvasSize.height || right < 0 || left > canvasSize.width
const positiveYUpBottom = canvasSize.height - bottom

Fixed box: https://codesandbox.io/s/view-skissor-forked-gvhfg1?file=/src/View.tsx:2788-2912

Any ideas why the "incorrect" isOffscreen calc works in this verison? Or perhaps it is infact wrong in the current version

Copy link
Member

@FarazzShaikh FarazzShaikh left a comment

Choose a reason for hiding this comment

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

Looks great to me!

@FarazzShaikh FarazzShaikh requested a review from drcmda July 13, 2022 17:01
@kmannislands
Copy link
Contributor Author

Implemented a speculative fix. I think I'll add a story (Abstractions/View ?) for this when I have a moment to make informal testing easier.

@itsthekeming
Copy link

Any update on this?

@joshuaellis joshuaellis merged commit 35c3600 into pmndrs:master Nov 21, 2022
@github-actions
Copy link

🎉 This PR is included in version 9.42.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<View /> Component assumes that the canvas is full screen
4 participants