@@ -44,9 +44,12 @@ Licensed to the Apache Software Foundation (ASF) under one
4444#define kThemeableBrowserPropShowPageTitle @" showPageTitle"
4545#define kThemeableBrowserPropAlign @" align"
4646#define kThemeableBrowserPropTitle @" title"
47+ #define kThemeableBrowserPropTitleFontSize @" fontSize"
4748#define kThemeableBrowserPropCancel @" cancel"
4849#define kThemeableBrowserPropItems @" items"
4950#define kThemeableBrowserPropAccessibilityDescription @" accessibilityDescription"
51+ #define kThemeableBrowserPropStatusBarStyle @" style"
52+ #define kThemeableBrowserPropToolbarPaddingX @" paddingX"
5053
5154#define kThemeableBrowserEmitError @" ThemeableBrowserError"
5255#define kThemeableBrowserEmitWarning @" ThemeableBrowserWarning"
@@ -237,13 +240,25 @@ - (void)openInThemeableBrowser:(NSURL*)url withOptions:(NSString*)options
237240 }
238241 }
239242
243+ UIStatusBarStyle statusBarStyle = UIStatusBarStyleDefault;
244+ if (browserOptions.statusbar [kThemeableBrowserPropStatusBarStyle ]){
245+ NSString * style = browserOptions.statusbar [kThemeableBrowserPropStatusBarStyle ];
246+ if ([style isEqualToString: @" lightcontent" ]){
247+ statusBarStyle = UIStatusBarStyleLightContent;
248+ }else if ([style isEqualToString: @" darkcontent" ]){
249+ if (@available (iOS 13.0 , *)) {
250+ statusBarStyle = UIStatusBarStyleDarkContent;
251+ }
252+ }
253+ }
254+
240255 if (self.themeableBrowserViewController == nil ) {
241256 NSString * originalUA = [CDVUserAgentUtil originalUserAgent ];
242257 self.themeableBrowserViewController = [[CDVThemeableBrowserViewController alloc ]
243258 initWithUserAgent: originalUA prevUserAgent: [self .commandDelegate userAgent ]
244259 browserOptions: browserOptions
245260 navigationDelete: self
246- statusBarStyle: [UIApplication sharedApplication ]. statusBarStyle];
261+ statusBarStyle: statusBarStyle];
247262
248263 if ([self .viewController conformsToProtocol: @protocol (CDVScreenOrientationDelegate)]) {
249264 self.themeableBrowserViewController .orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController ;
@@ -924,7 +939,14 @@ - (void)createViews
924939
925940 [self layoutButtons ];
926941
927- self.titleOffset = fmaxf (leftWidth, rightWidth);
942+ self.titleOffsetLeft = leftWidth;
943+ self.titleOffsetRight = rightWidth;
944+ self.toolbarPaddingX = 0 ;
945+ if (_browserOptions.toolbar [kThemeableBrowserPropToolbarPaddingX ]) {
946+ self.toolbarPaddingX = [_browserOptions.toolbar[kThemeableBrowserPropToolbarPaddingX ] floatValue ];
947+ }
948+
949+
928950 // The correct positioning of title is not that important right now, since
929951 // rePositionViews will take care of it a bit later.
930952 self.titleLabel = nil ;
@@ -939,6 +961,11 @@ - (void)createViews
939961 self.titleLabel .text = _browserOptions.title [kThemeableBrowserPropStaticText ];
940962 }
941963
964+ if (_browserOptions.title [kThemeableBrowserPropTitleFontSize ]) {
965+ CGFloat fontSize = [_browserOptions.title[kThemeableBrowserPropTitleFontSize ] floatValue ];
966+ self.titleLabel .font = [self .titleLabel.font fontWithSize: fontSize];
967+ }
968+
942969 [self .toolbar addSubview: self .titleLabel];
943970 }
944971
@@ -1064,19 +1091,22 @@ - (void)layoutButtons
10641091{
10651092 CGFloat screenWidth = CGRectGetWidth (self.view .frame );
10661093 CGFloat toolbarHeight = self.toolbar .frame .size .height ;
1094+ CGFloat toolbarPadding = _browserOptions.fullscreen ? [self getStatusBarOffset ] : 0.0 ;
10671095
10681096 // Layout leftButtons and rightButtons from outer to inner.
1069- CGFloat left = 0 ;
1097+ CGFloat left = self. toolbarPaddingX ;
10701098 for (UIButton* button in self.leftButtons ) {
10711099 CGSize size = button.frame .size ;
1072- button.frame = CGRectMake (left, floorf ((toolbarHeight - size.height ) / 2 ), size.width , size.height );
1100+ CGFloat yOffset = floorf ((toolbarHeight + (toolbarPadding/2 ) - size.height ) / 2 );
1101+ button.frame = CGRectMake (left, yOffset, size.width , size.height );
10731102 left += size.width ;
10741103 }
10751104
1076- CGFloat right = 0 ;
1105+ CGFloat right = self. toolbarPaddingX ;
10771106 for (UIButton* button in self.rightButtons ) {
10781107 CGSize size = button.frame .size ;
1079- button.frame = CGRectMake (screenWidth - right - size.width , floorf ((toolbarHeight - size.height ) / 2 ), size.width , size.height );
1108+ CGFloat yOffset = floorf ((toolbarHeight + (toolbarPadding/2 ) - size.height ) / 2 );
1109+ button.frame = CGRectMake (screenWidth - right - size.width , yOffset, size.width , size.height );
10801110 right += size.width ;
10811111 }
10821112}
@@ -1233,7 +1263,18 @@ - (void)viewDidUnload
12331263
12341264- (UIStatusBarStyle)preferredStatusBarStyle
12351265{
1236- return _statusBarStyle;
1266+ UIStatusBarStyle statusBarStyle = UIStatusBarStyleDefault;
1267+ if (_browserOptions.statusbar [kThemeableBrowserPropStatusBarStyle ]){
1268+ NSString * style = _browserOptions.statusbar [kThemeableBrowserPropStatusBarStyle ];
1269+ if ([style isEqualToString: @" lightcontent" ]){
1270+ statusBarStyle = UIStatusBarStyleLightContent;
1271+ }else if ([style isEqualToString: @" darkcontent" ]){
1272+ if (@available (iOS 13.0 , *)) {
1273+ statusBarStyle = UIStatusBarStyleDarkContent;
1274+ }
1275+ }
1276+ }
1277+ return statusBarStyle;
12371278}
12381279
12391280- (void )close
@@ -1409,48 +1450,51 @@ - (float) getStatusBarOffset {
14091450
14101451- (void ) rePositionViews {
14111452 // 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
1453+ CGFloat toolbarHeight = [self getFloatFromDict: _browserOptions.toolbar withKey: kThemeableBrowserPropHeight withDefault: TOOLBAR_DEF_HEIGHT];
1454+ CGFloat statusBarOffset = [self getStatusBarOffset ];
1455+ CGFloat toolbarOffset = _browserOptions.fullscreen ? 0.0 : statusBarOffset;
1456+ CGFloat toolbarPadding = _browserOptions.fullscreen ? statusBarOffset : 0.0 ;
1457+
14121458 if (@available (iOS 11 , *)) {
1413-
1414- CGFloat toolbarHeight = [self getFloatFromDict: _browserOptions.toolbar withKey: kThemeableBrowserPropHeight withDefault: TOOLBAR_DEF_HEIGHT];
1415- CGFloat statusBarOffset = [self getStatusBarOffset ];
1416- CGFloat webviewOffset = _browserOptions.fullscreen ? 0.0 : toolbarHeight + statusBarOffset;
1459+ // iOS 11+
1460+ CGFloat webviewOffset = _browserOptions.fullscreen ? toolbarPadding + toolbarHeight : toolbarHeight + statusBarOffset;
1461+ CGFloat webviewHeightOffset = _browserOptions.fullscreen ? -(toolbarHeight == statusBarOffset ? statusBarOffset+10 : statusBarOffset+toolbarHeight) : -(toolbarOffset+toolbarPadding);
14171462
14181463 if ([_browserOptions.toolbarposition isEqualToString: kThemeableBrowserToolbarBarPositionTop ]) {
14191464 // The webview height calculated did not take the status bar into account. Thus we need to remove status bar height to the webview height.
1420- [self .webView setFrame: CGRectMake (self .webView.frame.origin.x, webviewOffset, self .webView.frame.size.width, (self .webView.frame.size.height-statusBarOffset ))];
1421- [self .toolbar setFrame: CGRectMake (self .toolbar.frame.origin.x, [ self getStatusBarOffset ] , self .toolbar.frame.size.width, self .toolbar.frame.size.height)];
1465+ [self .webView setFrame: CGRectMake (self .webView.frame.origin.x, webviewOffset, self .webView.frame.size.width, (self .webView.frame.size.height+webviewHeightOffset ))];
1466+ [self .toolbar setFrame: CGRectMake (self .toolbar.frame.origin.x, toolbarOffset , self .toolbar.frame.size.width, self .toolbar.frame.size.height + toolbarPadding )];
14221467 }
14231468 // 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.
14241469 if (statusBarOffset == 0 ) {
14251470 [self .webView setFrame: CGRectMake (self .webView.frame.origin.x, webviewOffset, self .webView.frame.size.width, (self .webView.frame.size.height+20 ))];
14261471 }
14271472
1428- CGFloat screenWidth = CGRectGetWidth (self.view .frame );
1429- NSInteger width = floorf (screenWidth - self.titleOffset * 2 .0f );
1430- if (self.titleLabel ) {
1431- self.titleLabel .frame = CGRectMake (floorf ((screenWidth - width) / 2 .0f ), 0 , width, toolbarHeight);
1432- }
1433-
1434- [self layoutButtons ];
1435-
14361473 } else {
1437-
1438- CGFloat toolbarHeight = [self getFloatFromDict: _browserOptions.toolbar withKey: kThemeableBrowserPropHeight withDefault: TOOLBAR_DEF_HEIGHT];
1439- CGFloat webviewOffset = _browserOptions.fullscreen ? 0.0 : toolbarHeight;
1440-
1474+ // iOS <=10
1475+ CGFloat webviewOffset = _browserOptions.fullscreen ? toolbarPadding + toolbarHeight - statusBarOffset : toolbarHeight;
1476+ CGFloat webviewHeightOffset = _browserOptions.fullscreen ? -(toolbarOffset+toolbarPadding+statusBarOffset) : 0 ;
14411477 if ([_browserOptions.toolbarposition isEqualToString: kThemeableBrowserToolbarBarPositionTop ]) {
1442- [self .webView setFrame: CGRectMake (self .webView.frame.origin.x, webviewOffset, self .webView.frame.size.width, self .webView.frame.size.height)];
1443- [self .toolbar setFrame: CGRectMake (self .toolbar.frame.origin.x, [ self getStatusBarOffset ] , self .toolbar.frame.size.width, self .toolbar.frame.size.height)];
1478+ [self .webView setFrame: CGRectMake (self .webView.frame.origin.x, webviewOffset, self .webView.frame.size.width, self .webView.frame.size.height+webviewHeightOffset )];
1479+ [self .toolbar setFrame: CGRectMake (self .toolbar.frame.origin.x, toolbarOffset , self .toolbar.frame.size.width, self .toolbar.frame.size.height+toolbarPadding )];
14441480 }
1445-
1481+ }
1482+
1483+ if (self.titleLabel ) {
14461484 CGFloat screenWidth = CGRectGetWidth (self.view .frame );
1447- NSInteger width = floorf (screenWidth - self.titleOffset * 2 .0f );
1448- if (self.titleLabel ) {
1449- self.titleLabel .frame = CGRectMake (floorf ((screenWidth - width) / 2 .0f ), 0 , width, toolbarHeight);
1485+ NSInteger width = floorf (screenWidth - (self.titleOffsetLeft + self.titleOffsetRight ));
1486+ CGFloat leftOffset;
1487+ if (self.titleOffsetLeft > 0 && self.titleOffsetRight > 0 ){
1488+ leftOffset = floorf ((screenWidth - width) / 2 .0f );
1489+ }else if (self.titleOffsetLeft > 0 ){
1490+ leftOffset = self.titleOffsetLeft ;
1491+ }else {
1492+ leftOffset = self.toolbarPaddingX ;
14501493 }
1451-
1452- [self layoutButtons ];
1494+ self.titleLabel .frame = CGRectMake (leftOffset, toolbarPadding/2 , width, toolbarHeight+(toolbarPadding/2 ));
14531495 }
1496+
1497+ [self layoutButtons ];
14541498}
14551499
14561500- (CGFloat) getFloatFromDict : (NSDictionary *)dict withKey : (NSString *)key withDefault : (CGFloat)def
0 commit comments