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 MediaQuery view insets to account for scaled height and width #25

Merged
merged 3 commits into from Oct 24, 2020

Conversation

SpencerLindemuth
Copy link
Contributor

MediaQuery view insets return the values from the unscaled screen resolution so when you scale the screen size, the size of the media query becomes disproportionate. As scaledSize increases MediaQuery view insets move elements a smaller and smaller amount.

@rayliverified
Copy link
Contributor

Amazing! Thank you so much for the help. Let me review and merge this week and then I can add you as a contributor

@rayliverified
Copy link
Contributor

In my test with a large SafeArea inset, the inset does not look like it is scaled.
MaxthonSnap20201022134041
MaxthonSnap20201022133503
This PR should fix #14 correct?

@SpencerLindemuth
Copy link
Contributor Author

SpencerLindemuth commented Oct 22, 2020

Oh I forgot about the SafeArea. SafeArea uses MediaQuery.of(context).viewPadding and I only changed viewInsets which is the virtual keyboard. Let me update the PR now.

@SpencerLindemuth
Copy link
Contributor Author

Can you test with the latest commit and see if it fixes it?

@rayliverified
Copy link
Contributor

rayliverified commented Oct 23, 2020

No, setting the ViewPadding did not solve the issue.
However, setting the insets in the padding value did solve the issue.

MaxthonSnap20201022203244

  MediaQueryData calculateMediaQueryData() {
    // Update passed in MediaQueryData.
    if (widget.mediaQueryData != null) {
      return widget.mediaQueryData.copyWith(
          size: Size(scaledWidth, scaledHeight),
          devicePixelRatio: devicePixelRatio * activeScaleFactor,
          viewInsets: scaledViewInsets,
          padding: scaledViewPadding);
    }

    return MediaQuery.of(context).copyWith(
        size: Size(scaledWidth, scaledHeight),
        devicePixelRatio: devicePixelRatio * activeScaleFactor,
        viewInsets: scaledViewInsets,
        padding: scaledViewPadding);
  }

Also, are you able to explain the difference between the viewPadding and Padding?
From the documentation, my understanding is that the viewPadding is the absolute inset value that is not affected by calculations while the padding is measured from the MediaQuery bounds and consumed by the SafeArea.

So the correct implementation is to always set the viewPadding to the window viewPadding while inheriting the padding from the parent MediaQuery.

Would you be able to update your PR again? (thanks!)

@SpencerLindemuth
Copy link
Contributor Author

Ok I think I have it right this time! It passed the test I did. When I read the documentation the first time I read that the padding is calculated using viewInsets and viewPadding so I incorrectly thought the MediaQuery class calculated it itself. Now it updates correctly based on viewInsets and viewPadding while maintaining the logic from the base MediaQuery class

@rayliverified
Copy link
Contributor

Perfect @SpencerLindemuth , tested and LGTM.

@rayliverified rayliverified merged commit 723a80e into Codelessly:master Oct 24, 2020
@rayliverified
Copy link
Contributor

Thank you so much for creating this PR as I did not have the time. This allows me to close so many issues.
The last thing before the Responsive Framework is ready for v0.1.0 release is to scale modals.

I've added you as contributor to the ReadMe with the v0.0.10 release.

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.

None yet

2 participants