FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(android/platform): reinitialise screen metrics on orientation change by PeterStaev · Pull Request #6164 · NativeScript/NativeScript · GitHub

fix(android/platform): reinitialise screen metrics on orientation change - #6164

Merged
vakrilov merged 5 commits into
NativeScript:masterfrom
PeterStaev:issue-4588
Aug 10, 2018
Merged

vakrilov merged 5 commits into
NativeScript:masterfrom
PeterStaev:issue-4588

Conversation

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

When getting the screen width/height on android those are the same, no matter if you rotate the device or not. Unlike iOS where the properties always reflect the actual device width/height.

What is the new behavior?

platform.screen.mainScreen width and height properties will always show the actual values like on iOS.

Fixes #4588.

ghost added the ♥ community PR label Aug 8, 2018
ns-bot added the cla: yes label Aug 8, 2018
ghost assigned vakrilov Aug 8, 2018
ghost added in progress and removed ♥ community PR labels Aug 8, 2018

vakrilov left a comment •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do you think you can unify how appModule.on("cssChanged", ...) and appModule.on("orientationChanged", ...) events are handled. They can even call the same callback that re-inits the metrics. It is best that subscriptions happens on a single place (currently the "cssChanged" is handled on first get of metrics prop)

Copy link
Copy Markdown
Contributor Author

@vakrilov , just to confirm, you mean to move the cssChanged sub in the constructor? I was thinking about this, but since I wasn't sure if there might be a reason for the delayed sub, I decided not to touch the existing code 😉

vakrilov commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

Can you move the attaching the orientation changed event into the private get metrics() method. The idea here is that if nobody accesses the metrics filed - we won't listen to css/orientation events. As soon as someone does access them - we need to listen to those events so that we invalidate the cached metrics in case of an event.

Copy link
Copy Markdown
Contributor Author

Personally don't like subscriptions to happen inside a property since someone from outside could potentially nullify this._metrics and cause a double sub, but will see to change it a bit later.

vakrilov commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

test

vakrilov commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

@PeterStaev I can see your point and frankly - the constructor seems more logical place to put the subscriptions from a code-readability standpoint too. I think it is a kind of micro optimization to avoid subscribing if not necessary. The metrics() is private so it should be enough from external tinkering (as far as anything can be safe in JS 😄 ).

vakrilov commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

I checked the commits and it was moved to the dedicated property, because it was causing problems with generating android-snapshots. The snapshot should be OK now, even if we do the subscriptions are done in the constructor, because with webpack@4 we changed how the vendor-chunk is generated, but I don't think its worth it to move it again.

vakrilov merged commit 2ee1d7d into NativeScript:master Aug 10, 2018
ghost removed the in progress label Aug 10, 2018
vakrilov pushed a commit that referenced this pull request Sep 11, 2018
…nge (#6164)

* fix(android/platform): reinitialise screen metrics on orientation change

* fix(android/platform): reinitialise screen metrics on orientation change
PeterStaev deleted the issue-4588 branch September 18, 2018 13:07

lock Bot commented Sep 18, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock Bot locked and limited conversation to collaborators Sep 18, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screen dimensions platform.android & platform.ios different

3 participants


Back | FazBrowse Home | New Git URL