Skip to content

Commit

Permalink
Revert "MOBILE-1849 ios: Scroll if focused element is outside of screen"
Browse files Browse the repository at this point in the history
This reverts commit 419375f.
  • Loading branch information
jleyva committed Dec 12, 2016
1 parent 3ddeddb commit 467771a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
36 changes: 1 addition & 35 deletions www/core/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ angular.module('mm.core')

this.$get = function($ionicLoading, $ionicPopup, $injector, $translate, $http, $log, $q, $mmLang, $mmFS, $timeout, $mmApp,
$mmText, mmCoreWifiDownloadThreshold, mmCoreDownloadThreshold, $ionicScrollDelegate, $mmWS, $cordovaInAppBrowser,
$mmConfig, mmCoreSettingsRichTextEditor, $rootScope, $ionicPlatform, $ionicHistory, mmCoreSplitViewBlock, $state,
$window) {
$mmConfig, mmCoreSettingsRichTextEditor, $rootScope, $ionicPlatform, $ionicHistory, mmCoreSplitViewBlock, $state) {

$log = $log.getInstance('$mmUtil');

Expand Down Expand Up @@ -2028,39 +2027,6 @@ angular.module('mm.core')
}
};

/**
* Check if an element is outside of screen (viewport).
*
* @module mm.core
* @ngdoc method
* @name $mmUtil#isElementOutsideOfScreen
* @param {Object} element DOM element to check.
* @param {String} [scrollSelector] Selector to find the scroll that contains the element.
* @return {Boolean} Whether the element is outside of the viewport.
*/
self.isElementOutsideOfScreen = function(element, scrollSelector) {
scrollSelector = scrollSelector || '.scroll-content';

var elementRect = element.getBoundingClientRect(),
elementMidPoint,
scrollEl = self.closest(element, scrollSelector),
scrollElRect,
scrollTopPos = 0;

if (!elementRect) {
return false;
}

elementMidPoint = (Math.round(elementRect.bottom) + Math.round(elementRect.top)) / 2;

if (scrollEl) {
scrollElRect = scrollEl.getBoundingClientRect();
scrollTopPos = (scrollElRect && scrollElRect.top) || 0;
}

return elementMidPoint > $window.innerHeight || elementMidPoint < scrollTopPos;
};

return self;
};
});
16 changes: 1 addition & 15 deletions www/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ angular.module('mm.core', ['pascalprecht.translate'])
})

.run(function($ionicPlatform, $ionicBody, $window, $mmEvents, $mmInitDelegate, mmCoreEventKeyboardShow, mmCoreEventKeyboardHide,
$mmApp, $timeout, mmCoreEventOnline, mmCoreEventOnlineStatusChanged, $mmUtil, $ionicScrollDelegate) {
$mmApp, $timeout, mmCoreEventOnline, mmCoreEventOnlineStatusChanged) {
// Execute all the init processes.
$mmInitDelegate.executeInitProcesses();

Expand All @@ -190,20 +190,6 @@ angular.module('mm.core', ['pascalprecht.translate'])
// Listen for keyboard events. We don't use $cordovaKeyboard because it doesn't support keyboardHeight property.
$window.addEventListener('native.keyboardshow', function(e) {
$mmEvents.trigger(mmCoreEventKeyboardShow, e);

if (ionic.Platform.isIOS()) {
// In iOS the user can select elements outside of the view using previous/next. Check if it's the case.
if ($mmUtil.isElementOutsideOfScreen(document.activeElement)) {
// Focused element is outside of the screen. Scroll so the element is seen.
var position = $mmUtil.getElementXY(document.activeElement);
if (position) {
if ($window && $window.innerHeight) {
position[1] = position[1] - $window.innerHeight * 0.5;
}
$ionicScrollDelegate.scrollTo(position[0], position[1]);
}
}
}
});
$window.addEventListener('native.keyboardhide', function(e) {
$mmEvents.trigger(mmCoreEventKeyboardHide, e);
Expand Down

0 comments on commit 467771a

Please sign in to comment.