initialxy / cordova-plugin-themeablebrowser

Fork of org.apache.cordova.inappbrowser in an attempt to make it a bit more themeable and configurable to add some custom actions.
Apache License 2.0
294 stars 221 forks source link

hide() not working #169

Open schemelink opened 6 years ago

schemelink commented 6 years ago

Error has no method 'hide' when trying to hide window using hide()

Does anyone know how to fix this?

var ref = cordova.ThemeableBrowser.open("https://mysite.com", "_blank", { statusbar: { color: '#ffffffff' }, toolbar: { height: 44, color: '#f0f0f0ff' }, title: { color: '#003264ff', showPageTitle: true }, backButton: { image: 'back', imagePressed: 'back_pressed', align: 'left', event: 'backPressed' }, forwardButton: { image: 'forward', imagePressed: 'forward_pressed', align: 'left', event: 'forwardPressed' }, closeButton: { image: 'close', imagePressed: 'close_pressed', align: 'left', event: 'closePressed' }, customButtons: [ { image: 'share', imagePressed: 'share_pressed', align: 'right', event: 'sharePressed' } ], menu: { image: 'menu', imagePressed: 'menu_pressed', title: 'Test', cancel: 'Cancel', align: 'right', items: [ { event: 'helloPressed', label: 'Hello World!' }, { event: 'testPressed', label: 'Test!' } ] }, backButtonCanClose: true, hidden: true }).addEventListener('backPressed', function(e) { alert('back pressed'); }).addEventListener('helloPressed', function(e) { alert('hello pressed'); }).addEventListener('sharePressed', function(e) { alert(e.url); }).addEventListener(cordova.ThemeableBrowser.EVT_ERR, function(e) { console.error(e.message); }).addEventListener(cordova.ThemeableBrowser.EVT_WRN, function(e) { console.log(e.message); }); ref.addEventListener('loadstart', function(event) { }); ref.addEventListener('loadstop', function(event) { ref.show(); }); ref.addEventListener('loaderror', function(event) { ref.hide(); }); ref.addEventListener('exit', function(event) { navigator.app.exitApp(); });

dilukangelosl commented 6 years ago

const options: any = { statusbar: { color: '#c0392b' }, toolbar: { height: 44, color: '#c0392b' }, title: { color: '#ecf0f1', staticText: 'TEST', showPageTitle: true },

  closeButton: {
    wwwImage: 'assets/imgs/back.png',
    wwwImagePressed: 'assets/imgs/back.png',
    wwwImageDensity: 2,
    align: 'left',
    event: 'closePressed'
  },
  hidden: true,
  backButtonCanClose: true

};

Use the hidden: true option. It works

ryaa commented 3 years ago

Error has no method 'hide' when trying to hide window using hide() Does anyone know how to fix this?

I checked the native code and hide functionality is present for both iOS and Android. It has not just been added to plugin javascript to enable it. If this plugin fork is still maintained i can create the appropriate PR to enable this. In the meanwhile the quick workaround (for ionic 5/capacitor project) is to 1) create the file cordova-plugin-themeablebrowser-fix.ts under app directory in the project source (your project structure may be different) 2) add the below content into this file

import { ThemeableBrowserObject } from '@ionic-native/themeable-browser/ngx';
import { cordovaInstance } from '@ionic-native/core';

(ThemeableBrowserObject.prototype as any).hide = function() {
    return cordovaInstance(this, 'hide', { sync: true }, arguments);
};

3) add the below line to polyfills.ts file under app directory in the project source

import './cordova-plugin-themeablebrowser-fix';

Please note that there will be no appropriate typings for this hide method on ThemeableBrowserObject class but it will work when you invoke it.