Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the bug with wrong webviewOffset (issue reported for iPhone X and other iOS devices) #170

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

michal-th
Copy link

The offset should be calculated as height of the toolbar PLUS the height of the status bar. Prevents the negative offset of webview (hiding behind the toolbar).

…ed as height of the toolbar PLUS the height of the status bar. Prevents the negative offset of webview (hiding behind the toolbar).
@jumplee
Copy link

jumplee commented Jan 8, 2018

@michal-th great! solve my problem!

@procom
Copy link

procom commented Feb 15, 2018

Hello,

I come back to this topic.
Here is a global solution after several tests

- (void) rePositionViews {
    // Webview height is a bug that appear in the plugin for ios >= 11 so we need to keep the previous code that work great for previous versions
    if (@available(iOS 11, *)) {
        
        CGFloat toolbarHeight = [self getFloatFromDict:_browserOptions.toolbar withKey:kThemeableBrowserPropHeight withDefault:TOOLBAR_DEF_HEIGHT];
        CGFloat statusBarOffset = [self getStatusBarOffset];
        CGFloat webviewOffset = _browserOptions.fullscreen ? 0.0 : toolbarHeight + statusBarOffset;
        
        if ([_browserOptions.toolbarposition isEqualToString:kThemeableBrowserToolbarBarPositionTop]) {
            // The webview height calculated did not take the status bar into account. Thus we need to remove status bar height to the webview height.
            [self.webView setFrame:CGRectMake(self.webView.frame.origin.x, webviewOffset, self.webView.frame.size.width, (self.webView.frame.size.height-statusBarOffset))];
            [self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
        }
        // When positionning the iphone to landscape mode, status bar is hidden. The problem is that we set the webview height just before with removing the status bar height. We need to adjust the phenomen by adding the preview status bar height. We had to add manually 20 (pixel) because in landscape mode, the status bar height is equal to 0.
        if (statusBarOffset == 0) {
            [self.webView setFrame:CGRectMake(self.webView.frame.origin.x, webviewOffset, self.webView.frame.size.width, (self.webView.frame.size.height+20))];
        }
        
        CGFloat screenWidth = CGRectGetWidth(self.view.frame);
        NSInteger width = floorf(screenWidth - self.titleOffset * 2.0f);
        if (self.titleLabel) {
            self.titleLabel.frame = CGRectMake(floorf((screenWidth - width) / 2.0f), 0, width, toolbarHeight);
        }
        
        [self layoutButtons];
        
    } else {
        
        CGFloat toolbarHeight = [self getFloatFromDict:_browserOptions.toolbar withKey:kThemeableBrowserPropHeight withDefault:TOOLBAR_DEF_HEIGHT];
        CGFloat webviewOffset = _browserOptions.fullscreen ? 0.0 : toolbarHeight;
        
        if ([_browserOptions.toolbarposition isEqualToString:kThemeableBrowserToolbarBarPositionTop]) {
            [self.webView setFrame:CGRectMake(self.webView.frame.origin.x, webviewOffset, self.webView.frame.size.width, self.webView.frame.size.height)];
            [self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)];
        }
        
        CGFloat screenWidth = CGRectGetWidth(self.view.frame);
        NSInteger width = floorf(screenWidth - self.titleOffset * 2.0f);
        if (self.titleLabel) {
            self.titleLabel.frame = CGRectMake(floorf((screenWidth - width) / 2.0f), 0, width, toolbarHeight);
        }
        
        [self layoutButtons];
    }
}

@pbijvani
Copy link

pbijvani commented Mar 2, 2018

How can I use this fix? Its still not on master branch.

@torgnywalin
Copy link

Any updates on when this will be available in a release?

@hiepxanh
Copy link

some one can merge it please?

@hiepxanh
Copy link

@radu-cigmaian can you merge it please?

@Manny91
Copy link

Manny91 commented Sep 28, 2018

Is there any way we can get it merged?

@grexican
Copy link

I merged this into my own fork, for those who are interested. See #193 For details

@carlesferreiro
Copy link

Merge!!!

@jeanpfs
Copy link

jeanpfs commented Sep 30, 2019

Any updates?

@grexican
Copy link

It's in my branch. I think there's still a bug with one of the other branches I merged. I no longer see the standard iphone header when using the embedded browser. I think I know the source branch that caused it. Nothing I can do about it currently. I don't have my iOS dev environment set up for it. So if you use my branch, take that part into consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.