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

Scale the page programmatically to fit the screen #17

Open
segicm opened this issue Sep 21, 2022 · 2 comments
Open

Scale the page programmatically to fit the screen #17

segicm opened this issue Sep 21, 2022 · 2 comments

Comments

@segicm
Copy link

segicm commented Sep 21, 2022

Hi, is there a way to scale the page to fit the device screen?
This is how I am using the Webshell now:

const Webshell = useMemo(
    () =>
      makeWebshell(
        WebView,
        new HandleHTMLDimensionsFeature(),
        new ForceResponsiveViewportFeature({
          maxScale: 1.5,
          // initScale: 0.65,
          minScale: 0.25,
        }),
        new ForceElementSizeFeature({
          target: 'body',
          heightValue: 'auto',
          widthValue: 'auto',
        }),
        new HandleVisualViewportFeature()
      ),
    []
  );

Responsive pages fit perfectly, but the ones with fixed-width elements will go out of the screen.
I need to scale those pages to fit the width of the device screen.
I have noticed that when I double-tap the content in the webview, the content gets scaled perfectly.
Is there a way to achieve this?

This is how the content looks like on the init render (Gets out of the screen):

Screenshot 2022-09-28 at 17 07 17

And this is how it looks like when I double tap(this is what I need to achieve programmatically):
Screenshot 2022-09-28 at 17 07 00

@segicm segicm closed this as completed Sep 21, 2022
@segicm segicm changed the title Scale less than 1 keeps re-rendering the component infinitely Scale the page programmatically to fit the screen Sep 28, 2022
@segicm segicm reopened this Sep 28, 2022
@ororsatti
Copy link

Calc the ratio between the offsetWidth of the page, and the scrollWIdth,
and use scaleY to scale down the entire page by the ratio you just found.

@ororsatti
Copy link

ororsatti commented May 25, 2023

  const mailContent = document.body;
    const containerWidth = mailContent?.offsetWidth;
    const mailWidth = mailContent?.scrollWidth;
    if(!mailContent || !containerWidth || !mailWidth) return;

    const scale = containerWidth / mailWidth;
    document.body.style.transform = 'scale(' + scale + ')';
    document.body.style.transformOrigin = 'top left';
    
      if (document.readyState !== 'loading') {
    scaleMailToFit();

} else {
  addEventListener('DOMContentLoaded', () => {
    scaleMailToFit();
  });
}

Pass it as a script to the webview, the autohewight height should take care of the changing 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

No branches or pull requests

2 participants