Skip to content

Commit

Permalink
#20 page glitches 2 seconds after page transition
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Dec 14, 2014
1 parent d4405a4 commit 856cce6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.telerik.plugins.nativepagetransitions"
version="0.2.6">
version="0.2.7">

<name>Native Page Transitions</name>

Expand Down
21 changes: 12 additions & 9 deletions src/android/NativePageTransitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class NativePageTransitions extends CordovaPlugin {
private FrameLayout layout;
private static final boolean BEFORE_KITKAT = Build.VERSION.SDK_INT < 19;
private final boolean requiresRedraw = BEFORE_KITKAT;
private static final String HREF_PREFIX = "file:///android_asset/www/";
// this plugin listens to page changes, so only kick in a transition when it was actually requested by the JS bridge
private String lastCallbackID;

class MyCordovaWebViewClient extends CordovaWebViewClient {
public MyCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) {
Expand Down Expand Up @@ -134,7 +137,7 @@ public void run() {

if (href != null && !"null".equals(href)) {
if (!href.startsWith("#") && href.contains(".html")) {
webView.loadUrlIntoView("file:///android_asset/www/" + href, false);
webView.loadUrlIntoView(HREF_PREFIX + href, false);
} else {
// it's a #hash
String url = webView.getUrl();
Expand Down Expand Up @@ -197,7 +200,7 @@ public void run() {

if (href != null && !"null".equals(href)) {
if (!href.startsWith("#") && href.contains(".html")) {
webView.loadUrlIntoView("file:///android_asset/www/" + href, false);
webView.loadUrlIntoView(HREF_PREFIX + href, false);
} else {
// it's a #hash
String url = webView.getUrl();
Expand Down Expand Up @@ -232,7 +235,7 @@ public void run() {

if (href != null && !"null".equals(href)) {
if (!href.startsWith("#") && href.contains(".html")) {
webView.loadUrlIntoView("file:///android_asset/www/" + href, false);
webView.loadUrlIntoView(HREF_PREFIX + href, false);
} else {
// it's a #hash
String url = webView.getUrl();
Expand All @@ -252,9 +255,10 @@ public void run() {
}

private void doFlipTransition() {
if (!calledFromJS) {
if (!calledFromJS || this._callbackContext.getCallbackId().equals(lastCallbackID)) {
return;
}
lastCallbackID = this._callbackContext.getCallbackId();

new Timer().schedule(new TimerTask() {
public void run() {
Expand Down Expand Up @@ -321,9 +325,10 @@ public void onAnimationRepeat(Animation animation) {
}

private void doSlideTransition() {
if (!calledFromJS) {
if (!calledFromJS || this._callbackContext.getCallbackId().equals(lastCallbackID)) {
return;
}
lastCallbackID = this._callbackContext.getCallbackId();

new Timer().schedule(new TimerTask() {
public void run() {
Expand Down Expand Up @@ -429,9 +434,10 @@ public void onAnimationRepeat(Animation animation) {
}

private void doDrawerTransition() {
if (!calledFromJS) {
if (!calledFromJS || this._callbackContext.getCallbackId().equals(lastCallbackID)) {
return;
}
lastCallbackID = this._callbackContext.getCallbackId();

new Timer().schedule(new TimerTask() {
public void run() {
Expand Down Expand Up @@ -504,7 +510,6 @@ public void run() {
webView.setAnimation(animation);
layout.startLayoutAnimation();
}

calledFromJS = false;
}
});
Expand All @@ -527,8 +532,6 @@ private void enableHardwareAcceleration() {
imageView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
if (BEFORE_KITKAT) {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} else {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
}
}
Expand Down

0 comments on commit 856cce6

Please sign in to comment.