Skip to content

Commit 0ad10ed

Browse files
author
Adam Bradley
committed
fix(viewport): Remove height value on iOS browser
1 parent 2232261 commit 0ad10ed

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

Diff for: js/utils/viewport.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ function viewportLoadTag() {
2525
}
2626

2727
function viewportInitWebView() {
28-
var hasViewportChange = false;
28+
var initHeight = viewportProperties.height;
2929

3030
if( ionic.Platform.isWebView() ) {
31-
if( viewportProperties.height != 'device-height' ) {
32-
viewportProperties.height = 'device-height';
33-
hasViewportChange = true;
34-
}
31+
viewportProperties.height = 'device-height';
32+
33+
} else if( ionic.Platform.isIOS() && viewportProperties.height ) {
34+
// if its not a webview, and a viewport height was set, just removing
35+
// the height value doesn't trigger the change, but setting to 0 does the trick
36+
viewportProperties.height = '0';
37+
3538
} else if( viewportProperties.height ) {
3639
delete viewportProperties.height;
37-
hasViewportChange = true;
3840
}
39-
if(hasViewportChange) viewportUpdate();
41+
42+
// only update the viewport tag if there was a change
43+
if(initHeight !== viewportProperties.height) viewportUpdate();
44+
console.debug(viewportTag.content)
4045
}
4146

4247
function viewportUpdate(updates) {
@@ -49,7 +54,7 @@ function viewportUpdate(updates) {
4954
if(viewportProperties[key]) props.push(key + '=' + viewportProperties[key]);
5055
}
5156

52-
viewportTag.content = props.join(',');
57+
viewportTag.content = props.join(', ');
5358
}
5459

5560
ionic.DomUtil.ready(function() {

Diff for: test/unit/utils/keyboard.unit.js

+5-17
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ Tested On
4141
- Android 4.2 Cordova
4242
4343
44-
iOS 7.1 Cordova with AND without viewport height DOES resize, DOES NOT fire resize event
44+
iOS 7.1 Cordova with AND without viewport height DOES resize, DOES NOT fire resize event
4545
iOS 7.1 Safari with AND without viewport height DOES NOT resize
4646
4747
iOS 7.0 Cordova with viewport height DOES resize, DOES fire resize event
4848
iOS 7.0 Cordova without viewport height DOES resize, DOES NOT fire resize event
4949
iOS 7.0 Safari with AND without viewport height DOES NOT resize
5050
5151
iOS 6.1 Cordova with AND without viewport height DOES NOT resize
52-
iOS 6.1 Safari without viewport height DOES NOT resize
52+
iOS 6.1 Safari without viewport height DOES NOT resize
5353
54-
NOTES:
54+
NOTES:
5555
-iOS 7.1 Safari with viewport height screws up ionic layout
5656
-iOS 7.0 Safari with viewport height, the scroll view does not resize properly on keyboardhide
5757
-iOS 7.0 Cordova without viewport height, scroll view does not resize properly switching inputs at bottom of page
58-
-iOS 6.1 Cordova and Safari don't work well with viewport height
58+
-iOS 6.1 Cordova and Safari don't work well with viewport height
5959
6060
RECOMMENDATIONS:
6161
-iOS 7.1 Cordova no viewport height, keyboard is not over webview
62-
-iOS 7.1 Safari no viewport height, keyboard is over webview
62+
-iOS 7.1 Safari no viewport height, keyboard is over webview
6363
6464
-iOS 7.0 Cordova yes viewport height, keyboard is not over webview
6565
-iOS 7.0 Safari no viewport height, keyboard is over webview
@@ -215,18 +215,6 @@ describe('Ionic Keyboard', function() {
215215
expect( details.isElementUnderKeyboard ).toEqual(false);
216216
});
217217

218-
it('Should not subtract the keyboard height from the contentHeight if not keyboardIsOverWebView()', function(){
219-
var element = document.createElement('textarea');
220-
var elementTop = 300;
221-
var elementBottom = 400;
222-
var keyboardHeight = 200;
223-
var deviceHeight = 260;
224-
window.innerHeight = 260;
225-
var details = keyboardShow(element, elementTop, elementBottom, deviceHeight, keyboardHeight);
226-
227-
expect( details.contentHeight ).toEqual(260);
228-
});
229-
230218
it('Should subtract the keyboard height from the contentHeight if keyboardIsOverWebView()', function(){
231219
ionic.Platform.setPlatform('iOS');
232220
ionic.Platform.setVersion('7.1');

Diff for: test/unit/utils/viewport.unit.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
iOS 6.1 Safari without viewport height DOES NOT resize
1313
1414
NOTES:
15-
-iOS 7.1 Safari with viewport height screws up ionic layout
16-
-iOS 7.0 Safari with viewport height, the scroll view does not resize properly on keyboardhide
17-
-iOS 7.0 Cordova without viewport height, scroll view does not resize properly switching inputs at bottom of page
18-
-iOS 6.1 Cordova and Safari don't work well with viewport height
15+
- iOS 7.1 Safari with viewport height screws up ionic layout
16+
- iOS 7.0 Safari with viewport height, the scroll view does not resize properly on keyboardhide
17+
- iOS 7.0 Cordova without viewport height, scroll view does not resize properly switching inputs at bottom of page
18+
- iOS 6.1 Cordova and Safari don't work well with viewport height
19+
- If its not a webview, and a viewport height was set, just removing
20+
the height value doesn't trigger the change, but setting height=0 does the trick
1921
2022
RECOMMENDATIONS:
2123
-iOS 7.1 Cordova no viewport height, keyboard is not over webview
@@ -122,4 +124,14 @@ describe('Ionic Viewport', function() {
122124
expect( vportTag.content ).toEqual(originalViewport);
123125
});
124126

127+
it('Should set height=0 if browser and height=device-height was already in', function(){
128+
ionic.Platform.setPlatform('ios');
129+
var originalViewport = 'initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=device-height';
130+
vportTag.setAttribute('content', originalViewport);
131+
viewportLoadTag();
132+
133+
// if it was changed the spaces would have been removed
134+
expect( vportTag.content ).toEqual('initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=0');
135+
});
136+
125137
});

0 commit comments

Comments
 (0)