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: Prevent canvas resolution resizing if user passes in resolution values on canvas #116

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zplata
Copy link
Contributor

@zplata zplata commented Aug 2, 2022

Addresses an issue where someone's setting of width/height on the RiveComponent from useRive doesn't get overridden (brought up in Discord).

This is setting data- attributes on the canvas for user-passed in values for width/height resolutions as an indicator for us to see whether or not to override the width/height with our devicePixelRatio logic. This is because from the internals of the hook, we can't tell what user passed-in props (i.e width and/or height) are set on the RiveComponent, but we can look into the ref of the canvas element to check for these attributes.

Definitely open to other ideas here; had to find a way to distinguish between us setting the width/height internally vs consumers setting it via props.

@zplata zplata requested review from avivian and mjtalbot August 2, 2022 04:22
}
if (!heightProp) {
canvasRef.current.height = dpr * height;
}
canvasRef.current.style.width = width + 'px';
Copy link
Contributor

Choose a reason for hiding this comment

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

we still set the style to these new widths / heights?

@@ -130,18 +138,28 @@ export default function useRive(
const boundsChanged =
Copy link
Contributor

Choose a reason for hiding this comment

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

updateBounds be called at all if we have width & height fixed?

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

Successfully merging this pull request may close these issues.

3 participants