Skip to content

feat(aio): force live-example to embedded-style on narrow screen#15887

Merged
petebacondarwin merged 2 commits intoangular:masterfrom
IdeaBlade:aio-no-live-example-on-mobile
Apr 16, 2017
Merged

feat(aio): force live-example to embedded-style on narrow screen#15887
petebacondarwin merged 2 commits intoangular:masterfrom
IdeaBlade:aio-no-live-example-on-mobile

Conversation

@wardbell
Copy link
Copy Markdown
Contributor

@wardbell wardbell commented Apr 11, 2017

Updated

@IgorMinar asked that "mobile" screen constraint be determined by viewport size, not user-agent.

After further experimentation, I determined that, while the regular style plunker is useless on narrow screens, the embedded-style plunker is functional which means that we can show plunkers on mobile devices.

Therefore, this PR's 2nd commit changes the logic. It forces plunkers to embedded style on narrow (1000px) screens. It allows download of sample zips (I suppose you might want to email it from your phone).

It removes the user-agent test for mobile devices from the first commit. It keeps the refactoring of window resize in the DeviceService because that check is needed in two places and because it seems like a favorable abstraction for future use.

@sjtrimble CSS changes to control the embedded image width on narrow screens is more valid than ever.

Original

Cannot run plunkers on mobile devices nor does it make sense to download code sample to such devices. Therefore, should detect when on mobile and tell user that the live example is not available.

PR adds DeviceService to detect mobile device. The check does not consider a tablet (e.g., iPad) a mobile device because I believe that plunkers should display fine on them. While it is foolish to download the code to a tablet, we do not prevent it.

DeviceService also listen for window resize events. Moved window resize detection from AppComponent to DeviceService.displayWidth observable so others can hear about it from a shared, device-focused service.

I thought this would be important for addressing the no-LiveExample-on-mobile requirement. It turns out it wasn't needed but I kept it there because it feels like AppComponent should delegate this responsibility to a service that knows about the device.

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

@wardbell wardbell self-assigned this Apr 11, 2017
@mary-poppins
Copy link
Copy Markdown

The angular.io preview for 9adc212 is available here.

Copy link
Copy Markdown
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

No tests for DeviceService ? 😱

Comment thread aio/src/app/shared/device.service.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need all previous values? I would expect we only care about the last one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I frankly don't know how to test DeviceService itself because it interacts directly with the browser environment and I have no idea how to simulate that. I'm open to ideas.

Note that we never tested this interaction before my refactor. Thanks to the DeviceService, we can simulate the effects of different devices on the application code w/o actually changing devices.

My bad. Should be new ReplaySubject<number>(1); . Fixing.

Comment thread aio/src/app/shared/device.service.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not thrilled to access window directly here, but not a blocking issue 🌊

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you have a suggestion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In another PR, I used a Global provider so that I can more easily/cleanly mock it in tests. But maybe I am overthinking it. I am too used to AngularJS' $window 😁

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should have a test for both embedded and non-embedded plnkrs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we please move all the helpers in one place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@wardbell wardbell force-pushed the aio-no-live-example-on-mobile branch from 9adc212 to 8ff736f Compare April 11, 2017 21:30
@mary-poppins
Copy link
Copy Markdown

The angular.io preview for 8ff736f is available here.

Comment thread aio/src/app/shared/device.service.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow! OK, I will trust StackOverflow on this one 😁

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.

why do we use useragent string for this? it's the viewport resolution that matters not if it's a mobile device. Can we just use that instead?

Copy link
Copy Markdown
Contributor Author

@wardbell wardbell Apr 12, 2017

Choose a reason for hiding this comment

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

@IgorMinar I thought about that. It is the device and not the viewport that determines whether the link should show.

On desktop I might have the browser window narrow. I can always expand it to allow the plunker to play. I can also download the code. Neither of these options are available on mobile.

Are you suggesting that we change the logic so that plunkers/download are only available when the viewport is a certain width? I'm not sure what that width is but we could experiment. The download block, based on width, would be silly but we could get over it.

I await your decision.

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.

Please use viewport size. Only developers will see the site in narrow mode on desktop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On it

Copy link
Copy Markdown
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

A couple of nitpicks.
Regarding the DeviceService tests: Not a blocker (especially since we didn't test this before), but there is some logic in DeviceService that could be tested.
(An injectable global/window would indeed come in handy here.)

Comment thread aio/src/app/shared/device.service.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unnecessary ;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread aio/src/app/shared/device.service.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unnecessary space between isMobileCheck and () 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@gkalpak gkalpak added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Apr 12, 2017
@wardbell wardbell force-pushed the aio-no-live-example-on-mobile branch from 8ff736f to 9d304ce Compare April 12, 2017 20:18
@mary-poppins
Copy link
Copy Markdown

The angular.io preview for 9d304ce is available here.

@wardbell wardbell force-pushed the aio-no-live-example-on-mobile branch from b493409 to fba26fb Compare April 12, 2017 23:14
@wardbell wardbell changed the title feat(aio): detect mobile device; tell user live-example is not available feat(aio): force live-example to embedded-style on narrow screen Apr 12, 2017
@mary-poppins
Copy link
Copy Markdown

The angular.io preview for fba26fb is available here.

@wardbell
Copy link
Copy Markdown
Contributor Author

wardbell commented Apr 12, 2017

Reworked the logic to depend on viewport width and eliminate user-agent check. See revised initial PR comment which explains everything. Adjusted PR title accordingly.

Copy link
Copy Markdown
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

Can you write up the rules of when each plnkr style is applied (and whether it should be opened in a new tab etc). I am pretty confused atm 😕

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this supposed to be flat-style (with a dash)?

Copy link
Copy Markdown
Contributor Author

@wardbell wardbell Apr 15, 2017

Choose a reason for hiding this comment

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

It can be any of the aliased choices - "flatstyle", "flat-style", or "flatStyle" - known to appear in the docs. I didn't feel it was worth testing them all. But I will pick the first mentioned, "flat-style"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: this.attrs.name --> attrs.name 😃

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

k

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"even when"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops. Copy/paste error. Just "when ... requested"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The "rules" are described in the documentation at the top.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are calling this onDestroy in ApiService and SwUpdatesService. Let's be consistent 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

K

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this block, we know that width > this.narrowWidth.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch

…ilable

Adds DeviceService to detect mobile device and listen for window resize events.
@wardbell wardbell added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 15, 2017
@wardbell wardbell force-pushed the aio-no-live-example-on-mobile branch from fba26fb to aced5e0 Compare April 15, 2017 06:10
Regular plunker is unusable on narrow screen
Refactors LiveExampleComponent and adds tests.
Refactor width detection to `DeviceService` because need to know width change in 2 places.
Keep “disable” option add in earlier spikes because simple and potentially useful in future.
@wardbell wardbell force-pushed the aio-no-live-example-on-mobile branch from aced5e0 to d00565b Compare April 15, 2017 06:14
@mary-poppins
Copy link
Copy Markdown

The angular.io preview for aced5e0 is available here.

@mary-poppins
Copy link
Copy Markdown

The angular.io preview for d00565b is available here.

@wardbell wardbell added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 15, 2017
@petebacondarwin petebacondarwin merged commit 9a50844 into angular:master Apr 16, 2017
@wardbell wardbell deleted the aio-no-live-example-on-mobile branch April 19, 2017 18:17
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants