I am using BrowserField to display some local HTML files in my application. It is displaying the HTML files properly. But while starting of the screen it is displaying some white screen (background). How can i get rid of this issue?
I am using the below code:
BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
_bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
_bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
BrowserField myBrowserField = new BrowserField(_bfConfig);
add(myBrowserField);
BrowserFieldRequest request = new BrowserFieldRequest("local:///OTPhelp_en.html");
myBrowserField.requestContent(request);
I don't have a perfect answer for you. If you take a look at this question, so far, no answers have been given as to how to make the BrowserField background transparent, which would be one way to solve your problem.
Depending on how your OTPhelp_en.html page is written, how much control over it you have, and how often it changes, this may be a workaround that's acceptable:
If your html file has a solid background color, and you know what that color is (because it's your html content), then you could simply set the BrowserField background color to match. Then, you wouldn't see any white flash before the html content is rendered. Something like this:
public class MyBrowserScreen extends MainScreen {
// this assumes the html file uses a red (#ff0000) background
private int BG_COLOR = Color.RED;
public MyBrowserScreen() {
// set the screen manager's background
getMainManager().setBackground(BackgroundFactory.createSolidBackground(BG_COLOR));
BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
_bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
_bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
BrowserField myBrowserField = new BrowserField(_bfConfig);
// set the browser field background to match the HTML background, and
// the containing screen's background
_myBrowserField.setBackground(getMainManager().getBackground());
add(myBrowserField);
BrowserFieldRequest request = new BrowserFieldRequest("local:///OTPhelp_en.html");
myBrowserField.requestContent(request);
Of course, hardcoding it in this way means that if the HTML file changes its background color, you'll need to change it in the Java code, too.
If you wanted to avoid that, and you knew the HTML file would always use a solid background color, you could first open the html file as a resource stream
getClass().getResourceAsStream("/OTPhelp_en.html");
and then parse it, searching for the background color (e.g. <body bgcolor= or <body style="background-color:). That would at least allow the browser field to look right if a simple background color change is made in the HTML file.
If the HTML file uses a gradient background, or an image background, the above code will have to be changed. But, without more information, that's my suggestion for a workaround.
Related
I have a gallery component that uses the current window size to determine how large to make the gallery items. I've also hooked the window resize events so that the gallery items are resized correctly as the window is resized.
In Chrome, if a user then prints the gallery, the items are not being resized to fit the printed page. Instead they are just using the last size calculated for the window size. This is true even when switching from portrait to landscape in the print options.
Is there any way to force react to re-render components when the print dialog is being opened and when the page layout is switched from portrait to landscape? I thought the print dialog would re-render the page with the new dimensions but that doesn't seem to be the case.
When you print a page, the browser takes a snapshot of the current DOM and applies the print media styles. Your problem is the elements on your DOM are dependent on the dimensions of the screen.
Window resize events will help to rearrange your components when the user resizes their screen but they are not triggered when the user prints. There are however ways in which you can listen to an event when the user prints the page.
window.onbeforeprint will trigger when the user prints the page. On event you either resize the screen to make the window resize events trigger or re-render your components some other way. It is not supported in chrome although take a look at this stackoverflow post, it explains how you can use window.matchMedia('print') instead.
It's always best to depend on css media queries rather than on the screen dimensions and resize events, but sometimes that is not always possible.
Use media query to target portrait and landscape print
#media print and (orientation: landscape) {
/* landscape styles */
/* write specific styles for landscape e.g */
h1 {
color: #000;
background: none;
}
nav, aside {
display: none;
}
}
#media print and (orientation: portrait) {
/* portrait styles */
}
In addition the WitVault's solution, I've created a simple React Component that makes handling complex print.css much easier. Instead of adding classes, IDs, etc. all over your markup and creating a complex print.css file, you can use my react-print library as follows:
https://github.com/captray/react-print
Add this ID to the root (or somewhere high up in your DOM tree) of your current content (but inside in the body tag)
<div id="react-no-print">
Add a div with the id of 'print-mount', or whatever mount ID you'd like to use.
<div id="print-mount"></div>
Create the structure you want for your printable version (which can include child components with their own styles to make things easier.
var PrintTemplate = require('react-print');
var ReactDOM = require('react-dom');
var React = require('react');
var MyTemplate = React.createClass({
render() {
return (
<PrintTemplate>
Your custom HTML or React Components go here, and will replace the existing HTML inside of the "react-no-print" ID, and instead it will render what's inside of your custom template.
</PrintTemplate>
);
}
});
ReactDOM.render(<MyTemplate/>, document.getElementById('print-mount'));
Basically, this renders your printable version, but it's hidden until it's needed for printing. If you need this for a sliding gallery, you probably want to hook into the change event for your slider and re-render (unmount the old one, mount the new one) the print template.
Hope this helps!
You will need to use matchMedia API in your component. But doing it yourself, you will be re-inventing a whole lot of the wheel. It'd be easier to use an existing library which takes care of this. Please check out https://www.npmjs.com/package/react-responsive. It has React based wrapper components over matchMedia, so you should be able to quickly prototype it in your project. There are polyfills available too. One other advantage I can think of is that you can have a print-preview option in your interface where you can let the user preview how the gallery will look in print mode. For this you can use the server rendering feature of this library to simulate print mode.
PS: I am not affiliated with this project in any way.
I load html string in which i link a local css file that lies in docment folder,
...<head><link href="a.css">...</head>...
Then i call webview.loadHTML:htmlstring baseURL:docURL;
the css was loaded OK. Then I change the a.css 's body {background:url(b.gif);} //previous is a.gif, then I pop the webview's view controller, and re-push a new one in which the webview load the same html string that link same css but the body's background image has been changed. Now comes the problem: Some times the webview load the changed background, while some times it will load old image though the css changed! And maybe I realloc the view controller some times, it maybe load the right one!
Can anyone teach me how to fix it?
Thanks a lot!
I am trying to build a Flash AIR app for iOS. As part of this I need to display specific HTML markup dialogs that are loaded into the app itself. I'm creating a StageWebView to display this HTML but it comes up blank every time. The StageWebView is up and visible with the specified dimensions, but there's nothing on it save a white blank page.
The code for loading it is pretty straightforward:
_webView = new StageWebView();
_webView.stage = this.stage;
_webView.viewPort = new Rectangle(50, 50, 400, 300);
_webView.loadString(markupString /* String with full HTML page as text */);
This gets called every time I need to display one of these dialogs.
While testing I noticed a LOCATION_CHANGING event fired with a target that looked like this:
http: //adobe.1234567890.apollo.air/
I have no idea at this point what's going on here. Any help so I can get the StageWebView to display properly on iOS devices is greatly appreciated.
I am using BrowserField component of RIM BB. It is right now displaying a white background. I want make a transparent background, so it could match with the Manager's background color.
I had tried with below code. But it's not working.
BrowserField contentField = new BrowserField();
bgTransparent = BackgroundFactory.createSolidTransparentBackground(0xffffff, 0);
contentField.setBackground(bgTransparent);
How to solve this?
I need to set the background of a window to be transparent programmatically, once the window is already created.
This creates a new window with a transparent background.
Titanium.UI.createWindow({url:location.href,transparentBackground:true}).open()
Background transparency can also be set in the tiapp.xml, but I need to set it after the window is loaded.
I also tried the following
var win = Titanium.UI.getCurrentWindow();
win.backgroundColor = 'transparent';
which does not have any effect...
Is there a way to achieve that?
Perhaps you could create 2 windows with the same components, one transparent and one not. Once you want the transparent background to show close the other window?
or win.setBackgroundColor('transparent');
I pasted your code into a click event and it worked fine for me. All i did was change the url to 'app://index.html' for testing purposes.
$('.button').click(function(){
// test
Titanium.UI.createWindow({url:'app://index.html',transparentBackground:true}).open();
});
Have you opened the web inspector to check for js errors?
If you want the initial window to be transparent, add this
<transparent-background>false</transparent-background>
to
<window />
on the tiapp.xml file.