Skip to content

Commit

Permalink
fix: ensure @callsuper native methods call superFunc (#8025)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrifonov authored and manoldonev committed Nov 7, 2019
1 parent 0c7f838 commit 7fa9978
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions nativescript-core/ui/frame/frame.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,18 +937,21 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {

@profile
public onDestroyView(fragment: org.nativescript.widgets.FragmentBase, superFunc: Function): void {
if (traceEnabled()) {
traceWrite(`${fragment}.onDestroyView()`, traceCategories.NativeLifecycle);
}
try {
if (traceEnabled()) {
traceWrite(`${fragment}.onDestroyView()`, traceCategories.NativeLifecycle);
}

const hasRemovingParent = fragment.getRemovingParentFragment();
const hasRemovingParent = fragment.getRemovingParentFragment();

if (hasRemovingParent) {
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(application.android.context.getResources(), this.backgroundBitmap);
this.frame.nativeViewProtected.setBackgroundDrawable(bitmapDrawable);
this.backgroundBitmap = null;
if (hasRemovingParent) {
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(application.android.context.getResources(), this.backgroundBitmap);
this.frame.nativeViewProtected.setBackgroundDrawable(bitmapDrawable);
this.backgroundBitmap = null;
}
} finally {
superFunc.call(fragment);
}
superFunc.call(fragment);
}

@profile
Expand Down Expand Up @@ -982,14 +985,17 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {

@profile
public onPause(fragment: org.nativescript.widgets.FragmentBase, superFunc: Function): void {
// Get view as bitmap and set it as background. This is workaround for the disapearing nested fragments.
// TODO: Consider removing it when update to androidx.fragment:1.2.0
const hasRemovingParent = fragment.getRemovingParentFragment();
try {
// Get view as bitmap and set it as background. This is workaround for the disapearing nested fragments.
// TODO: Consider removing it when update to androidx.fragment:1.2.0
const hasRemovingParent = fragment.getRemovingParentFragment();

if (hasRemovingParent) {
this.backgroundBitmap = this.loadBitmapFromView(this.frame.nativeViewProtected);
if (hasRemovingParent) {
this.backgroundBitmap = this.loadBitmapFromView(this.frame.nativeViewProtected);
}
} finally {
superFunc.call(fragment);
}
superFunc.call(fragment);
}

@profile
Expand Down Expand Up @@ -1154,19 +1160,21 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {

@profile
public onDestroy(activity: any, superFunc: Function): void {
if (traceEnabled()) {
traceWrite("NativeScriptActivity.onDestroy();", traceCategories.NativeLifecycle);
}

const rootView = this._rootView;
if (rootView) {
rootView._tearDownUI(true);
}
try {
if (traceEnabled()) {
traceWrite("NativeScriptActivity.onDestroy();", traceCategories.NativeLifecycle);
}

const exitArgs = { eventName: application.exitEvent, object: application.android, android: activity };
application.notify(exitArgs);
const rootView = this._rootView;
if (rootView) {
rootView._tearDownUI(true);
}

superFunc.call(activity);
const exitArgs = { eventName: application.exitEvent, object: application.android, android: activity };
application.notify(exitArgs);
} finally {
superFunc.call(activity);
}
}

@profile
Expand Down

0 comments on commit 7fa9978

Please sign in to comment.