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

ThemeableBrowser Title and Button Customization Update #171

Open
wants to merge 2 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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ This plugin launches an in-app web view on top the existing [CordovaWebView](htt
},
title: {
color: '#003264ff',
showPageTitle: true
showPageTitle: true,
size: 17
},
backButton: {
image: 'back',
imagePressed: 'back_pressed',
align: 'left',
event: 'backPressed'
event: 'backPressed',
showFirstTime: false
},
forwardButton: {
image: 'forward',
Expand Down Expand Up @@ -122,11 +124,13 @@ In addition to InAppBrowser's properties, following properties were added to ful
+ `color` sets title text color in RGBA web hex format. eg. `#fff0f0ff`. Default to black.
+ `staticText` sets static text for title. This property overrides `showPageTitle` (see below).
+ `showPageTitle` when set to true, title of the current web page will be shown.
+ `size` set font-size for title.
+ `backButton`
+ `image` sets image for back button. This property references to a **native** image resource, therefore it is platform dependent.
+ `imagePressed` sets image for back button in its pressed state. This property references to a **native** image resource, therefore it is platform dependent.
+ `align` aligns back button to either `left` or `right`. Default to `left`.
+ `event` raises an custom event with given text as event name when back button is pressed. Optional.
+ 'showFirstTime' to show/hide back button at first time. (default = true).
+ `forwardButton`
+ `image` sets image for forward button. This property references to a **native** image resource, therefore it is platform dependent.
+ `imagePressed` sets image for forward button in its pressed state. This property references to a **native** image resource, therefore it is platform dependent.
Expand Down
30 changes: 26 additions & 4 deletions src/android/ThemeableBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class ThemeableBrowser extends CordovaPlugin {

private static final int TOOLBAR_DEF_HEIGHT = 44;
private static final int DISABLED_ALPHA = 127; // 50% AKA 127/255.
private static final int VISIBLE = 0;
private static final int INVISIBLE = 4;

private static final String EVT_ERR = "ThemeableBrowserError";
private static final String EVT_WRN = "ThemeableBrowserWarning";
Expand All @@ -108,7 +110,7 @@ public class ThemeableBrowser extends CordovaPlugin {
private WebView inAppWebView;
private EditText edittext;
private CallbackContext callbackContext;

/**
* Executes the request and returns PluginResult.
*
Expand Down Expand Up @@ -483,7 +485,7 @@ public void goBack() {
* @return boolean
*/
public boolean canGoBack() {
return this.inAppWebView != null && this.inAppWebView.canGoBack();
return this.inAppWebView != null && this.inAppWebView.canGoBack();
}

/**
Expand Down Expand Up @@ -637,6 +639,9 @@ public void onClick(View v) {

if (back != null) {
back.setEnabled(features.backButtonCanClose);
if(features.backButton != null && !features.backButton.showFirstTime) {
back.setVisibility(INVISIBLE);
}
}

// Forward button
Expand All @@ -656,6 +661,9 @@ public void onClick(View v) {

if (back != null) {
back.setEnabled(false);
if(features.backButton != null && !features.backButton.showFirstTime) {
back.setVisibility(INVISIBLE);
}
}


Expand Down Expand Up @@ -746,6 +754,9 @@ public void onNothingSelected(
if (features.title.staticText != null) {
title.setText(features.title.staticText);
}
if (features.title.size != 0) {
title.setTextSize(features.title.size);
}
}

// WebView
Expand All @@ -770,6 +781,15 @@ public void onPageFinished(String url, boolean canGoBack, boolean canGoForward)

if (back != null) {
back.setEnabled(canGoBack || features.backButtonCanClose);

if(features.backButton != null && !features.backButton.showFirstTime) {
if(canGoBack) {
back.setVisibility(VISIBLE);
}else {
back.setVisibility(INVISIBLE);
}
}

}

if (forward != null) {
Expand Down Expand Up @@ -861,7 +881,7 @@ public void onClick(View view) {
}

if (back != null && features.backButton != null
&& !ALIGN_RIGHT.equals(features.backButton.align)) {
&& !ALIGN_RIGHT.equals(features.backButton.align)) {
leftButtonContainer.addView(back, 0);
leftContainerWidth
+= back.getLayoutParams().width;
Expand Down Expand Up @@ -1403,7 +1423,7 @@ private static class Options {
public BrowserButton[] customButtons;
public boolean backButtonCanClose;
public boolean disableAnimation;
public boolean fullscreen;
public boolean fullscreen;
}

private static class Event {
Expand All @@ -1425,6 +1445,7 @@ private static class BrowserButton extends Event {
public String wwwImagePressed;
public double wwwImageDensity = 1;
public String align = ALIGN_LEFT;
public boolean showFirstTime = true;
}

private static class BrowserMenu extends BrowserButton {
Expand All @@ -1443,5 +1464,6 @@ private static class Title {
public String color;
public String staticText;
public boolean showPageTitle;
public float size = 0;
}
}
22 changes: 22 additions & 0 deletions src/ios/CDVThemeableBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Licensed to the Apache Software Foundation (ASF) under one
#define kThemeableBrowserPropWwwImageDensity @"wwwImageDensity"
#define kThemeableBrowserPropStaticText @"staticText"
#define kThemeableBrowserPropShowPageTitle @"showPageTitle"
#define kThemeableBrowserPropSize @"size"
#define kThemeableBrowserPropShowFirstTime @"showFirstTime"
#define kThemeableBrowserPropAlign @"align"
#define kThemeableBrowserPropTitle @"title"
#define kThemeableBrowserPropCancel @"cancel"
Expand Down Expand Up @@ -805,6 +807,11 @@ - (void)createViews
leftWidth += width;
}
}

BOOL showFirstTime = [self getBoolFromDict:_browserOptions.backButton withKey:kThemeableBrowserPropShowFirstTime];
if (showFirstTime == false) {
self.backButton.hidden = YES;
}

// Back and forward buttons must be added with special ordering logic such
// that back button is always on the left of forward button if both buttons
Expand Down Expand Up @@ -882,6 +889,11 @@ - (void)createViews
if (_browserOptions.title[kThemeableBrowserPropStaticText]) {
self.titleLabel.text = _browserOptions.title[kThemeableBrowserPropStaticText];
}

if (_browserOptions.title[kThemeableBrowserPropSize]) {
CGFloat textSize = [self getFloatFromDict:_browserOptions.title withKey:kThemeableBrowserPropSize withDefault:13.0];
self.titleLabel.font = [UIFont boldSystemFontOfSize:textSize];
}

[self.toolbar addSubview:self.titleLabel];
}
Expand Down Expand Up @@ -1486,6 +1498,16 @@ - (void)updateButton:(UIWebView*)theWebView
{
if (self.backButton) {
self.backButton.enabled = _browserOptions.backButtonCanClose || theWebView.canGoBack;

BOOL showFirstTime = [self getBoolFromDict:_browserOptions.backButton withKey:kThemeableBrowserPropShowFirstTime];
if (showFirstTime == false) {
if(theWebView.canGoBack) {
self.backButton.hidden = NO;
}else {
self.backButton.hidden = YES;
}
}

}

if (self.forwardButton) {
Expand Down