Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

anchorScroll() forces Android address bar to show #1718

Closed
@viceversus

Description

@viceversus

The code below found in $anchorScrollProvider forces the Android address bar to show. The scroll method is called every time angular changes views, which causes this issue. While iOS and other browsers allow 0 in the scrollTo method, Android allows only positive integers for the desired behavior (http://mobile.tutsplus.com/tutorials/mobile-web-apps/remove-address-bar/).

function scroll() {
  var hash = $location.hash(), elm;

  // empty hash, scroll to the top of the page
  if (!hash) $window.scrollTo(0, 0);

  // element with given id
  else if ((elm = document.getElementById(hash))) elm.scrollIntoView();

  // first anchor with given name :-D
  else if ((elm = getFirstAnchor(document.getElementsByName(hash)))) elm.scrollIntoView();

  // no element and hash == 'top', scroll to the top of the page
  else if (hash === 'top') $window.scrollTo(0, 0);
}

Our fix is to wrap window's scrollTo method and check if the device is an Android. If it is an android and the x, y arguments are 0, 0, we manually set the value to 0, 1.

window.aliasedScrollTo = window.scrollTo

window.scrollTo = (x, y, delay) ->
  if Device.android() && x == 0 && y == 0
    window.aliasedScrollTo(x, 1, delay)
  else
    window.aliasedScrollTo(x, y, delay)

Is there a better solution for this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions