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

Add inappbrowser reposition and resize attributes #756

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ instance, or the system browser.
All platforms support:

- __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off.

- __x__: Sets the X position for the InappBrowser. The default value is 0.
- __y__: Sets the Y position for the InappBrowser. The default value is 0.
- __width__: Sets the width of the InappBrowser Webview. The default value is fill-width of the screen.
- __height__: Sets the height of the InappBrowser Webview. The default value is fill-height of the screen.

Android supports these additional options:

- __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
Expand Down
27 changes: 24 additions & 3 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
Expand Down Expand Up @@ -117,7 +118,12 @@ public class InAppBrowser extends CordovaPlugin {
private static final String BEFORELOAD = "beforeload";
private static final String FULLSCREEN = "fullscreen";

private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
public static final String X = "x";
public static final String Y = "y";
public static final String WIDTH = "width";
public static final String HEIGHT = "height";

private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR, X, Y, WIDTH, HEIGHT);

private InAppBrowserDialog dialog;
private WebView inAppWebView;
Expand Down Expand Up @@ -791,6 +797,17 @@ public void run() {
dialog.setCancelable(true);
dialog.setInAppBroswer(getInAppBrowser());

Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.TOP | Gravity.LEFT;
wlp.width = features.get(WIDTH) != null ? this.dpToPixels(Integer.parseInt(features.get(WIDTH))) : WindowManager.LayoutParams.MATCH_PARENT;
wlp.height = features.get(HEIGHT) != null ? this.dpToPixels(Integer.parseInt(features.get(HEIGHT))) : WindowManager.LayoutParams.MATCH_PARENT;
wlp.dimAmount=0.5f;
window.setFlags(LayoutParams.FLAG_NOT_TOUCH_MODAL,LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.setFlags(LayoutParams.FLAG_NOT_FOCUSABLE,LayoutParams.FLAG_NOT_FOCUSABLE);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setAttributes(wlp);

// Main container layout
LinearLayout main = new LinearLayout(cordova.getActivity());
main.setOrientation(LinearLayout.VERTICAL);
Expand Down Expand Up @@ -1028,8 +1045,12 @@ public void postMessage(String data) {

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;

lp.x = features.get(X) != null ? this.dpToPixels(Integer.parseInt(features.get(X))) : 0;
lp.y = features.get(Y) != null ? this.dpToPixels(Integer.parseInt(features.get(Y))) : 0;
lp.width = features.get(WIDTH) != null ? this.dpToPixels(Integer.parseInt(features.get(WIDTH))) : WindowManager.LayoutParams.MATCH_PARENT;
lp.height = features.get(HEIGHT) != null ? this.dpToPixels(Integer.parseInt(features.get(HEIGHT))) : WindowManager.LayoutParams.MATCH_PARENT;


if (dialog != null) {
dialog.setContentView(main);
Expand Down
5 changes: 5 additions & 0 deletions src/ios/CDVInAppBrowserOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
@property (nonatomic, assign) BOOL disallowoverscroll;
@property (nonatomic, copy) NSString* beforeload;

@property (nonatomic, copy) NSString* x;
@property (nonatomic, copy) NSString* y;
@property (nonatomic, copy) NSString* width;
@property (nonatomic, copy) NSString* height;

+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options;

@end
3 changes: 2 additions & 1 deletion src/ios/CDVWKInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@property (nonatomic, retain) CDVWKInAppBrowserViewController* inAppBrowserViewController;
@property (nonatomic, copy) NSString* callbackId;
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
@property (nonatomic, strong) CDVInAppBrowserOptions* CDVBrowserOptions;

+ (id) getInstance;
- (void)open:(CDVInvokedUrlCommand*)command;
Expand All @@ -49,7 +50,7 @@

@end

@interface CDVWKInAppBrowserViewController : UIViewController <CDVScreenOrientationDelegate,WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,UIAdaptivePresentationControllerDelegate>{
@interface CDVWKInAppBrowserViewController : UIViewController <CDVScreenOrientationDelegate,WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler>{
@private
CDVInAppBrowserOptions *_browserOptions;
NSDictionary *_settings;
Expand Down
17 changes: 10 additions & 7 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ - (void)open:(CDVInvokedUrlCommand*)command
} else if ([target isEqualToString:kInAppBrowserTargetSystem]) {
[self openInSystem:absoluteUrl];
} else { // _blank or anything else
self.CDVBrowserOptions = [CDVInAppBrowserOptions parseOptions:options];
[self openInInAppBrowser:absoluteUrl withOptions:options];
}

Expand Down Expand Up @@ -292,7 +293,6 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
nav.orientationDelegate = self.inAppBrowserViewController;
nav.navigationBarHidden = YES;
nav.modalPresentationStyle = self.inAppBrowserViewController.modalPresentationStyle;
nav.presentationController.delegate = self.inAppBrowserViewController;

__weak CDVWKInAppBrowser* weakSelf = self;

Expand All @@ -306,6 +306,15 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
if(initHidden && osVersion < 11){
frame.origin.x = -10000;
}
// Set Dimensions
double x = self->_CDVBrowserOptions.x != nil ? [self->_CDVBrowserOptions.x doubleValue] : frame.origin.x;
double y = self->_CDVBrowserOptions.y != nil ? [self->_CDVBrowserOptions.y doubleValue] : frame.origin.y;
double width = self->_CDVBrowserOptions.width != nil ? [self->_CDVBrowserOptions.width doubleValue] : (frame.size.width - x); // For taking in consideration if (x) is set , custom width not set
double height = self->_CDVBrowserOptions.height != nil ? [self->_CDVBrowserOptions.height doubleValue] : (frame.size.height - y); // For taking in consideration if (y) is set , custom height not set

// Set Updated Frame
frame = CGRectMake(x , y , width , height );

strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
}
UIViewController *tmpController = [[UIViewController alloc] init];
Expand Down Expand Up @@ -1096,7 +1105,6 @@ - (void)close
// Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{
isExiting = TRUE;
lastReducedStatusBarHeight = 0.0;
if ([weakSelf respondsToSelector:@selector(presentingViewController)]) {
[[weakSelf presentingViewController] dismissViewControllerAnimated:YES completion:nil];
} else {
Expand Down Expand Up @@ -1283,10 +1291,5 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

#pragma mark UIAdaptivePresentationControllerDelegate

- (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController {
isExiting = TRUE;
}

@end //CDVWKInAppBrowserViewController