Skip to content

Commit 7fa9978

Browse files
vtrifonovmanoldonev
authored andcommitted
fix: ensure @callsuper native methods call superFunc (#8025)
1 parent 0c7f838 commit 7fa9978

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

nativescript-core/ui/frame/frame.android.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -937,18 +937,21 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
937937

938938
@profile
939939
public onDestroyView(fragment: org.nativescript.widgets.FragmentBase, superFunc: Function): void {
940-
if (traceEnabled()) {
941-
traceWrite(`${fragment}.onDestroyView()`, traceCategories.NativeLifecycle);
942-
}
940+
try {
941+
if (traceEnabled()) {
942+
traceWrite(`${fragment}.onDestroyView()`, traceCategories.NativeLifecycle);
943+
}
943944

944-
const hasRemovingParent = fragment.getRemovingParentFragment();
945+
const hasRemovingParent = fragment.getRemovingParentFragment();
945946

946-
if (hasRemovingParent) {
947-
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(application.android.context.getResources(), this.backgroundBitmap);
948-
this.frame.nativeViewProtected.setBackgroundDrawable(bitmapDrawable);
949-
this.backgroundBitmap = null;
947+
if (hasRemovingParent) {
948+
const bitmapDrawable = new android.graphics.drawable.BitmapDrawable(application.android.context.getResources(), this.backgroundBitmap);
949+
this.frame.nativeViewProtected.setBackgroundDrawable(bitmapDrawable);
950+
this.backgroundBitmap = null;
951+
}
952+
} finally {
953+
superFunc.call(fragment);
950954
}
951-
superFunc.call(fragment);
952955
}
953956

954957
@profile
@@ -982,14 +985,17 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
982985

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

989-
if (hasRemovingParent) {
990-
this.backgroundBitmap = this.loadBitmapFromView(this.frame.nativeViewProtected);
993+
if (hasRemovingParent) {
994+
this.backgroundBitmap = this.loadBitmapFromView(this.frame.nativeViewProtected);
995+
}
996+
} finally {
997+
superFunc.call(fragment);
991998
}
992-
superFunc.call(fragment);
993999
}
9941000

9951001
@profile
@@ -1154,19 +1160,21 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
11541160

11551161
@profile
11561162
public onDestroy(activity: any, superFunc: Function): void {
1157-
if (traceEnabled()) {
1158-
traceWrite("NativeScriptActivity.onDestroy();", traceCategories.NativeLifecycle);
1159-
}
1160-
1161-
const rootView = this._rootView;
1162-
if (rootView) {
1163-
rootView._tearDownUI(true);
1164-
}
1163+
try {
1164+
if (traceEnabled()) {
1165+
traceWrite("NativeScriptActivity.onDestroy();", traceCategories.NativeLifecycle);
1166+
}
11651167

1166-
const exitArgs = { eventName: application.exitEvent, object: application.android, android: activity };
1167-
application.notify(exitArgs);
1168+
const rootView = this._rootView;
1169+
if (rootView) {
1170+
rootView._tearDownUI(true);
1171+
}
11681172

1169-
superFunc.call(activity);
1173+
const exitArgs = { eventName: application.exitEvent, object: application.android, android: activity };
1174+
application.notify(exitArgs);
1175+
} finally {
1176+
superFunc.call(activity);
1177+
}
11701178
}
11711179

11721180
@profile

0 commit comments

Comments
 (0)