Skip to content

Commit 7851629

Browse files
author
Vasil Chimev
authored
fix: crash at application launch on Android P (NativeScript#5831)
* fix: crash at application launch on Android P Reference: https://developer.android.com/preview/restrictions-non-sdk-interfaces Android P introduces new restrictions on the use of non-SDK interfaces, whether directly, via reflection, or via JNI. These restrictions are applied whenever an app references a non-SDK interface or attempts to obtain its handle using reflection or JNI. In particular, remove reflection via Class.getDeclaredField() and fallback default transition to fade transition. * refactor: create default transition based on SDK version Create default transition and setup default animations based on SDK version. This is to avoid reflection via Class.getDeclaredMethod() for Android P where it throws. * refactor: extract isAndroidP method
1 parent f9d66de commit 7851629

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

tns-core-modules/ui/frame/fragment.transitions.android.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const sdkVersion = lazy(() => parseInt(device.sdkVersion));
5050
const intEvaluator = lazy(() => new android.animation.IntEvaluator());
5151
const defaultInterpolator = lazy(() => new android.view.animation.AccelerateDecelerateInterpolator());
5252

53+
// NOTE: Android P Beta SDK version returns 27, which is API level for Android 8.1
54+
// TODO: Update condition when Android P SDK version returns 28
55+
const isAndroidP = lazy(() => sdkVersion() >= 27);
56+
5357
export const waitingQueue = new Map<number, Set<ExpandedEntry>>();
5458
export const completedEntries = new Map<number, ExpandedEntry>();
5559

@@ -76,7 +80,9 @@ export function _setAndroidFragmentTransitions(
7680
throw new Error("Calling navigation before previous navigation finish.");
7781
}
7882

79-
initDefaultAnimations(manager);
83+
if (!isAndroidP()) {
84+
initDefaultAnimations(manager);
85+
}
8086

8187
if (sdkVersion() >= 21) {
8288
allowTransitionOverlap(currentFragment);
@@ -116,7 +122,11 @@ export function _setAndroidFragmentTransitions(
116122
if (name === "none") {
117123
transition = new NoTransition(0, null);
118124
} else if (name === "default") {
119-
transition = new DefaultTransition(0, null);
125+
if (isAndroidP()) {
126+
transition = new FadeTransition(150, null);
127+
} else {
128+
transition = new DefaultTransition(0, null);
129+
}
120130
} else if (useLollipopTransition) {
121131
// setEnterTransition: Enter
122132
// setExitTransition: Exit
@@ -170,7 +180,11 @@ export function _setAndroidFragmentTransitions(
170180
}
171181
}
172182

173-
setupDefaultAnimations(newEntry, new DefaultTransition(0, null));
183+
if (isAndroidP()) {
184+
setupDefaultAnimations(newEntry, new FadeTransition(150, null));
185+
} else {
186+
setupDefaultAnimations(newEntry, new DefaultTransition(0, null));
187+
}
174188

175189
printTransitions(currentEntry);
176190
printTransitions(newEntry);

0 commit comments

Comments
 (0)