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

Added possibility to filter & ignore suggested size change events #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kirchet
Copy link

@kirchet kirchet commented Jun 9, 2023

Added possibility to filter & ignore suggested size change events

Before:

const binding = bindCanvasElementBitmapSizeTo(canvas, {
  type: 'device-pixel-content-box',
  transform: (bitmapSize: Size, canvasElementClientSize: Size) => ({
    // no way to ignore `subscribeSuggestedBitmapSizeChanged` listeners 😒
    width: Math.max(bitmapSize.width, canvasElementClientSize.width),
    height: Math.max(bitmapSize.height, canvasElementClientSize.height),
  }),
});

Now:

const binding = bindCanvasElementBitmapSizeTo(canvas, {
  type: 'device-pixel-content-box',
  transform: (bitmapSize: Size, canvasElementClientSize: Size) => {
    if (bitmapSize.width === 0 && bitmapSize.height === 0) {
      // ignore zero size resize events 🎉
      return null;
    }
    return {
      width: Math.max(bitmapSize.width, canvasElementClientSize.width),
      height: Math.max(bitmapSize.height, canvasElementClientSize.height),
    }
  }),
});

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.

1 participant